Skip to content

Commit 1ea193e

Browse files
romanmichalvasko
authored andcommitted
session server ssh REFACTOR comment static funcs
1 parent 9cc7b20 commit 1ea193e

1 file changed

Lines changed: 72 additions & 9 deletions

File tree

src/session_server_ssh.c

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,15 @@
4848

4949
extern struct nc_server_opts server_opts;
5050

51+
/**
52+
* @brief Stores the private key data as a temporary file.
53+
*
54+
* @param[in] in Private key data.
55+
* @param[in] privkey_format String representation of the private key format.
56+
* @return Path to the created temporary file or NULL on fail.
57+
*/
5158
static char *
52-
base64der_privkey_to_tmp_file(const char *in, const char *privkey_format)
59+
nc_server_ssh_privkey_data_to_tmp_file(const char *in, const char *privkey_format)
5360
{
5461
char path[12] = "/tmp/XXXXXX";
5562
int fd, written;
@@ -110,6 +117,13 @@ base64der_privkey_to_tmp_file(const char *in, const char *privkey_format)
110117
return strdup(path);
111118
}
112119

120+
/**
121+
* @brief Get asymmetric key from the keystore.
122+
*
123+
* @param[in] referenced_name Name of the asymmetric key in the keystore.
124+
* @param[out] askey Referenced asymmetric key.
125+
* @return 0 on success, 1 on error.
126+
*/
113127
static int
114128
nc_server_ssh_ks_ref_get_key(const char *referenced_name, struct nc_asymmetric_key **askey)
115129
{
@@ -142,6 +156,14 @@ nc_server_ssh_ks_ref_get_key(const char *referenced_name, struct nc_asymmetric_k
142156
return 0;
143157
}
144158

159+
/**
160+
* @brief Get public keys from the truststore.
161+
*
162+
* @param[in] referenced_name Name of the public key bag in the truststore.
163+
* @param[out] pubkeys Referenced public keys.
164+
* @param[out] pubkey_count Referenced public key count.
165+
* @return 0 on success, 1 on error.
166+
*/
145167
static int
146168
nc_server_ssh_ts_ref_get_keys(const char *referenced_name, struct nc_public_key **pubkeys, uint16_t *pubkey_count)
147169
{
@@ -177,6 +199,12 @@ nc_server_ssh_ts_ref_get_keys(const char *referenced_name, struct nc_public_key
177199
return 0;
178200
}
179201

202+
/**
203+
* @brief Convert UID to string.
204+
*
205+
* @param[in] uid UID to convert.
206+
* @return UID converted to string or NULL on fail.
207+
*/
180208
static char *
181209
nc_server_ssh_uid_to_str(uid_t uid)
182210
{
@@ -194,6 +222,16 @@ nc_server_ssh_uid_to_str(uid_t uid)
194222
return uid_str;
195223
}
196224

225+
/**
226+
* @brief Append a character or a string to a string.
227+
*
228+
* @param[in] src_c Source character.
229+
* @param[in] src_str Source string.
230+
* @param[in,out] size Size of the destination string.
231+
* @param[out] idx Index of the next character to write.
232+
* @param[out] dst Destination string.
233+
* @return 0 on success, 1 on error.
234+
*/
197235
static int
198236
nc_server_ssh_str_append(const char src_c, const char *src_str, int *size, int *idx, char **dst)
199237
{
@@ -230,6 +268,13 @@ nc_server_ssh_str_append(const char src_c, const char *src_str, int *size, int *
230268
return 0;
231269
}
232270

271+
/**
272+
* @brief Get the path to the system public keys from format set by an API.
273+
*
274+
* @param[in] username Username.
275+
* @param[out] out_path Path to the system public keys.
276+
* @return 0 on success, 1 on error.
277+
*/
233278
static int
234279
nc_server_ssh_get_system_keys_path(const char *username, char **out_path)
235280
{
@@ -305,11 +350,18 @@ nc_server_ssh_get_system_keys_path(const char *username, char **out_path)
305350
return ret;
306351
}
307352

308-
/* reads public keys from authorized_keys-like file */
353+
/**
354+
* @brief Read public keys from the authorized keys file.
355+
*
356+
* @param[in] path Path to the authorized keys file.
357+
* @param[out] pubkeys Public keys.
358+
* @param[out] pubkey_count Public key count.
359+
* @return 0 on success, 1 on error.
360+
*/
309361
static int
310362
nc_server_ssh_read_authorized_keys_file(const char *path, struct nc_public_key **pubkeys, uint16_t *pubkey_count)
311363
{
312-
int ret = 0, line_num = 0;
364+
int ret = 0, rc, line_num = 0;
313365
FILE *f = NULL;
314366
char *line = NULL, *ptr, *ptr2;
315367
size_t n;
@@ -360,8 +412,8 @@ nc_server_ssh_read_authorized_keys_file(const char *path, struct nc_public_key *
360412
/* add the key */
361413
*pubkeys = nc_realloc(*pubkeys, (*pubkey_count + 1) * sizeof **pubkeys);
362414
NC_CHECK_ERRMEM_GOTO(!(*pubkeys), ret = 1, cleanup);
363-
ret = asprintf(&(*pubkeys)[*pubkey_count].name, "authorized_key_%" PRIu16, *pubkey_count);
364-
NC_CHECK_ERRMEM_GOTO(ret == -1, (*pubkeys)[*pubkey_count].name = NULL; ret = 1, cleanup);
415+
rc = asprintf(&(*pubkeys)[*pubkey_count].name, "authorized_key_%" PRIu16, *pubkey_count);
416+
NC_CHECK_ERRMEM_GOTO(rc == -1, (*pubkeys)[*pubkey_count].name = NULL; ret = 1, cleanup);
365417
(*pubkeys)[*pubkey_count].type = NC_PUBKEY_FORMAT_SSH;
366418
(*pubkeys)[*pubkey_count].data = strdup(ptr);
367419
NC_CHECK_ERRMEM_GOTO(!(*pubkeys)[*pubkey_count].data, ret = 1, cleanup);
@@ -378,6 +430,14 @@ nc_server_ssh_read_authorized_keys_file(const char *path, struct nc_public_key *
378430
return ret;
379431
}
380432

433+
/**
434+
* @brief Get user's public keys from the system.
435+
*
436+
* @param[in] username Username.
437+
* @param[out] pubkeys User's public keys.
438+
* @param[out] pubkey_count Public key count.
439+
* @return 0 on success, non-zero on error.
440+
*/
381441
static int
382442
nc_server_ssh_get_system_keys(const char *username, struct nc_public_key **pubkeys, uint16_t *pubkey_count)
383443
{
@@ -1003,10 +1063,13 @@ nc_server_ssh_set_authkey_path_format(const char *path)
10031063
return ret;
10041064
}
10051065

1006-
/*
1007-
* Get the public key type from binary data stored in buffer.
1008-
* The data is in the form of: 4 bytes = data length, then data of data length
1009-
* and the data is in network byte order. The key has to be in the SSH2 format.
1066+
/**
1067+
* @brief Get the public key type from binary data.
1068+
*
1069+
* @param[in] buffer Binary key data, which is in the form of: 4 bytes = data length, then data of data length.
1070+
* Data is in network byte order. The key has to be in the SSH2 format.
1071+
* @param[out] len Length of the key type.
1072+
* @return Pointer to where the key type starts in the buffer and is of the length @p len .
10101073
*/
10111074
static const char *
10121075
nc_server_ssh_get_pubkey_type(const unsigned char *buffer, uint32_t *len)

0 commit comments

Comments
 (0)