@@ -6333,4 +6333,87 @@ nc_server_config_oper_get_supported_tls_algs(const struct ly_ctx *ctx, struct ly
63336333 return nc_server_config_oper_get_algs (ctx , mod , NULL , nc_tls_supported_cipher_suites , supported_algs );
63346334}
63356335
6336+ API int
6337+ nc_server_config_oper_get_user_password_last_modified (const char * ch_client , const char * endpoint ,
6338+ const char * username , time_t * last_modified )
6339+ {
6340+ int rc = 0 ;
6341+ LY_ARRAY_COUNT_TYPE i ;
6342+ struct nc_server_ssh_opts * ssh_opts = NULL ;
6343+ struct nc_endpt * endpt = NULL ;
6344+ struct nc_ch_client * client = NULL ;
6345+ struct nc_ch_endpt * ch_endpt = NULL ;
6346+ time_t found_time = 0 ;
6347+
6348+ NC_CHECK_ARG_RET (NULL , endpoint , username , last_modified , 1 );
6349+
6350+ * last_modified = 0 ;
6351+
6352+ /* LOCK */
6353+ pthread_rwlock_rdlock (& server_opts .config_lock );
6354+
6355+ if (ch_client ) {
6356+ /* find the call-home client */
6357+ LY_ARRAY_FOR (server_opts .config .ch_clients , i ) {
6358+ if (!strcmp (server_opts .config .ch_clients [i ].name , ch_client )) {
6359+ client = & server_opts .config .ch_clients [i ];
6360+ break ;
6361+ }
6362+ }
6363+ if (!client ) {
6364+ ERR (NULL , "Call-home client '%s' not found." , ch_client );
6365+ rc = 1 ;
6366+ goto cleanup ;
6367+ }
6368+
6369+ /* find the endpoint */
6370+ LY_ARRAY_FOR (client -> ch_endpts , struct nc_ch_endpt , ch_endpt ) {
6371+ if (!strcmp (ch_endpt -> name , endpoint ) && (ch_endpt -> ti == NC_TI_SSH )) {
6372+ ssh_opts = ch_endpt -> opts .ssh ;
6373+ break ;
6374+ }
6375+ }
6376+
6377+ if (!ssh_opts ) {
6378+ ERR (NULL , "Endpoint '%s' with SSH transport not found in call-home client '%s'." , endpoint , ch_client );
6379+ rc = 1 ;
6380+ goto cleanup ;
6381+ }
6382+ } else {
6383+ /* no call-home client specified, search in listening endpoints */
6384+ LY_ARRAY_FOR (server_opts .config .endpts , struct nc_endpt , endpt ) {
6385+ if (!strcmp (endpt -> name , endpoint ) && (endpt -> ti == NC_TI_SSH )) {
6386+ ssh_opts = endpt -> opts .ssh ;
6387+ break ;
6388+ }
6389+ }
6390+
6391+ if (!ssh_opts ) {
6392+ ERR (NULL , "Endpoint '%s' with SSH transport not found in listening endpoints." , endpoint );
6393+ rc = 1 ;
6394+ goto cleanup ;
6395+ }
6396+ }
6397+
6398+ /* find the SSH user */
6399+ LY_ARRAY_FOR (ssh_opts -> auth_clients , i ) {
6400+ if (!strcmp (ssh_opts -> auth_clients [i ].username , username )) {
6401+ found_time = ssh_opts -> auth_clients [i ].password_last_modified ;
6402+ break ;
6403+ }
6404+ }
6405+ if (i == LY_ARRAY_COUNT (ssh_opts -> auth_clients )) {
6406+ ERR (NULL , "SSH user '%s' not found on endpoint '%s'." , username , endpoint );
6407+ rc = 1 ;
6408+ goto cleanup ;
6409+ }
6410+
6411+ * last_modified = found_time ;
6412+
6413+ cleanup :
6414+ /* UNLOCK */
6415+ pthread_rwlock_unlock (& server_opts .config_lock );
6416+ return rc ;
6417+ }
6418+
63366419#endif /* NC_ENABLED_SSH_TLS */
0 commit comments