Skip to content

Commit 431989b

Browse files
committed
server config UPDATE add pw last modified oper getter
1 parent 38e649b commit 431989b

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

src/server_config.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 */

src/server_config.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,18 @@ int nc_server_config_oper_get_supported_ssh_algs(const struct ly_ctx *ctx, struc
348348
*/
349349
int nc_server_config_oper_get_supported_tls_algs(const struct ly_ctx *ctx, struct lyd_node **supported_algs);
350350

351+
/**
352+
* @brief Gets the last modified time of an SSH user's password.
353+
*
354+
* @param[in] ch_client Name of the call-home client the user is configured on. NULL if the user is on a listening endpoint.
355+
* @param[in] endpoint Name of the endpoint the user is configured on. Can be either a listening or call-home endpoint.
356+
* @param[in] username Name of the SSH user.
357+
* @param[out] last_modified Time of the last password modification.
358+
* @return 0 on success, non-zero otherwise.
359+
*/
360+
int nc_server_config_oper_get_user_password_last_modified(const char *ch_client,
361+
const char *endpoint, const char *username, time_t *last_modified);
362+
351363
/**
352364
* @} Server Configuration Functions
353365
*/

0 commit comments

Comments
 (0)