Skip to content

Commit 1cb9a3e

Browse files
committed
server config UPDATE add pw last modified oper getter
1 parent 173044c commit 1cb9a3e

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

src/server_config.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6307,4 +6307,64 @@ nc_server_config_oper_get_supported_tls_algs(const struct ly_ctx *ctx, struct ly
63076307
return nc_server_config_oper_get_algs(ctx, mod, NULL, nc_tls_supported_cipher_suites, supported_algs);
63086308
}
63096309

6310+
API int
6311+
nc_server_config_oper_get_user_password_last_modified(const char *endpoint, const char *username, time_t *last_modified)
6312+
{
6313+
int rc = 0;
6314+
LY_ARRAY_COUNT_TYPE i;
6315+
struct nc_server_ssh_opts *ssh_opts = NULL;
6316+
struct nc_endpt *endpt;
6317+
struct nc_ch_client *ch_client;
6318+
struct nc_ch_endpt *ch_endpt;
6319+
6320+
NC_CHECK_ARG_RET(NULL, endpoint, username, last_modified, 1);
6321+
6322+
/* LOCK */
6323+
pthread_rwlock_rdlock(&server_opts.config_lock);
6324+
6325+
/* find the endpoint */
6326+
LY_ARRAY_FOR(server_opts.config.endpts, struct nc_endpt, endpt) {
6327+
if (!strcmp(endpt->name, endpoint) && (endpt->ti == NC_TI_SSH)) {
6328+
ssh_opts = endpt->opts.ssh;
6329+
goto found;
6330+
}
6331+
}
6332+
6333+
/* not found in the listening endpoints, check call-home clients */
6334+
LY_ARRAY_FOR(server_opts.config.ch_clients, struct nc_ch_client, ch_client) {
6335+
LY_ARRAY_FOR(ch_client->ch_endpts, struct nc_ch_endpt, ch_endpt) {
6336+
if (!strcmp(ch_endpt->name, endpoint) && (ch_endpt->ti == NC_TI_SSH)) {
6337+
ssh_opts = ch_endpt->opts.ssh;
6338+
goto found;
6339+
}
6340+
}
6341+
}
6342+
6343+
if (!ssh_opts) {
6344+
/* should always be true if we reach here */
6345+
ERR(NULL, "Endpoint '%s' with SSH transport not found.", endpoint);
6346+
rc = 1;
6347+
goto cleanup;
6348+
}
6349+
6350+
found:
6351+
/* find the SSH user */
6352+
LY_ARRAY_FOR(ssh_opts->auth_clients, i) {
6353+
if (!strcmp(ssh_opts->auth_clients[i].username, username)) {
6354+
*last_modified = ssh_opts->auth_clients[i].password_last_modified;
6355+
break;
6356+
}
6357+
}
6358+
if (i == LY_ARRAY_COUNT(ssh_opts->auth_clients)) {
6359+
ERR(NULL, "SSH user '%s' not found on endpoint '%s'.", username, endpoint);
6360+
rc = 1;
6361+
goto cleanup;
6362+
}
6363+
6364+
cleanup:
6365+
/* UNLOCK */
6366+
pthread_rwlock_unlock(&server_opts.config_lock);
6367+
return rc;
6368+
}
6369+
63106370
#endif /* NC_ENABLED_SSH_TLS */

src/server_config.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,17 @@ 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] endpoint Name of the endpoint the user is configured on.
355+
* @param[in] username Name of the SSH user.
356+
* @param[out] last_modified Time of the last password modification.
357+
* @return 0 on success, non-zero otherwise.
358+
*/
359+
int nc_server_config_oper_get_user_password_last_modified(const char *endpoint,
360+
const char *username, time_t *last_modified);
361+
351362
/**
352363
* @} Server Configuration Functions
353364
*/

0 commit comments

Comments
 (0)