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