Skip to content

Commit 06ab60d

Browse files
Roytakmichalvasko
authored andcommitted
server config UPDATE add pw last modified oper getter
1 parent b7012f4 commit 06ab60d

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
@@ -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 */

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)