Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ nc_write_msg_io(struct nc_session *session, int io_timeout, int type, ...)

switch (reply->type) {
case NC_RPL_OK:
assert(rpc_envp != NULL);
if (lyd_new_opaq2(reply_envp, NULL, "ok", NULL, rpc_envp->name.prefix, rpc_envp->name.module_ns, NULL)) {
lyd_free_tree(reply_envp);

Expand Down
1 change: 1 addition & 0 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ nc_log_vprintf(const struct nc_session *session, NC_VERB_LEVEL level, const char

cleanup:
free(msg);
va_end(args2);
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/server_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -3232,7 +3232,7 @@ nc_server_config_create_cert_to_name(const struct lyd_node *node, struct nc_serv

assert(!strcmp(LYD_NAME(node), "cert-to-name"));

/* find the list's key */
/* find the list's key - ignore result using assert of reference argument instead */
lyd_find_path(node, "id", 0, &n);
assert(n);
id = ((struct lyd_node_term *)n)->value.uint32;
Expand Down
12 changes: 10 additions & 2 deletions src/server_config_util_ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,18 @@ _nc_server_config_add_ssh_user_password(const struct ly_ctx *ctx, const char *tr
int ret = 0;
char *hashed_pw = NULL;
const char *salt = "$6$idsizuippipk$";
struct crypt_data cdata = {0};
struct crypt_data *cdata = NULL;

NC_CHECK_ARG_RET(NULL, ctx, tree_path, password, config, 1);

hashed_pw = crypt_r(password, salt, &cdata);
cdata = (struct crypt_data *) calloc(sizeof(struct crypt_data), 1);
if (cdata == NULL) {
ERR(NULL, "Allocation of crypt_data struct failed.");
ret = 1;
Comment thread
MartinHerberg marked this conversation as resolved.
goto cleanup;
}

hashed_pw = crypt_r(password, salt, cdata);
if (!hashed_pw) {
ERR(NULL, "Hashing password failed (%s).", strerror(errno));
ret = 1;
Expand All @@ -515,6 +522,7 @@ _nc_server_config_add_ssh_user_password(const struct ly_ctx *ctx, const char *tr
}

cleanup:
free(cdata);
return ret;
}

Expand Down
19 changes: 18 additions & 1 deletion src/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,25 @@ nc_session_free(struct nc_session *session, void (*data_free)(void *))
struct ly_in *msg;
struct timespec ts;
void *p;
NC_STATUS status;

if (!session || (session->status == NC_STATUS_CLOSING)) {
if (!session) {
return;
}

if ((session->side == NC_SERVER) && (session->flags & NC_SESSION_CALLHOME)) {
/* CH LOCK */
pthread_mutex_lock(&session->opts.server.ch_lock);
}

status = session->status;

if ((session->side == NC_SERVER) && (session->flags & NC_SESSION_CALLHOME)) {
/* CH UNLOCK */
pthread_mutex_unlock(&session->opts.server.ch_lock);
}

if (status == NC_STATUS_CLOSING) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/session_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -2766,7 +2766,7 @@ nc_connect_ch_endpt(struct nc_ch_endpt *endpt, nc_server_ch_session_acquire_ctx_
const struct ly_ctx *ctx = NULL;
int sock, ret;
struct timespec ts_cur;
char *ip_host;
char *ip_host = NULL;

sock = nc_sock_connect(endpt->src_addr, endpt->src_port, endpt->dst_addr, endpt->dst_port,
NC_CH_CONNECT_TIMEOUT, &endpt->ka, &endpt->sock_pending, &ip_host);
Expand Down
17 changes: 14 additions & 3 deletions src/session_server_ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,8 @@ static int
nc_server_ssh_compare_password(const char *stored_pw, const char *received_pw)
{
char *received_pw_hash = NULL;
struct crypt_data cdata = {0};
struct crypt_data *cdata;
int ret;

NC_CHECK_ARG_RET(NULL, stored_pw, received_pw, 1);

Expand All @@ -645,13 +646,23 @@ nc_server_ssh_compare_password(const char *stored_pw, const char *received_pw)
return strcmp(stored_pw + 3, received_pw);
}

received_pw_hash = crypt_r(received_pw, stored_pw, &cdata);
cdata = (struct crypt_data *) calloc(sizeof(struct crypt_data), 1);
if (cdata == NULL) {
ERR(NULL, "Allocation of crypt_data struct failed.");
return 1;
Comment thread
MartinHerberg marked this conversation as resolved.
}

received_pw_hash = crypt_r(received_pw, stored_pw, cdata);
if (!received_pw_hash) {
ERR(NULL, "Hashing the password failed (%s).", strerror(errno));
free(cdata);
return 1;
}

return strcmp(received_pw_hash, stored_pw);
ret = strcmp(received_pw_hash, stored_pw);
free(cdata);

return ret;
}

API int
Expand Down
10 changes: 2 additions & 8 deletions src/session_server_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ static int
nc_server_tls_cert_to_name(struct nc_ctn *ctn, void *cert_chain, char **username)
{
int ret = 1, i, cert_count, fingerprint_match;
char *digest_md5 = NULL, *digest_sha1 = NULL, *digest_sha224 = NULL;
char *digest_sha256 = NULL, *digest_sha384 = NULL, *digest_sha512 = NULL;
char *digest_md5, *digest_sha1, *digest_sha224;
char *digest_sha256, *digest_sha384, *digest_sha512;
void *cert;

/* first make sure the entry is valid */
Expand Down Expand Up @@ -372,7 +372,6 @@ nc_server_tls_cert_to_name(struct nc_ctn *ctn, void *cert_chain, char **username
fingerprint_match = 1;
}
free(digest_md5);
digest_md5 = NULL;
Comment thread
MartinHerberg marked this conversation as resolved.

/* SHA-1 */
} else if (!strncmp(ctn->fingerprint, "02", 2)) {
Expand All @@ -388,7 +387,6 @@ nc_server_tls_cert_to_name(struct nc_ctn *ctn, void *cert_chain, char **username
fingerprint_match = 1;
}
free(digest_sha1);
digest_sha1 = NULL;

/* SHA-224 */
} else if (!strncmp(ctn->fingerprint, "03", 2)) {
Expand All @@ -404,7 +402,6 @@ nc_server_tls_cert_to_name(struct nc_ctn *ctn, void *cert_chain, char **username
fingerprint_match = 1;
}
free(digest_sha224);
digest_sha224 = NULL;

/* SHA-256 */
} else if (!strncmp(ctn->fingerprint, "04", 2)) {
Expand All @@ -420,7 +417,6 @@ nc_server_tls_cert_to_name(struct nc_ctn *ctn, void *cert_chain, char **username
fingerprint_match = 1;
}
free(digest_sha256);
digest_sha256 = NULL;

/* SHA-384 */
} else if (!strncmp(ctn->fingerprint, "05", 2)) {
Expand All @@ -436,7 +432,6 @@ nc_server_tls_cert_to_name(struct nc_ctn *ctn, void *cert_chain, char **username
fingerprint_match = 1;
}
free(digest_sha384);
digest_sha384 = NULL;

/* SHA-512 */
} else if (!strncmp(ctn->fingerprint, "06", 2)) {
Expand All @@ -452,7 +447,6 @@ nc_server_tls_cert_to_name(struct nc_ctn *ctn, void *cert_chain, char **username
fingerprint_match = 1;
}
free(digest_sha512);
digest_sha512 = NULL;

/* unknown */
} else {
Expand Down