annotate cli-runopts.c @ 46:3bea78e1b175

Filled out a bit, with commandline support etc
author Matt Johnston <matt@ucc.asn.au>
date Fri, 06 Aug 2004 02:51:17 +0000
parents b4874d772210
children 4b53a43f0082
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 /*
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 * Dropbear - a SSH2 server
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 *
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 * Copyright (c) 2002,2003 Matt Johnston
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 * All rights reserved.
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 *
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 * of this software and associated documentation files (the "Software"), to deal
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 * in the Software without restriction, including without limitation the rights
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 * copies of the Software, and to permit persons to whom the Software is
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 * furnished to do so, subject to the following conditions:
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 *
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 * The above copyright notice and this permission notice shall be included in
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 * all copies or substantial portions of the Software.
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 *
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 * SOFTWARE. */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 #include "includes.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 #include "runopts.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 #include "signkey.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 #include "buffer.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 #include "dbutil.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 #include "algo.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 cli_runopts cli_opts; /* GLOBAL */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 static void printhelp(const char * progname);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 static void printhelp(const char * progname) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 fprintf(stderr, "Dropbear client v%s\n"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 "Usage: %s [options] [email protected][:port]\n"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 "Options are:\n"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 "user Remote username\n"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 "host Remote host\n"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 "port Remote port\n"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 ,DROPBEAR_VERSION, progname);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 void cli_getopts(int argc, char ** argv) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48
46
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
49 unsigned int i, j;
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 char ** next = 0;
46
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
51 unsigned int cmdlen;
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
52 int nextiskey = 0; /* A flag if the next argument is a keyfile */
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54 uid_t uid;
46
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
55 struct passwd *pw = NULL;
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 char* userhostarg = NULL;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 /* see printhelp() for options */
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
60 cli_opts.progname = argv[0];
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 cli_opts.remotehost = NULL;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 cli_opts.remoteport = NULL;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 cli_opts.username = NULL;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 cli_opts.cmd = NULL;
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
65 cli_opts.wantpty = 1;
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66 opts.nolocaltcp = 0;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 opts.noremotetcp = 0;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 /* not yet
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 opts.ipv4 = 1;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70 opts.ipv6 = 1;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73 if (argc != 2) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 printhelp(argv[0]);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 exit(EXIT_FAILURE);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77
46
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
78 for (i = 1; i < (unsigned int)argc; i++) {
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
79 if (nextiskey) {
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
80 /* XXX do stuff */
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
81 break;
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83 if (next) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 *next = argv[i];
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 if (*next == NULL) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 dropbear_exit("Invalid null argument");
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 }
46
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
88 next = NULL;
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 continue;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92 if (argv[i][0] == '-') {
46
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
93
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
94 /* A flag *waves* */
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 switch (argv[i][1]) {
46
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
96 case 'p':
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
97 next = &cli_opts.remoteport;
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 break;
46
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
99 #ifdef DROPBEAR_PUBKEY_AUTH
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
100 case 'i':
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
101 nextiskey = 1;
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
102 break;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
103 #endif
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104 default:
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105 fprintf(stderr, "Unknown argument %s\n", argv[i]);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106 printhelp(argv[0]);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107 exit(EXIT_FAILURE);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108 break;
46
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
109 } /* Switch */
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
110
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
111 } else {
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
112
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
113 /* Either the hostname or commands */
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
114 /* Hostname is first up, must be set before we get the cmds */
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
115
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
116 if (cli_opts.remotehost == NULL) {
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
117 /* We'll be editing it, should probably make a copy */
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
118 userhostarg = m_strdup(argv[1]);
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
119
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
120 cli_opts.remotehost = strchr(userhostarg, '@');
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
121 if (cli_opts.remotehost == NULL) {
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
122 /* no username portion, the cli-auth.c code can figure the
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
123 * local user's name */
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
124 cli_opts.remotehost = userhostarg;
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
125 } else {
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
126 cli_opts.remotehost[0] = '\0'; /* Split the user/host */
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
127 cli_opts.remotehost++;
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
128 cli_opts.username = userhostarg;
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
129 }
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
130
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
131 if (cli_opts.username == NULL) {
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
132 uid = getuid();
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
133
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
134 pw = getpwuid(uid);
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
135 if (pw == NULL || pw->pw_name == NULL) {
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
136 dropbear_exit("I don't know my own [user]name");
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
137 }
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
138
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
139 cli_opts.username = m_strdup(pw->pw_name);
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
140 }
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
141
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
142 if (cli_opts.remotehost[0] == '\0') {
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
143 dropbear_exit("Bad hostname");
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
144 }
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
145 } else {
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
146 /* this is part of the commands to send - after this we
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
147 * don't parse any more options, and flags are sent as the
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
148 * command */
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
149 cmdlen = 0;
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
150 for (j = i; j < (unsigned int)argc; j++) {
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
151 cmdlen += strlen(argv[j]) + 1; /* +1 for spaces */
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
152 }
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
153 /* Allocate the space */
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
154 cli_opts.cmd = (char*)m_malloc(cmdlen);
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
155 cli_opts.cmd[0] = '\0';
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
156
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
157 /* Append all the bits */
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
158 for (j = i; j < (unsigned int)argc; j++) {
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
159 strlcat(cli_opts.cmd, argv[j], cmdlen);
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
160 strlcat(cli_opts.cmd, " ", cmdlen);
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
161 }
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
162 /* It'll be null-terminated here */
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
163
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
164 /* We've eaten all the options and flags */
3bea78e1b175 Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
165 break;
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
166 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
167 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
168 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
169 }