102
52
* @see ssh_session_connect()
104
SSH_OPTIONS *ssh_options_copy(SSH_OPTIONS *opt) {
105
SSH_OPTIONS *new = NULL;
54
int ssh_options_copy(ssh_session src, ssh_session *dest) {
112
new = ssh_options_new();
118
new->username = strdup(opt->username);
58
if (src == NULL || dest == NULL || *dest == NULL) {
65
new->username = strdup(src->username);
119
66
if (new->username == NULL) {
124
new->host = strdup(opt->host);
125
if (new->host == NULL) {
130
new->host = strdup(opt->bindaddr);
131
if (new->host == NULL) {
136
new->identity=strdup(opt->identity);
72
new->host = strdup(src->host);
73
if (new->host == NULL) {
79
new->identity = strdup(src->identity);
137
80
if (new->identity == NULL) {
142
new->ssh_dir = strdup(opt->ssh_dir);
143
if (new->ssh_dir == NULL) {
147
if (opt->known_hosts_file) {
148
new->known_hosts_file = strdup(opt->known_hosts_file);
149
if (new->known_hosts_file == NULL) {
154
new->dsakey = strdup(opt->dsakey);
155
if (new->dsakey == NULL) {
160
new->rsakey = strdup(opt->rsakey);
161
if (new->rsakey == NULL) {
86
new->sshdir = strdup(src->sshdir);
87
if (new->sshdir == NULL) {
92
if (src->knownhosts) {
93
new->knownhosts = strdup(src->knownhosts);
94
if (new->knownhosts == NULL) {
165
99
for (i = 0; i < 10; ++i) {
166
if (opt->wanted_methods[i]) {
167
new->wanted_methods[i] = strdup(opt->wanted_methods[i]);
100
if (src->wanted_methods[i]) {
101
new->wanted_methods[i] = strdup(src->wanted_methods[i]);
168
102
if (new->wanted_methods[i] == NULL) {
175
new->port = opt->port;
176
new->auth_function = opt->auth_function;
177
new->auth_userdata = opt->auth_userdata;
178
new->connect_status_function = opt->connect_status_function;
179
new->connect_status_arg = opt->connect_status_arg;
180
new->timeout = opt->timeout;
181
new->timeout_usec = opt->timeout_usec;
182
new->ssh2allowed = opt->ssh2allowed;
183
new->ssh1allowed = opt->ssh1allowed;
184
new->log_function = opt->log_function;
185
new->log_verbosity = opt->log_verbosity;
189
ssh_options_free(new);
194
* @brief Frees an option structure.
196
* @param opt Option structure to free.
198
void ssh_options_free(SSH_OPTIONS *opt) {
206
* We don't touch the banner. If the implementation
207
* did use it, they have to free it
210
SAFE_FREE(opt->username);
211
SAFE_FREE(opt->host);
212
SAFE_FREE(opt->identity);
213
SAFE_FREE(opt->bindaddr);
214
SAFE_FREE(opt->ssh_dir);
215
SAFE_FREE(opt->known_hosts_file);
216
SAFE_FREE(opt->dsakey);
217
SAFE_FREE(opt->rsakey);
219
for (i = 0; i < 10; i++) {
220
if (opt->wanted_methods[i]) {
221
free(opt->wanted_methods[i]);
229
* @brief Set destination hostname
231
* @param opt The option structure to use.
233
* @param hostname The host name to connect.
235
* @return 0 on succes, < 0 on error.
237
int ssh_options_set_host(SSH_OPTIONS *opt, const char *hostname){
241
if (opt == NULL || hostname == NULL) {
245
h = strdup(hostname);
251
SAFE_FREE(opt->host);
255
opt->host = strdup(p + 1);
256
if (opt->host == NULL) {
261
SAFE_FREE(opt->username);
262
opt->username = strdup(h);
264
if (opt->username == NULL) {
275
* @brief Set the username for authentication
277
* @param opt The options structure to use.
279
* @param username The username to authenticate.
281
* @return 0 on success, -1 on error.
283
* @bug this should not be set at options time
285
int ssh_options_set_username(SSH_OPTIONS *opt, const char *username) {
286
if (opt == NULL || username == NULL) {
290
SAFE_FREE(opt->username);
291
opt->username = strdup(username);
292
if (opt->username == NULL) {
300
* @brief Set a file descriptor for connection.
302
* If you wish to open the socket yourself for a reason or another, set the
303
* file descriptor. Don't forget to use ssh_option_set_hostname() as the
304
* hostname is used as a key in the known_host mechanism.
306
* @param opt The options structure to use.
308
* @param fd An opened file descriptor to use.
310
* @return 0 on success, < 0 on error.
312
int ssh_options_set_fd(SSH_OPTIONS *opt, socket_t fd) {
322
* @brief Set the local address and port binding.
324
* In case your client has multiple IP adresses, select the local address and
325
* port to use for the socket.\n
326
* If the address or port is not bindable, it may be impossible to connect.
328
* @param opt The options structure to use.
330
* @param bindaddr The bind address in form of hostname or ip address.
332
* @param port The port number to bind.
334
* @return 0 on success, < 0 on error.
336
int ssh_options_set_bind(SSH_OPTIONS *opt, const char *bindaddr, int port) {
337
if (opt == NULL || bindaddr == NULL) {
341
SAFE_FREE(opt->bindaddr);
342
opt->bindaddr = strdup(bindaddr);
343
if (opt->bindaddr == NULL) {
346
opt->bindport = port;
352
* @brief Set the ssh directory.
354
* The ssh directory is used for files like known_hosts and identity (public
357
* @param opt The options structure to use.
359
* @param dir The directory to set. It may include "%s" which will be
360
* replaced by the user home directory.
362
* @return 0 on success, < 0 on error.
364
* @see ssh_options_set_user_home_dir()
366
int ssh_options_set_ssh_dir(SSH_OPTIONS *opt, const char *dir) {
367
char buffer[1024] = {0};
369
if (opt == NULL || dir == NULL) {
373
snprintf(buffer, 1024, dir, ssh_get_user_home_dir());
374
SAFE_FREE(opt->ssh_dir);
375
opt->ssh_dir = strdup(buffer);
376
if (opt->ssh_dir == NULL) {
384
* @brief Set the known hosts file name.
386
* The known hosts file is used to certify remote hosts are genuine.
388
* @param opt The options structure to use.
390
* @param dir The path to the file including its name. "%s" will be
391
* substitued with the user home directory.
393
* @return 0 on success, < 0 on error.
395
* @see ssh_options_set_user_home_dir()
397
int ssh_options_set_known_hosts_file(SSH_OPTIONS *opt, const char *dir){
398
char buffer[1024] = {0};
400
if (opt == NULL || dir == NULL) {
404
snprintf(buffer, 1024, dir, ssh_get_user_home_dir());
405
SAFE_FREE(opt->known_hosts_file);
406
opt->known_hosts_file = strdup(buffer);
407
if (opt->known_hosts_file == NULL) {
415
* @brief Set the identity file name.
417
* The identity file is used authenticate with public key.
419
* @param opt The options structure to use.
421
* @param identity The path to the file including its name. "%s" will be
422
* substitued with the user home directory.
424
* @return 0 on success, < 0 on error.
426
* @see ssh_options_set_user_home_dir()
428
int ssh_options_set_identity(SSH_OPTIONS *opt, const char *identity){
429
char buffer[1024] = {0};
431
if (opt == NULL || identity == NULL) {
435
snprintf(buffer, 1024, identity, ssh_get_user_home_dir());
436
SAFE_FREE(opt->identity);
437
opt->identity = strdup(buffer);
438
if (opt->identity == NULL) {
446
* @brief Set the path to the dsa ssh host key.
448
* @param opt The options structure to use.
450
* @param dsakey The path to the dsa key to set.
452
* @return 0 on success, < 0 on error.
454
int ssh_options_set_dsa_server_key(SSH_OPTIONS *opt, const char *dsakey) {
455
if (opt == NULL || dsakey == NULL) {
459
opt->dsakey = strdup(dsakey);
460
if (opt->dsakey == NULL) {
468
* @brief Set the path to the ssh host rsa key.
470
* @param opt The options structure to use.
472
* @param rsakey The path to the rsa key to set.
474
* @return 0 on success, < 0 on error.
476
int ssh_options_set_rsa_server_key(SSH_OPTIONS *opt, const char *rsakey) {
477
if (opt == NULL || rsakey == NULL) {
481
opt->rsakey = strdup(rsakey);
482
if (opt->rsakey == NULL) {
490
* @brief Set the server banner sent to clients.
492
* @param opt The options structure to use.
494
* @param banner A text banner to be shown.
496
* @return 0 on success, < 0 on error.
498
int ssh_options_set_banner(SSH_OPTIONS *opt, const char *banner) {
499
if (opt == NULL || banner == NULL) {
503
SAFE_FREE(opt->banner);
504
opt->banner = strdup(banner);
505
if (opt->banner == NULL) {
513
* @brief Set the algorithms to be used for cryptography and compression.
516
* KEX_HOSTKEY (server public key type) : ssh-rsa or ssh-dss\n
517
* KEX_CRYPT_C_S (symmetric cipher client to server)\n
518
* KEX_CRYPT_S_C (symmetric cipher server to client)\n
519
* KEX_COMP_C_S (Compression client to server): zlib or none\n
520
* KEX_COMP_S_C (Compression server to client): zlib or none\n
521
* You don't have to use this function if using the default ciphers
523
* in order to enable compression client to server, do\n
525
* ret = ssh_options_set_wanted_algos(opt,KEX_COMP_C_S,"zlib");
528
* @param opt The options structure to use.
530
* @param algo The method which needs to be changed.
532
* @param list A list of algorithms to be used, in order of preference
533
* and separated by commas.
535
* @return 0 on success, < 0 on error
537
int ssh_options_set_wanted_algos(SSH_OPTIONS *opt, int algo, const char *list) {
538
if (opt == NULL || list == NULL) {
542
if(algo > SSH_LANG_S_C || algo < 0) {
543
ssh_set_error(opt, SSH_REQUEST_DENIED, "algo %d out of range", algo);
547
if ((!opt->use_nonexisting_algo) && !verify_existing_algo(algo, list)) {
548
ssh_set_error(opt, SSH_REQUEST_DENIED, "Setting method: no algorithm "
549
"for method \"%s\" (%s)\n", ssh_kex_nums[algo], list);
553
SAFE_FREE(opt->wanted_methods[algo]);
554
opt->wanted_methods[algo] = strdup(list);
555
if (opt->wanted_methods[algo] == NULL) {
109
new->port = src->port;
110
new->callbacks = src->callbacks;
111
new->timeout = src->timeout;
112
new->timeout_usec = src->timeout_usec;
113
new->ssh2 = src->ssh2;
114
new->ssh1 = src->ssh1;
115
new->log_verbosity = src->log_verbosity;
563
static char *get_username_from_uid(SSH_OPTIONS *opt, uid_t uid){
121
static char *get_username_from_uid(ssh_session session, uid_t uid){
564
122
struct passwd *pwd = NULL;
566
125
pwd = getpwuid(uid);
568
127
if (pwd == NULL) {
569
ssh_set_error(opt,SSH_FATAL,"uid %d doesn't exist !",uid);
573
return strdup(pwd->pw_name);
577
/* this function must be called when no specific username has been asked. it has to guess it */
578
int ssh_options_default_username(SSH_OPTIONS *opt) {
586
user = get_username_from_uid(opt,getuid());
588
opt->username = user;
593
GetUserName(NULL, &Size); //Get Size
598
if (GetUserName(user, &Size)) {
608
int ssh_options_default_ssh_dir(SSH_OPTIONS *opt) {
609
char buffer[256] = {0};
615
snprintf(buffer, 256, "%s/.ssh/", ssh_get_user_home_dir());
616
opt->ssh_dir = strdup(buffer);
617
if (opt->ssh_dir == NULL) {
624
int ssh_options_default_known_hosts_file(SSH_OPTIONS *opt) {
625
char buffer[1024] = {0};
627
if (opt->known_hosts_file) {
631
if (ssh_options_default_ssh_dir(opt) < 0) {
635
snprintf(buffer, 1024, "%s/known_hosts", opt->ssh_dir);
636
opt->known_hosts_file = strdup(buffer);
637
if (opt->known_hosts_file == NULL) {
645
* @brief Set a callback to show connection status in realtime.
647
* During ssh_connect(), libssh will call the callback with status from
650
* @param opt The options structure to use.
652
* @param callback A function pointer to a callback in form
653
* f(void *userarg, float status).
655
* @param arg The value to be given as argument to the callback
656
* function when it is called.
658
* @return 0 on success, < 0 on error.
662
int ssh_options_set_status_callback(SSH_OPTIONS *opt,
663
void (*callback)(void *arg, float status), void *arg) {
664
if (opt == NULL || callback == NULL) {
668
opt->connect_status_function = callback;
669
opt->connect_status_arg = arg;
675
* @brief Set a timeout for the connection.
677
* @param opt The options structure to use.
679
* @param seconds Number of seconds.
681
* @param usec Number of micro seconds.
683
* @return 0 on success, < 0 on error.
685
* @bug Currently it only timeouts the socket connection, not the
688
int ssh_options_set_timeout(SSH_OPTIONS *opt, long seconds, long usec) {
693
opt->timeout=seconds;
694
opt->timeout_usec=usec;
700
* @brief Allow or deny the connection to SSH1 servers.
702
* Default value is 0 (no connection to SSH1 servers).
704
* @param opt The options structure to use.
706
* @param allow Non zero value allow ssh1.
708
* @return 0 on success, < 0 on error.
710
int ssh_options_allow_ssh1(SSH_OPTIONS *opt, int allow) {
716
opt->ssh1allowed = 1;
718
opt->ssh1allowed = 0;
725
* @brief Allow or deny the connection to SSH2 servers.
727
* Default value is 1 (allow connection to SSH2 servers).
729
* @param opt The options structure to use.
731
* @param allow Non zero values allow ssh2.
733
* @return 0 on success, < 0 on error.
735
int ssh_options_allow_ssh2(SSH_OPTIONS *opt, int allow) {
741
opt->ssh2allowed = 1;
743
opt->ssh2allowed = 0;
750
* @brief Change the writer callback for logging.
752
* Default is a write on stderr.
754
* @param opt The options structure to use.
756
* @param callback A callback function for the printing.
758
* @return 0 on success, < 0 on error.
760
* @warning The message string may contain format string characters.
762
int ssh_options_set_log_function(SSH_OPTIONS *opt,
763
void (*callback)(const char *message, SSH_SESSION *session, int priority)) {
764
if (opt == NULL || callback == NULL) {
768
opt->log_function = callback;
774
* @brief Set the session logging priority.
776
* @param opt The options structure to use.
778
* @param verbosity The verbosity of the messages. Every log smaller or
779
* equal to verbosity will be shown\n
780
* SSH_LOG_NOLOG No logging \n
781
* SSH_LOG_RARE Rare conditions or warnings\n
782
* SSH_LOG_ENTRY Api-accessible entrypoints\n
783
* SSH_LOG_PACKET Packet id and size\n
784
* SSH_LOG_FUNCTIONS function entering and leaving\n
786
* @return 0 on success, < 0 on error.
788
int ssh_options_set_log_verbosity(SSH_OPTIONS *opt, int verbosity) {
793
opt->log_verbosity = verbosity;
128
ssh_set_error(session, SSH_FATAL, "uid %d doesn't exist !", uid);
132
name = strdup(pwd->pw_name);
135
ssh_set_error_oom(session);
143
int ssh_options_set_algo(ssh_session session, int algo,
145
if (!verify_existing_algo(algo, list)) {
146
ssh_set_error(session, SSH_REQUEST_DENIED,
147
"Setting method: no algorithm for method \"%s\" (%s)\n",
148
ssh_kex_nums[algo], list);
152
SAFE_FREE(session->wanted_methods[algo]);
153
session->wanted_methods[algo] = strdup(list);
154
if (session->wanted_methods[algo] == NULL) {
155
ssh_set_error_oom(session);
162
char *dir_expand_dup(ssh_session session, const char *value, int allowsshdir) {
165
if (value[0] == '~' && value[1] == '/') {
166
char *homedir = ssh_get_user_home_dir();
169
if (homedir == NULL) {
172
lv = strlen(value + 1);
173
lh = strlen(homedir);
175
new = malloc(lv + lh + 1);
177
ssh_set_error_oom(session);
181
memcpy(new, homedir, lh);
183
memcpy(new + lh, value + 1, lv + 1);
186
if (allowsshdir && strncmp(value, "SSH_DIR/", 8) == 0) {
188
if (session->sshdir == NULL) {
189
if (ssh_options_set(session, SSH_OPTIONS_SSH_DIR, NULL) < 0)
195
ls = strlen(session->sshdir);
197
new = malloc(lv + ls + 1);
199
ssh_set_error_oom(session);
202
memcpy(new, session->sshdir, ls);
203
memcpy(new + ls, value, lv + 1);
208
ssh_set_error_oom(session);
215
* @brief This function can set all possible ssh options.
217
* @param session An allocated ssh option structure.
219
* @param type The option type to set. This could be one of the
223
* The hostname or ip address to connect to (string).
226
* The port to connect to (integer).
228
* SSH_OPTIONS_PORT_STR:
229
* The port to connect to (string).
232
* The file descriptor to use (socket_t).
234
* If you wish to open the socket yourself for a reason
235
* or another, set the file descriptor. Don't forget to
236
* set the hostname as the hostname is used as a key in
237
* the known_host mechanism.
240
* The username for authentication (string).
242
* If the value is NULL, the username is set to the
245
* SSH_OPTIONS_SSH_DIR:
246
* Set the ssh directory (format string).
248
* If the value is NULL, the directory is set to the
249
* default ssh directory.
251
* The ssh directory is used for files like known_hosts
252
* and identity (private and public key). It may include
253
* "%s" which will be replaced by the user home
256
* SSH_OPTIONS_KNOWNHOSTS:
257
* Set the known hosts file name (format string).
259
* If the value is NULL, the directory is set to the
260
* default known hosts file, normally ~/.ssh/known_hosts.
262
* The known hosts file is used to certify remote hosts
263
* are genuine. It may include "%s" which will be
264
* replaced by the user home directory.
266
* SSH_OPTIONS_IDENTITY:
267
* Set the identity file name (format string).
269
* By default identity, id_dsa and id_rsa are checked.
271
* The identity file used authenticate with public key.
272
* It may include "%s" which will be replaced by the
273
* user home directory.
275
* SSH_OPTIONS_TIMEOUT:
276
* Set a timeout for the connection in seconds (integer).
278
* SSH_OPTIONS_TIMEOUT_USEC:
279
* Set a timeout for the connection in micro seconds
283
* Allow or deny the connection to SSH1 servers
287
* Allow or deny the connection to SSH2 servers
290
* SSH_OPTIONS_LOG_VERBOSITY:
291
* Set the session logging verbosity (integer).
293
* The verbosity of the messages. Every log smaller or
294
* equal to verbosity will be shown.
295
* SSH_LOG_NOLOG: No logging
296
* SSH_LOG_RARE: Rare conditions or warnings
297
* SSH_LOG_ENTRY: API-accessible entrypoints
298
* SSH_LOG_PACKET: Packet id and size
299
* SSH_LOG_FUNCTIONS: Function entering and leaving
301
* SSH_OPTIONS_LOG_VERBOSITY_STR:
302
* Set the session logging verbosity (string).
304
* The verbosity of the messages. Every log smaller or
305
* equal to verbosity will be shown.
306
* SSH_LOG_NOLOG: No logging
307
* SSH_LOG_RARE: Rare conditions or warnings
308
* SSH_LOG_ENTRY: API-accessible entrypoints
309
* SSH_LOG_PACKET: Packet id and size
310
* SSH_LOG_FUNCTIONS: Function entering and leaving
312
* See the corresponding numbers in libssh.h.
314
* SSH_OPTTIONS_AUTH_CALLBACK:
315
* Set a callback to use your own authentication function
316
* (function pointer).
318
* SSH_OPTTIONS_AUTH_USERDATA:
319
* Set the user data passed to the authentication function
322
* SSH_OPTTIONS_LOG_CALLBACK:
323
* Set a callback to use your own logging function
324
* (function pointer).
326
* SSH_OPTTIONS_LOG_USERDATA:
327
* Set the user data passed to the logging function
330
* SSH_OPTTIONS_STATUS_CALLBACK:
331
* Set a callback to show connection status in realtime
332
* (function pointer).
334
* fn(void *arg, float status)
336
* During ssh_connect(), libssh will call the callback
337
* with status from 0.0 to 1.0.
339
* SSH_OPTTIONS_STATUS_ARG:
340
* Set the status argument which should be passed to the
341
* status callback (generic pointer).
343
* SSH_OPTIONS_CIPHERS_C_S:
344
* Set the symmetric cipher client to server (string,
345
* comma-separated list).
347
* SSH_OPTIONS_CIPHERS_S_C:
348
* Set the symmetric cipher server to client (string,
349
* comma-separated list).
351
* SSH_OPTIONS_COMPRESSION_C_S:
352
* Set the compression to use for client to server
353
* communication (string, "none" or "zlib").
355
* SSH_OPTIONS_COMPRESSION_S_C:
356
* Set the compression to use for server to client
357
* communication (string, "none" or "zlib").
359
* @param value The value to set. This is a generic pointer and the
360
* datatype which is used should be set according to the
363
* @return 0 on success, < 0 on error.
365
int ssh_options_set(ssh_session session, enum ssh_options_e type,
370
if (session == NULL) {
375
case SSH_OPTIONS_HOST:
378
ssh_set_error_oom(session);
383
SAFE_FREE(session->host);
387
session->host = strdup(p + 1);
388
if (session->host == NULL) {
390
ssh_set_error_oom(session);
394
SAFE_FREE(session->username);
395
session->username = strdup(q);
397
if (session->username == NULL) {
398
ssh_set_error_oom(session);
405
case SSH_OPTIONS_PORT:
407
session->port = 22 & 0xffff;
409
int *x = (int *) value;
411
session->port = *x & 0xffff;
414
case SSH_OPTIONS_PORT_STR:
416
session->port = 22 & 0xffff;
420
ssh_set_error_oom(session);
423
i = strtol(q, &p, 10);
429
session->port = i & 0xffff;
432
case SSH_OPTIONS_USER:
433
SAFE_FREE(session->username);
434
if (value == NULL) { /* set default username */
437
GetUserName(NULL, &size); //Get Size
440
ssh_set_error_oom(session);
443
if (GetUserName(q, &size)) {
444
session->username = q;
450
q = get_username_from_uid(session, getuid());
454
session->username = q;
456
} else { /* username provided */
457
session->username = strdup(value);
458
if (session->username == NULL) {
459
ssh_set_error_oom(session);
464
case SSH_OPTIONS_SSH_DIR:
466
SAFE_FREE(session->sshdir);
467
/* TODO: why ~/.ssh/ instead of ~/.ssh ? */
469
session->sshdir = dir_expand_dup(session, "~/.ssh/", 0);
470
if (session->sshdir == NULL) {
474
SAFE_FREE(session->sshdir);
475
session->sshdir = dir_expand_dup(session, value, 0);
476
if (session->sshdir == NULL) {
481
case SSH_OPTIONS_IDENTITY:
484
ssh_set_error_invalid(session, __FUNCTION__);
487
SAFE_FREE(session->identity);
488
session->identity = dir_expand_dup(session, value, 1);
489
if (session->identity == NULL) {
493
case SSH_OPTIONS_KNOWNHOSTS:
495
SAFE_FREE(session->knownhosts);
496
session->knownhosts = dir_expand_dup(session,
497
"SSH_DIR/known_hosts", 1);
498
if (session->knownhosts == NULL) {
502
SAFE_FREE(session->knownhosts);
503
session->knownhosts = dir_expand_dup(session, value, 1);
504
if (session->knownhosts == NULL) {
509
case SSH_OPTIONS_TIMEOUT:
511
ssh_set_error_invalid(session, __FUNCTION__);
514
long *x = (long *) value;
516
session->timeout = *x & 0xffffffff;
519
case SSH_OPTIONS_TIMEOUT_USEC:
521
ssh_set_error_invalid(session, __FUNCTION__);
524
long *x = (long *) value;
526
session->timeout_usec = *x & 0xffffffff;
529
case SSH_OPTIONS_SSH1:
531
ssh_set_error_invalid(session, __FUNCTION__);
534
int *x = (int *) value;
538
case SSH_OPTIONS_SSH2:
540
ssh_set_error_invalid(session, __FUNCTION__);
543
int *x = (int *) value;
544
session->ssh2 = *x & 0xffff;
547
case SSH_OPTIONS_LOG_VERBOSITY:
549
ssh_set_error_invalid(session, __FUNCTION__);
552
int *x = (int *) value;
554
session->log_verbosity = *x & 0xffff;
557
case SSH_OPTIONS_LOG_VERBOSITY_STR:
559
session->log_verbosity = 0 & 0xffff;
563
ssh_set_error_oom(session);
566
i = strtol(q, &p, 10);
572
session->log_verbosity = i & 0xffff;
575
case SSH_OPTIONS_CIPHERS_C_S:
577
ssh_set_error_invalid(session, __FUNCTION__);
580
if (ssh_options_set_algo(session, SSH_CRYPT_C_S, value) < 0)
584
case SSH_OPTIONS_CIPHERS_S_C:
586
ssh_set_error_invalid(session, __FUNCTION__);
589
if (ssh_options_set_algo(session, SSH_CRYPT_S_C, value) < 0)
593
case SSH_OPTIONS_COMPRESSION_C_S:
595
ssh_set_error_invalid(session, __FUNCTION__);
598
if (ssh_options_set_algo(session, SSH_COMP_C_S, value) < 0)
602
case SSH_OPTIONS_COMPRESSION_S_C:
604
ssh_set_error_invalid(session, __FUNCTION__);
607
if (ssh_options_set_algo(session, SSH_COMP_S_C, value) < 0)
612
ssh_set_error(session, SSH_REQUEST_DENIED, "Unkown ssh option %d", type);
621
static int ssh_bind_options_set_algo(ssh_bind sshbind, int algo,
623
if (!verify_existing_algo(algo, list)) {
624
ssh_set_error(sshbind, SSH_REQUEST_DENIED,
625
"Setting method: no algorithm for method \"%s\" (%s)\n",
626
ssh_kex_nums[algo], list);
630
SAFE_FREE(sshbind->wanted_methods[algo]);
631
sshbind->wanted_methods[algo] = strdup(list);
632
if (sshbind->wanted_methods[algo] == NULL) {
633
ssh_set_error_oom(sshbind);
641
* @brief This function can set all possible ssh bind options.
643
* @param session An allocated ssh option structure.
645
* @param type The option type to set. This could be one of the
648
* SSH_BIND_OPTIONS_LOG_VERBOSITY:
649
* Set the session logging verbosity (integer).
651
* The verbosity of the messages. Every log smaller or
652
* equal to verbosity will be shown.
653
* SSH_LOG_NOLOG: No logging
654
* SSH_LOG_RARE: Rare conditions or warnings
655
* SSH_LOG_ENTRY: API-accessible entrypoints
656
* SSH_LOG_PACKET: Packet id and size
657
* SSH_LOG_FUNCTIONS: Function entering and leaving
659
* SSH_BIND_OPTIONS_LOG_VERBOSITY_STR:
660
* Set the session logging verbosity (integer).
662
* The verbosity of the messages. Every log smaller or
663
* equal to verbosity will be shown.
664
* SSH_LOG_NOLOG: No logging
665
* SSH_LOG_RARE: Rare conditions or warnings
666
* SSH_LOG_ENTRY: API-accessible entrypoints
667
* SSH_LOG_PACKET: Packet id and size
668
* SSH_LOG_FUNCTIONS: Function entering and leaving
670
* SSH_BIND_OPTIONS_BINDADDR:
671
* Set the bind address.
673
* SSH_BIND_OPTIONS_BINDPORT:
674
* Set the bind port, default is 22.
676
* SSH_BIND_OPTIONS_HOSTKEY:
677
* Set the server public key type: ssh-rsa or ssh-dss
680
* SSH_BIND_OPTIONS_DSAKEY:
681
* Set the path to the dsa ssh host key (string).
683
* SSH_BIND_OPTIONS_RSAKEY:
684
* Set the path to the ssh host rsa key (string).
686
* SSH_BIND_OPTIONS_BANNER:
687
* Set the server banner sent to clients (string).
689
* @param value The value to set. This is a generic pointer and the
690
* datatype which is used should be set according to the
693
* @return 0 on success, < 0 on error.
695
int ssh_bind_options_set(ssh_bind sshbind, enum ssh_bind_options_e type,
700
if (sshbind == NULL) {
705
case SSH_BIND_OPTIONS_HOSTKEY:
707
ssh_set_error_invalid(sshbind, __FUNCTION__);
710
if (ssh_bind_options_set_algo(sshbind, SSH_HOSTKEYS, value) < 0)
714
case SSH_BIND_OPTIONS_BINDADDR:
716
ssh_set_error_invalid(sshbind, __FUNCTION__);
719
SAFE_FREE(sshbind->bindaddr);
720
sshbind->bindaddr = strdup(value);
721
if (sshbind->bindaddr == NULL) {
722
ssh_set_error_oom(sshbind);
727
case SSH_BIND_OPTIONS_BINDPORT:
729
ssh_set_error_invalid(sshbind, __FUNCTION__);
732
int *x = (int *) value;
733
sshbind->bindport = *x & 0xffff;
736
case SSH_BIND_OPTIONS_BINDPORT_STR:
738
sshbind->bindport = 22 & 0xffff;
742
ssh_set_error_oom(sshbind);
745
i = strtol(q, &p, 10);
751
sshbind->bindport = i & 0xffff;
754
case SSH_BIND_OPTIONS_LOG_VERBOSITY:
756
ssh_set_error_invalid(sshbind, __FUNCTION__);
759
int *x = (int *) value;
760
sshbind->log_verbosity = *x & 0xffff;
763
case SSH_BIND_OPTIONS_LOG_VERBOSITY_STR:
765
sshbind->log_verbosity = 0;
769
ssh_set_error_oom(sshbind);
772
i = strtol(q, &p, 10);
778
sshbind->log_verbosity = i & 0xffff;
781
case SSH_BIND_OPTIONS_DSAKEY:
783
ssh_set_error_invalid(sshbind, __FUNCTION__);
786
SAFE_FREE(sshbind->dsakey);
787
sshbind->dsakey = strdup(value);
788
if (sshbind->dsakey == NULL) {
789
ssh_set_error_oom(sshbind);
794
case SSH_BIND_OPTIONS_RSAKEY:
796
ssh_set_error_invalid(sshbind, __FUNCTION__);
799
SAFE_FREE(sshbind->rsakey);
800
sshbind->rsakey = strdup(value);
801
if (sshbind->rsakey == NULL) {
802
ssh_set_error_oom(sshbind);
807
case SSH_BIND_OPTIONS_BANNER:
809
ssh_set_error_invalid(sshbind, __FUNCTION__);
812
SAFE_FREE(sshbind->banner);
813
sshbind->banner = strdup(value);
814
if (sshbind->banner == NULL) {
815
ssh_set_error_oom(sshbind);
821
ssh_set_error(sshbind, SSH_REQUEST_DENIED, "Unkown ssh option %d", type);
798
831
* @brief Parse command line arguments.