Print this page
4307 Variable is used before it is initialized in kwarndtest.c
Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/krb5/kwarn/kwarndtest.c
+++ new/usr/src/cmd/krb5/kwarn/kwarndtest.c
1 1 /*
2 2 * Copyright 1995-2002 Sun Microsystems, Inc. All rights reserved.
3 3 * Use is subject to license terms.
4 + *
5 + * Copyright 2013 Nexenta Systems. All rights reserved.
4 6 */
5 7
6 -#pragma ident "%Z%%M% %I% %E% SMI"
7 -
8 8 /*
9 9 * Test client for kwarnd. This program is not shipped on the binary
10 10 * release. This code was taken and modified from gssdtest.c
11 11 */
12 12
13 13 #include <stdio.h>
14 14 #include <strings.h>
15 15 #include <ctype.h>
16 16 #include <stdlib.h>
17 17 #include "kwarnd.h"
18 18 #include <rpc/rpc.h>
19 19
20 20 #define LOOP_COUNTER 100
21 21
22 22 #define OCTAL_MACRO "%03.3o."
23 23 #define MALLOC(n) malloc(n)
24 24 #define CALLOC(n, s) calloc((n), (s))
25 25 #define FREE(x, n) free(x)
26 26
27 27 static void instructs(void);
28 28 static void usage(void);
29 29 static int parse_input_line(char *, int *, char ***);
30 30 extern uid_t getuid(void);
31 31
32 32 static void _kwarnd_add_warning(int, char **);
33 33 static void _kwarnd_del_warning(int, char **);
34 34
35 35 static int do_kwarndtest(char *buf);
36 36
37 37 extern OM_UINT32 kwarn_add_warning();
38 38 extern OM_UINT32 kwarn_del_warning();
39 39
40 40 static int read_line(char *buf, int size)
41 41 {
42 42 int len;
43 43
44 44 /* read the next line. If cntl-d, return with zero char count */
45 45 printf(gettext("\n> "));
46 46
47 47 if (fgets(buf, size, stdin) == NULL)
48 48 return (0);
49 49
50 50 len = strlen(buf);
51 51 buf[--len] = '\0';
52 52 return (len);
53 53 }
54 54
55 55 int
56 56 main()
57 57 {
58 58 char buf[512];
59 59 int len, ret;
60 60
61 61 /* Print out usage and instructions to start off the session */
62 62
63 63 instructs();
64 64 usage();
65 65
66 66 /*
67 67 * Loop, repeatedly calling parse_input_line() to get the
68 68 * next line and parse it into argc and argv. Act on the
69 69 * arguements found on the line.
70 70 */
71 71
72 72 do {
73 73 len = read_line(buf, 512);
74 74 if (len)
75 75 ret = do_kwarndtest(buf);
76 76 } while (len && !ret);
77 77
78 78 return (0);
79 79 }
80 80
81 81 static int
82 82 do_kwarndtest(char *buf)
83 83 {
84 84 int argc;
85 85 char **argv, **argv_array;
86 86
87 87 char *cmd;
↓ open down ↓ |
70 lines elided |
↑ open up ↑ |
88 88
89 89 argv = 0;
90 90
91 91 if (parse_input_line(buf, &argc, &argv) == 0) {
92 92 printf(gettext("\n"));
93 93 return (1);
94 94 }
95 95
96 96 if (argc == 0) {
97 97 usage();
98 - /*LINTED*/
99 - FREE(argv_array, (argc+1)*sizeof (char *));
98 + FREE(argv, (argc+1)*sizeof (char *));
100 99 return (0);
101 100 }
102 101
103 102 /*
104 103 * remember argv_array address, which is memory calloc'd by
105 104 * parse_input_line, so it can be free'd at the end of the loop.
106 105 */
107 106
108 107 argv_array = argv;
109 108
110 109 cmd = argv[0];
111 110
112 111 argc--;
113 112 argv++;
114 113
115 114 if (strcmp(cmd, "kwarn_add_warning") == 0 ||
116 115 strcmp(cmd, "add") == 0) {
117 116 _kwarnd_add_warning(argc, argv);
118 117 } else if (strcmp(cmd, "kwarn_del_warning") == 0 ||
119 - strcmp(cmd, "delete") == 0) {
118 + strcmp(cmd, "delete") == 0) {
120 119 _kwarnd_del_warning(argc, argv);
121 120 } else if (strcmp(cmd, "exit") == 0) {
122 121 printf(gettext("\n"));
123 122 FREE(argv_array, (argc+2) * sizeof (char *));
124 123 return (1);
125 124 } else
126 125 usage();
127 126
128 127 /* free argv array */
129 128
130 129 FREE(argv_array, (argc+2) * sizeof (char *));
131 130 return (0);
132 131 }
133 132
134 133 static void
135 134 _kwarnd_add_warning(int argc, char **argv)
136 135 {
137 136 OM_UINT32 status;
138 137 time_t exptime;
139 138 time_t now;
140 139
141 140 /* set up the arguments specified in the input parameters */
142 141
143 142 if (argc == 0) {
144 143 usage();
145 144 return;
146 145 }
147 146
148 147 if (argc != 2) {
149 148 usage();
150 149 return;
151 150 }
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
152 151
153 152 time(&now);
154 153 exptime = atol(argv[1]);
155 154 exptime = now + exptime;
156 155
157 156 status = kwarn_add_warning(argv[0], exptime);
158 157
159 158 if (status == 0) {
160 159 printf(gettext("\nadd of credential\n\n"));
161 160 printf(gettext("warning message successful for \"%s\"\n\n"),
162 - argv[0]);
161 + argv[0]);
163 162 } else {
164 163 printf(gettext("server ret err (octal) %o (%s)\n"),
165 - status, gettext("add warning error"));
164 + status, gettext("add warning error"));
166 165 }
167 166
168 167 return;
169 168
170 169 }
171 170
172 171 static void
173 172 _kwarnd_del_warning(int argc, char **argv)
174 173 {
175 174 OM_UINT32 status;
176 175
177 176 if (argc != 1) {
178 177 usage();
179 178 return;
180 179 }
181 180
182 181 status = kwarn_del_warning(argv[0]);
183 182
184 183 if (status == 0) {
185 184 printf(gettext("delete of principal warning message"
186 - "for %s successful"),
187 - argv[0]);
185 + "for %s successful"),
186 + argv[0]);
188 187 } else {
189 188 printf(gettext("delete of principal %s unsuccessful\n\n"),
190 - argv[0]);
189 + argv[0]);
191 190 }
192 191 }
193 192
194 193 static void
195 194 instructs(void)
196 195 {
197 196 fprintf(stderr,
198 - gettext(
197 + gettext(
199 198 "\nThis program will test kwarnd. kwarnd must be running as root. Enter\n"
200 199 "the desired command and the principal to be added/deleted. If adding a\n"
201 200 "principal, also include the expiration time in seconds.\n"));
202 201 }
203 202
204 203 static void
205 204 usage(void)
206 205 {
207 206 fprintf(stderr,
208 - gettext(
209 - "\nusage:\t[kwarn_add_warning | add] (principal) (exptime)\n"
210 - "\t[kwarn_del_warning | delete] (principal)\n"
211 - "\texit\n\n"));
207 + gettext(
208 + "\nusage:\t[kwarn_add_warning | add] (principal) (exptime)\n"
209 + "\t[kwarn_del_warning | delete] (principal)\n"
210 + "\texit\n\n"));
212 211 }
213 212
214 213 /* Copied from parse_argv(), then modified */
215 214
216 215 static int
217 216 parse_input_line(char *input_line, int *argc, char ***argv)
218 217 {
219 218 const char nil = '\0';
220 219 char *chptr;
221 220 int chr_cnt;
222 221 int arg_cnt = 0;
223 222 int ch_was_space = 1;
224 223 int ch_is_space;
225 224
226 225 chr_cnt = strlen(input_line);
227 226
228 227 /* Count the arguments in the input_line string */
229 228
230 229 *argc = 1;
231 230
232 231 for (chptr = &input_line[0]; *chptr != nil; chptr++) {
233 232 ch_is_space = isspace(*chptr);
234 233 if (ch_is_space && !ch_was_space) {
235 234 (*argc)++;
236 235 }
237 236 ch_was_space = ch_is_space;
238 237 }
239 238
240 239 if (ch_was_space) {
241 240 (*argc)--;
242 241 } /* minus trailing spaces */
243 242
244 243 /* Now that we know how many args calloc the argv array */
245 244
246 245 *argv = (char **)CALLOC((*argc)+1, sizeof (char *));
247 246 chptr = (char *)(&input_line[0]);
248 247
249 248 for (ch_was_space = 1; *chptr != nil; chptr++) {
250 249 ch_is_space = isspace(*chptr);
251 250 if (ch_is_space) {
252 251 *chptr = nil; /* replace each space with nil */
253 252 } else if (ch_was_space) { /* begining of word? */
254 253 (*argv)[arg_cnt++] = chptr; /* new argument ? */
255 254 }
256 255
257 256 ch_was_space = ch_is_space;
258 257 }
259 258
260 259 return (chr_cnt);
261 260 }
↓ open down ↓ |
40 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX