5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2000 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
23 * Revision 1.4 2000/07/14 06:11:32 priikone
24 * Fixed key-pair generation.
26 * Revision 1.3 2000/07/05 06:11:00 priikone
27 * Added ~./silc directory checking, autoloading of keys and
28 * tweaked the key pair generation function.
30 * Revision 1.2 2000/06/30 10:49:48 priikone
31 * Added SOCKS4 and SOCKS5 support for SILC client.
33 * Revision 1.1.1.1 2000/06/27 11:36:56 priikone
34 * Imported from internal CVS/Added Log headers.
39 #include "clientincludes.h"
42 /* Long command line options */
43 static struct option long_opts[] =
46 { "server", 1, NULL, 's' },
47 { "port", 1, NULL, 'p' },
48 { "nickname", 1, NULL, 'n' },
49 { "channel", 1, NULL, 'c' },
50 { "cipher", 1, NULL, 'r' },
51 { "public-key", 1, NULL, 'b' },
52 { "private-key", 1, NULL, 'k' },
53 { "config-file", 1, NULL, 'f' },
54 { "no-silcrc", 0, NULL, 'q' },
55 { "help", 0, NULL, 'h' },
56 { "version", 0, NULL, 'V' },
57 { "list-ciphers", 0, NULL, 1 },
58 { "list-hash-funcs", 0, NULL, 2 },
59 { "list-pkcs", 0, NULL, 3 },
61 /* Key management options */
62 { "create-key-pair", 0, NULL, 'C' },
63 { "pkcs", 1, NULL, 10 },
64 { "bits", 1, NULL, 11 },
69 /* Command line option variables */
70 static char *opt_server = NULL;
71 static int opt_port = 0;
72 static char *opt_nickname = NULL;
73 static char *opt_channel = NULL;
74 static char *opt_cipher = NULL;
75 static char *opt_public_key = NULL;
76 static char *opt_private_key = NULL;
77 static char *opt_config_file = NULL;
78 static int opt_no_silcrc = FALSE;
80 static int opt_create_keypair = FALSE;
81 static char *opt_pkcs = NULL;
82 static int opt_bits = 0;
84 /* Prints out the usage of silc client */
89 Usage: silc [options]\n\
92 -s, --server=HOST Open connection to server HOST\n\
93 -p, --port=PORT Set PORT as default port to connect\n\
94 -n, --nickname=STRING Set default nickname on startup\n\
95 -c, --channel=STRING Join channel on startup\n\
96 -r, --cipher=CIPHER Use CIPHER as default cipher in SILC\n\
97 -b, --public-key=FILE Public key used in SILC\n\
98 -k, --private-key=FILE Private key used in SILC\n\
99 -f, --config-file=FILE Alternate configuration file\n\
100 -q, --no-silcrc Don't load ~/.silcrc on startup\n\
101 -h, --help Display this help message\n\
102 -V, --version Display version\n\
103 --list-ciphers List supported ciphers\n\
104 --list-hash-funcs List supported hash functions\n\
105 --list-pkcs List supported PKCS's\n\
107 Key Management Options:\n\
108 -C, --create-key-pair Create new public key pair\n\
109 --pkcs=PKCS Set the PKCS of the public key pair\n\
110 --bits=VALUE Set length of the public key pair\n\
114 int main(int argc, char **argv)
116 int opt, option_index = 1;
118 SilcClient silc = NULL;
119 SilcClientConfig config = NULL;
124 getopt_long(argc, argv,
125 "s:p:n:c:b:k:f:qhVC",
126 long_opts, &option_index)) != EOF)
135 opt_server = strdup(optarg);
139 opt_port = atoi(optarg);
143 opt_nickname = strdup(optarg);
147 opt_channel = strdup(optarg);
151 opt_cipher = strdup(optarg);
155 opt_public_key = strdup(optarg);
159 opt_private_key = strdup(optarg);
163 opt_config_file = strdup(optarg);
166 opt_no_silcrc = TRUE;
174 SILC Secure Internet Live Conferencing, version %s\n",
177 (c) 1997 - 2000 Pekka Riikonen <priikone@poseidon.pspt.fi>\n");
181 silc_client_list_ciphers();
185 silc_client_list_hash_funcs();
189 silc_client_list_pkcs();
194 * Key management options
197 opt_create_keypair = TRUE;
201 opt_pkcs = strdup(optarg);
205 opt_bits = atoi(optarg);
216 signal(SIGHUP, SIG_DFL);
217 signal(SIGTERM, SIG_DFL);
218 signal(SIGPIPE, SIG_IGN);
219 signal(SIGCHLD, SIG_DFL);
220 signal(SIGALRM, SIG_IGN);
221 signal(SIGQUIT, SIG_IGN);
222 signal(SIGSEGV, SIG_DFL);
223 signal(SIGBUS, SIG_DFL);
224 signal(SIGFPE, SIG_DFL);
225 // signal(SIGINT, SIG_IGN);
227 if (opt_create_keypair == TRUE) {
228 /* Create new key pair and exit */
229 silc_client_create_key_pair(opt_pkcs, opt_bits,
230 NULL, NULL, NULL, NULL, NULL);
234 /* Default configuration file */
235 if (!opt_config_file)
236 opt_config_file = strdup(SILC_CLIENT_CONFIG_FILE);
238 /* Read global configuration file. */
239 config = silc_client_config_alloc(opt_config_file);
243 /* Read local configuration file */
245 /* Check ~/.silc directory and public and private keys */
246 if (silc_client_check_silc_dir() == FALSE)
254 /* Allocate new client */
255 ret = silc_client_alloc(&silc);
259 /* Initialize the client */
260 silc->config = config;
261 ret = silc_client_init(silc);
266 silc_client_run(silc);
268 /* Stop the client. This probably has been done already but it
269 doesn't hurt to do it here again. */
270 silc_client_stop(silc);
271 silc_client_free(silc);
277 silc_free(opt_config_file);
279 silc_client_config_free(config);
281 silc_client_free(silc);