Print this page
10120 smatch indenting fixes for usr/src/cmd
Reviewed by: Gergő Doma <domag02@gmail.com>
Portions contributed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/ndmpadm/ndmpadm_main.c
+++ new/usr/src/cmd/ndmpadm/ndmpadm_main.c
1 1 /*
2 2 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
3 3 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
4 + * Copyright (c) 2018, Joyent, Inc.
4 5 */
5 6
6 7 /*
7 8 * BSD 3 Clause License
8 9 *
9 10 * Copyright (c) 2007, The Storage Networking Industry Association.
10 11 *
11 12 * Redistribution and use in source and binary forms, with or without
12 13 * modification, are permitted provided that the following conditions
13 14 * are met:
14 15 * - Redistributions of source code must retain the above copyright
15 16 * notice, this list of conditions and the following disclaimer.
16 17 *
17 18 * - Redistributions in binary form must reproduce the above copyright
18 19 * notice, this list of conditions and the following disclaimer in
19 20 * the documentation and/or other materials provided with the
20 21 * distribution.
21 22 *
22 23 * - Neither the name of The Storage Networking Industry Association (SNIA)
23 24 * nor the names of its contributors may be used to endorse or promote
24 25 * products derived from this software without specific prior written
25 26 * permission.
26 27 *
27 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 31 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 32 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 38 * POSSIBILITY OF SUCH DAMAGE.
38 39 */
39 40 #include <assert.h>
40 41 #include <ctype.h>
41 42 #include <libgen.h>
42 43 #include <libintl.h>
43 44 #include <locale.h>
44 45 #include <stddef.h>
45 46 #include <stdio.h>
46 47 #include <stdlib.h>
47 48 #include <strings.h>
48 49 #include <unistd.h>
49 50 #include <fcntl.h>
50 51 #include <sys/stat.h>
51 52 #include <door.h>
52 53 #include <sys/mman.h>
53 54 #include <libndmp.h>
54 55 #include "ndmpadm.h"
55 56
56 57 typedef enum {
57 58 HELP_GET_CONFIG,
58 59 HELP_SET_CONFIG,
59 60 HELP_SHOW_DEVICES,
60 61 HELP_SHOW_SESSIONS,
61 62 HELP_KILL_SESSIONS,
62 63 HELP_ENABLE_AUTH,
63 64 HELP_DISABLE_AUTH
64 65 } ndmp_help_t;
65 66
66 67 typedef struct ndmp_command {
67 68 const char *nc_name;
68 69 int (*func)(int argc, char **argv,
69 70 struct ndmp_command *cur_cmd);
70 71 ndmp_help_t nc_usage;
71 72 } ndmp_command_t;
72 73
73 74 static int ndmp_get_config(int, char **, ndmp_command_t *);
74 75 static int ndmp_set_config(int, char **, ndmp_command_t *);
75 76 static int ndmp_show_devices(int, char **, ndmp_command_t *);
76 77 static int ndmp_show_sessions(int, char **, ndmp_command_t *);
77 78 static int ndmp_kill_sessions(int, char **, ndmp_command_t *);
78 79 static int ndmp_enable_auth(int, char **, ndmp_command_t *);
79 80 static int ndmp_disable_auth(int, char **, ndmp_command_t *);
80 81 static void ndmp_get_config_process(char *);
81 82 static void ndmp_set_config_process(char *arg);
82 83 static int ndmp_get_password(char **);
83 84
84 85 static ndmp_command_t command_table[] = {
85 86 { "get", ndmp_get_config, HELP_GET_CONFIG },
86 87 { "set", ndmp_set_config, HELP_SET_CONFIG },
87 88 { "show-devices", ndmp_show_devices, HELP_SHOW_DEVICES },
88 89 { "show-sessions", ndmp_show_sessions, HELP_SHOW_SESSIONS },
89 90 { "kill-sessions", ndmp_kill_sessions, HELP_KILL_SESSIONS },
90 91 { "enable", ndmp_enable_auth, HELP_ENABLE_AUTH },
91 92 { "disable", ndmp_disable_auth, HELP_DISABLE_AUTH }
92 93 };
93 94
94 95 #define NCOMMAND (sizeof (command_table) / sizeof (command_table[0]))
95 96
96 97 static char *prop_table[] = {
97 98 "debug-path",
98 99 "dump-pathnode",
99 100 "tar-pathnode",
100 101 "ignore-ctime",
101 102 "token-maxseq",
102 103 "version",
103 104 "dar-support",
104 105 "tcp-port",
105 106 "backup-quarantine",
106 107 "restore-quarantine",
107 108 "overwrite-quarantine",
108 109 "zfs-force-override",
109 110 "drive-type",
110 111 "debug-mode"
111 112 };
112 113
113 114 #define NDMPADM_NPROP (sizeof (prop_table) / sizeof (prop_table[0]))
114 115
115 116 typedef struct ndmp_auth {
116 117 const char *auth_type;
117 118 const char *username;
118 119 const char *password;
119 120 } ndmp_auth_t;
120 121
121 122 static ndmp_auth_t ndmp_auth_table[] = {
122 123 { "cram-md5", "cram-md5-username", "cram-md5-password" },
123 124 { "cleartext", "cleartext-username", "cleartext-password" }
124 125 };
125 126 #define NAUTH (sizeof (ndmp_auth_table) / sizeof (ndmp_auth_table[0]))
126 127 #define NDMP_PASSWORD_RETRIES 3
127 128
128 129 #if !defined(TEXT_DOMAIN)
129 130 #define TEXT_DOMAIN "SYS_TEST"
130 131 #endif
131 132
132 133 static const char *
133 134 get_usage(ndmp_help_t idx)
134 135 {
135 136 switch (idx) {
136 137 case HELP_SET_CONFIG:
137 138 return ("\tset [-p] <property=value> [[-p] property=value] "
138 139 "...\n");
139 140 case HELP_GET_CONFIG:
140 141 return ("\tget [-p] [property] [[-p] property] ...\n");
141 142 case HELP_SHOW_DEVICES:
142 143 return ("\tshow-devices\n");
143 144 case HELP_SHOW_SESSIONS:
144 145 return ("\tshow-sessions [-i tape,scsi,data,mover] [id] ...\n");
145 146 case HELP_KILL_SESSIONS:
146 147 return ("\tkill-sessions <id ...>\n");
147 148 case HELP_ENABLE_AUTH:
148 149 return ("\tenable <-a auth-type> <-u username>\n");
149 150 case HELP_DISABLE_AUTH:
150 151 return ("\tdisable <-a auth-type>\n");
151 152 }
152 153
153 154 return (NULL);
154 155 }
155 156
156 157 /*
157 158 * Display usage message. If we're inside a command, display only the usage for
158 159 * that command. Otherwise, iterate over the entire command table and display
159 160 * a complete usage message.
160 161 */
161 162 static void
162 163 usage(boolean_t requested, ndmp_command_t *current_command)
163 164 {
164 165 int i;
165 166 boolean_t show_properties = B_FALSE;
166 167 FILE *fp = requested ? stdout : stderr;
167 168
168 169 if (current_command == NULL) {
169 170 (void) fprintf(fp,
170 171 gettext("Usage: ndmpadm subcommand args ...\n"));
171 172 (void) fprintf(fp,
172 173 gettext("where 'command' is one of the following:\n\n"));
173 174
174 175 for (i = 0; i < NCOMMAND; i++) {
175 176 (void) fprintf(fp, "%s",
176 177 get_usage(command_table[i].nc_usage));
177 178 }
178 179 (void) fprintf(fp, gettext("\t\twhere %s can be either "
179 180 "%s or %s\n"), "'auth-type'", "'cram-md5'", "'cleartext'");
180 181 } else {
181 182 (void) fprintf(fp, gettext("Usage:\n"));
182 183 (void) fprintf(fp, "%s", get_usage(current_command->nc_usage));
183 184 if ((current_command->nc_usage == HELP_ENABLE_AUTH) ||
184 185 (current_command->nc_usage == HELP_DISABLE_AUTH))
185 186 (void) fprintf(fp, gettext("\t\twhere %s can be either "
186 187 "%s or %s\n"),
187 188 "'auth-type'", "'cram-md5'", "'cleartext'");
188 189 }
189 190
190 191 if (current_command != NULL &&
191 192 (strcmp(current_command->nc_name, "set") == 0))
192 193 show_properties = B_TRUE;
193 194
194 195 if (show_properties) {
195 196 (void) fprintf(fp,
196 197 gettext("\nThe following properties are supported:\n"));
197 198
198 199 (void) fprintf(fp, gettext("\n\tPROPERTY"));
199 200 (void) fprintf(fp, "\n\t%s", "-------------");
200 201 for (i = 0; i < NDMPADM_NPROP; i++)
201 202 (void) fprintf(fp, "\n\t%s", prop_table[i]);
202 203 (void) fprintf(fp, "\n");
203 204 }
204 205
205 206 exit(requested ? 0 : 2);
206 207 }
207 208
208 209 /*ARGSUSED*/
209 210 static int
210 211 ndmp_get_config(int argc, char **argv, ndmp_command_t *cur_cmd)
211 212 {
212 213 char *propval;
213 214 int i, c;
214 215
215 216 if (argc == 1) {
216 217 /*
217 218 * Get all the properties and variables ndmpadm is allowed
218 219 * to see.
219 220 */
220 221 for (i = 0; i < NDMPADM_NPROP; i++) {
221 222 if (ndmp_get_prop(prop_table[i], &propval)) {
222 223 (void) fprintf(stdout, "\t%s=\n",
223 224 prop_table[i]);
224 225 } else {
225 226 (void) fprintf(stdout, "\t%s=%s\n",
226 227 prop_table[i], propval);
227 228 free(propval);
228 229 }
229 230 }
230 231 } else if (argc > 1) {
231 232 while ((c = getopt(argc, argv, ":p:")) != -1) {
232 233 switch (c) {
233 234 case 'p':
234 235 ndmp_get_config_process(optarg);
235 236 break;
236 237 case ':':
237 238 (void) fprintf(stderr, gettext("Option -%c "
238 239 "requires an operand\n"), optopt);
239 240 break;
240 241 case '?':
241 242 (void) fprintf(stderr, gettext("Unrecognized "
242 243 "option: -%c\n"), optopt);
243 244 }
244 245 }
245 246 /*
246 247 * optind is initialized to 1 if the -p option is not used,
247 248 * otherwise index to argv.
248 249 */
249 250 argc -= optind;
250 251 argv += optind;
251 252
252 253 for (i = 0; i < argc; i++) {
253 254 if (strncmp(argv[i], "-p", 2) == 0)
254 255 continue;
255 256
256 257 ndmp_get_config_process(argv[i]);
257 258 }
258 259 }
259 260 return (0);
260 261 }
261 262
262 263 static void
263 264 ndmp_get_config_process(char *arg)
264 265 {
265 266 int j;
266 267 char *propval;
267 268
268 269 for (j = 0; j < NDMPADM_NPROP; j++) {
269 270 if (strcmp(arg, prop_table[j]) == 0) {
270 271 if (ndmp_get_prop(arg, &propval)) {
271 272 (void) fprintf(stdout, "\t%s=\n", arg);
272 273 } else {
273 274 (void) fprintf(stdout, "\t%s=%s\n",
274 275 arg, propval);
275 276 free(propval);
276 277 }
277 278 break;
278 279 }
279 280 }
280 281 if (j == NDMPADM_NPROP) {
281 282 (void) fprintf(stdout, gettext("\t%s is invalid property "
282 283 "or variable\n"), arg);
283 284 }
284 285 }
285 286
286 287 /*ARGSUSED*/
287 288 static int
288 289 ndmp_set_config(int argc, char **argv, ndmp_command_t *cur_cmd)
289 290 {
290 291 int c, i;
291 292
292 293 if (argc < 2) {
293 294 (void) fprintf(stderr, gettext("Missing property=value "
294 295 "argument\n"));
295 296 usage(B_FALSE, cur_cmd);
296 297 }
297 298 while ((c = getopt(argc, argv, ":p:")) != -1) {
298 299 switch (c) {
299 300 case 'p':
300 301 ndmp_set_config_process(optarg);
301 302 break;
302 303 case ':':
303 304 (void) fprintf(stderr, gettext("Option -%c "
304 305 "requires an operand\n"), optopt);
305 306 break;
306 307 case '?':
307 308 (void) fprintf(stderr, gettext("Unrecognized "
308 309 "option: -%c\n"), optopt);
309 310 }
310 311 }
311 312 /*
312 313 * optind is initialized to 1 if the -p option is not used,
313 314 * otherwise index to argv.
314 315 */
315 316 argc -= optind;
316 317 argv += optind;
317 318
318 319 for (i = 0; i < argc; i++) {
319 320 if (strncmp(argv[i], "-p", 2) == 0)
320 321 continue;
321 322
322 323 ndmp_set_config_process(argv[i]);
323 324 }
324 325 return (0);
325 326 }
↓ open down ↓ |
312 lines elided |
↑ open up ↑ |
326 327
327 328 static void
328 329 ndmp_set_config_process(char *propname)
329 330 {
330 331 char *propvalue;
331 332 int ret, j;
332 333
333 334 if ((propvalue = strchr(propname, '=')) == NULL) {
334 335 (void) fprintf(stderr, gettext("Missing value in "
335 336 "property=value argument for %s\n"), propname);
336 - return;
337 + return;
337 338 }
338 339 *propvalue = '\0';
339 340 propvalue++;
340 341
341 342 if (*propname == '\0') {
342 343 (void) fprintf(stderr, gettext("Missing property in "
343 344 "property=value argument for %s\n"), propname);
344 - return;
345 + return;
345 346 }
346 347 for (j = 0; j < NDMPADM_NPROP; j++) {
347 348 if (strcmp(propname, prop_table[j]) == 0)
348 349 break;
349 350 }
350 351 if (j == NDMPADM_NPROP) {
351 352 (void) fprintf(stdout, gettext("%s is invalid property or "
352 353 "variable\n"), propname);
353 354 return;
354 355 }
355 356 ret = ndmp_set_prop(propname, propvalue);
356 357 if (ret != -1) {
357 358 if (!ndmp_door_status()) {
358 359 if (ndmp_service_refresh() != 0)
359 360 (void) fprintf(stdout, gettext("Could not "
360 361 "refesh property of service ndmpd\n"));
361 362 }
362 363 } else {
363 364 (void) fprintf(stdout, gettext("Could not set property for "
364 365 "%s - %s\n"), propname, ndmp_strerror(ndmp_errno));
365 366 }
366 367 }
367 368
368 369 /*ARGSUSED*/
369 370 static int
370 371 ndmp_show_devices(int argc, char **argv, ndmp_command_t *cur_cmd)
371 372 {
372 373 int ret;
373 374 ndmp_devinfo_t *dip = NULL;
374 375 size_t size;
375 376
376 377 if (ndmp_door_status()) {
377 378 (void) fprintf(stdout,
378 379 gettext("Service ndmpd not running\n"));
379 380 return (-1);
380 381 }
381 382
382 383 ret = ndmp_get_devinfo(&dip, &size);
383 384
384 385 if (ret == -1)
385 386 (void) fprintf(stdout,
386 387 gettext("Could not get device information\n"));
387 388 else
388 389 ndmp_devinfo_print(dip, size);
389 390
390 391 ndmp_get_devinfo_free(dip, size);
391 392 return (0);
392 393 }
393 394
394 395 static int
395 396 ndmp_show_sessions(int argc, char **argv, ndmp_command_t *cur_cmd)
396 397 {
397 398 ndmp_session_info_t *sinfo = NULL;
398 399 ndmp_session_info_t *sp = NULL;
399 400 uint_t num;
400 401 int c, ret, i, j;
401 402 int statarg = 0;
402 403 char *value;
403 404 char *type_subopts[] = { "tape", "scsi", "data", "mover", NULL };
404 405
405 406 if (ndmp_door_status()) {
406 407 (void) fprintf(stdout,
407 408 gettext("Service ndmpd not running\n"));
408 409 return (-1);
409 410 }
410 411
411 412 /* Detail output if no option is specified */
412 413 if (argc == 1) {
413 414 statarg = NDMP_CAT_ALL;
414 415 } else {
415 416 statarg = 0;
416 417 while ((c = getopt(argc, argv, ":i:")) != -1) {
417 418 switch (c) {
418 419 case 'i':
419 420 while (*optarg != '\0') {
420 421 switch (getsubopt(&optarg, type_subopts,
421 422 &value)) {
422 423 case 0:
423 424 statarg |= NDMP_CAT_TAPE;
424 425 break;
425 426 case 1:
426 427 statarg |= NDMP_CAT_SCSI;
427 428 break;
428 429 case 2:
429 430 statarg |= NDMP_CAT_DATA;
430 431 break;
431 432 case 3:
432 433 statarg |= NDMP_CAT_MOVER;
433 434 break;
434 435 default:
435 436 (void) fprintf(stderr,
436 437 gettext("Invalid object "
437 438 "type '%s'\n"), value);
438 439 usage(B_FALSE, cur_cmd);
439 440 }
440 441 }
441 442 break;
442 443 case ':':
443 444 (void) fprintf(stderr,
444 445 gettext("Missing argument for "
445 446 "'%c' option\n"), optopt);
446 447 usage(B_FALSE, cur_cmd);
447 448 break;
448 449 case '?':
449 450 (void) fprintf(stderr,
450 451 gettext("Invalid option '%c'\n"), optopt);
451 452 usage(B_FALSE, cur_cmd);
452 453 }
453 454 }
454 455 /* if -i and its argument are not specified, display all */
455 456 if (statarg == 0)
456 457 statarg = NDMP_CAT_ALL;
457 458 }
458 459 /*
459 460 * optind is initialized to 1 if the -i option is not used, otherwise
460 461 * index to argv.
461 462 */
462 463 argc -= optind;
463 464 argv += optind;
464 465
465 466 ret = ndmp_get_session_info(&sinfo, &num);
466 467 if (ret == -1) {
467 468 (void) fprintf(stdout,
468 469 gettext("Could not get session information\n"));
469 470 } else {
470 471 if (argc == 0) {
471 472 ndmp_session_all_print(statarg, sinfo, num);
472 473 } else {
473 474 for (i = 0; i < argc; i++) {
474 475 sp = sinfo;
475 476 for (j = 0; j < num; j++, sp++) {
476 477 if (sp->nsi_sid == atoi(argv[i])) {
477 478 ndmp_session_print(statarg, sp);
478 479 (void) fprintf(stdout, "\n");
479 480 break;
480 481 }
481 482 }
482 483 if (j == num) {
483 484 (void) fprintf(stdout,
484 485 gettext("Session %d not "
485 486 "found\n"), atoi(argv[i]));
486 487 }
487 488 }
488 489 }
489 490 ndmp_get_session_info_free(sinfo, num);
490 491 }
491 492 return (0);
492 493 }
493 494
494 495 /*ARGSUSED*/
495 496 static int
496 497 ndmp_kill_sessions(int argc, char **argv, ndmp_command_t *cur_cmd)
497 498 {
498 499 int ret, i;
499 500
500 501 if (ndmp_door_status()) {
501 502 (void) fprintf(stdout,
502 503 gettext("Service ndmpd not running.\n"));
503 504 return (-1);
504 505 }
505 506
↓ open down ↓ |
151 lines elided |
↑ open up ↑ |
506 507 /* If no arg is specified, print the usage and exit */
507 508 if (argc == 1)
508 509 usage(B_FALSE, cur_cmd);
509 510
510 511 for (i = 1; i < argc; i++) {
511 512 if (atoi(argv[i]) > 0) {
512 513 ret = ndmp_terminate_session(atoi(argv[i]));
513 514 } else {
514 515 (void) fprintf(stderr,
515 516 gettext("Invalid argument %s\n"), argv[i]);
516 - continue;
517 + continue;
517 518 }
518 519 if (ret == -1)
519 520 (void) fprintf(stdout,
520 521 gettext("Session id %d not found.\n"),
521 522 atoi(argv[i]));
522 523 }
523 524 return (0);
524 525 }
525 526
526 527 static int
527 528 ndmp_get_password(char **password)
528 529 {
529 530 char *pw1, pw2[257];
530 531 int i;
531 532
532 533 for (i = 0; i < NDMP_PASSWORD_RETRIES; i++) {
533 534 /*
534 535 * getpassphrase use the same buffer to return password, so
535 536 * copy the result in different buffer, before calling the
536 537 * getpassphrase again.
537 538 */
538 539 if ((pw1 =
539 540 getpassphrase(gettext("Enter new password: "))) != NULL) {
540 541 (void) strlcpy(pw2, pw1, sizeof (pw2));
541 542 if ((pw1 =
542 543 getpassphrase(gettext("Re-enter password: ")))
543 544 != NULL) {
544 545 if (strncmp(pw1, pw2, strlen(pw1)) == 0) {
545 546 *password = pw1;
546 547 return (0);
547 548 } else {
548 549 (void) fprintf(stderr,
549 550 gettext("Both password did not "
550 551 "match.\n"));
551 552 }
552 553 }
553 554 }
554 555 }
555 556 return (-1);
556 557 }
557 558
558 559 static int
559 560 ndmp_enable_auth(int argc, char **argv, ndmp_command_t *cur_cmd)
560 561 {
561 562 char *auth_type, *username, *password;
562 563 int c, i, auth_type_flag = 0;
563 564 char *enc_password;
564 565
565 566 /* enable <-a auth-type> <-u username> */
566 567 if (argc != 5) {
567 568 usage(B_FALSE, cur_cmd);
568 569 }
569 570
570 571 while ((c = getopt(argc, argv, ":a:u:")) != -1) {
571 572 switch (c) {
572 573 case 'a':
573 574 auth_type = strdup(optarg);
574 575 break;
575 576 case 'u':
576 577 username = strdup(optarg);
577 578 break;
578 579 case ':':
579 580 (void) fprintf(stderr, gettext("Option -%c "
580 581 "requires an operand\n"), optopt);
581 582 usage(B_FALSE, cur_cmd);
582 583 break;
583 584 case '?':
584 585 (void) fprintf(stderr, gettext("Unrecognized "
585 586 "option: -%c\n"), optopt);
586 587 usage(B_FALSE, cur_cmd);
587 588 }
588 589 }
589 590
590 591 if ((auth_type) && (username)) {
591 592 if (ndmp_get_password(&password)) {
592 593 (void) fprintf(stderr, gettext("Could not get correct "
593 594 "password, exiting..."));
594 595 free(auth_type);
595 596 free(username);
596 597 exit(-1);
597 598 }
598 599 } else {
599 600 (void) fprintf(stderr, gettext("%s or %s can not be blank"),
600 601 "'auth-type'", "'username'");
601 602 free(auth_type);
602 603 free(username);
603 604 exit(-1);
604 605 }
605 606
606 607 if ((enc_password = ndmp_base64_encode(password)) == NULL) {
607 608 (void) fprintf(stdout,
608 609 gettext("Could not encode password - %s\n"),
609 610 ndmp_strerror(ndmp_errno));
610 611 free(auth_type);
611 612 free(username);
612 613 exit(-1);
613 614 }
614 615
615 616 for (i = 0; i < NAUTH; i++) {
616 617 if (strncmp(auth_type, ndmp_auth_table[i].auth_type,
617 618 strlen(ndmp_auth_table[i].auth_type)) == 0) {
618 619 auth_type_flag = 1;
619 620 if ((ndmp_set_prop(ndmp_auth_table[i].username,
620 621 username)) == -1) {
621 622 (void) fprintf(stdout,
622 623 gettext("Could not set username - %s\n"),
623 624 ndmp_strerror(ndmp_errno));
624 625 continue;
625 626 }
626 627 if ((ndmp_set_prop(ndmp_auth_table[i].password,
627 628 enc_password)) == -1) {
628 629 (void) fprintf(stdout,
629 630 gettext("Could not set password - %s\n"),
630 631 ndmp_strerror(ndmp_errno));
631 632 continue;
632 633 }
633 634 if (!ndmp_door_status() &&
634 635 (ndmp_service_refresh()) != 0) {
635 636 (void) fprintf(stdout,
636 637 gettext("Could not refesh ndmpd service "
637 638 "properties\n"));
638 639 }
639 640 }
640 641 }
641 642 free(auth_type);
642 643 free(username);
643 644 free(enc_password);
644 645
645 646 if (!auth_type_flag)
646 647 usage(B_FALSE, cur_cmd);
647 648
648 649 return (0);
649 650 }
650 651
651 652 static int
652 653 ndmp_disable_auth(int argc, char **argv, ndmp_command_t *cur_cmd)
653 654 {
654 655 char *auth_type;
655 656 int c, i, auth_type_flag = 0;
656 657
657 658 /* disable <-a auth-type> */
658 659 if (argc != 3) {
659 660 usage(B_FALSE, cur_cmd);
660 661 }
661 662
662 663 while ((c = getopt(argc, argv, ":a:")) != -1) {
663 664 switch (c) {
664 665 case 'a':
665 666 auth_type = strdup(optarg);
666 667 break;
667 668 case ':':
668 669 (void) fprintf(stderr, gettext("Option -%c "
669 670 "requires an operand\n"), optopt);
670 671 break;
671 672 case '?':
672 673 (void) fprintf(stderr, gettext("Unrecognized "
673 674 "option: -%c\n"), optopt);
674 675 }
675 676 }
676 677 for (i = 0; i < NAUTH; i++) {
677 678 if (strncmp(auth_type, ndmp_auth_table[i].auth_type,
678 679 strlen(ndmp_auth_table[i].auth_type)) == 0) {
679 680 auth_type_flag = 1;
680 681 if ((ndmp_set_prop(ndmp_auth_table[i].username,
681 682 "")) == -1) {
682 683 (void) fprintf(stdout,
683 684 gettext("Could not clear username - %s\n"),
684 685 ndmp_strerror(ndmp_errno));
685 686 continue;
686 687 }
687 688 if ((ndmp_set_prop(ndmp_auth_table[i].password,
688 689 "")) == -1) {
689 690 (void) fprintf(stdout,
690 691 gettext("Could not clear password - %s\n"),
691 692 ndmp_strerror(ndmp_errno));
692 693 continue;
693 694 }
694 695 if (!ndmp_door_status() &&
695 696 (ndmp_service_refresh()) != 0) {
696 697 (void) fprintf(stdout, gettext("Could not "
697 698 "refesh ndmpd service properties\n"));
698 699 }
699 700 }
700 701 }
701 702 free(auth_type);
702 703
703 704 if (!auth_type_flag)
704 705 usage(B_FALSE, cur_cmd);
705 706
706 707 return (0);
707 708 }
708 709
709 710 int
710 711 main(int argc, char **argv)
711 712 {
712 713 int ret;
713 714 int i;
714 715 char *cmdname;
715 716 ndmp_command_t *current_command = NULL;
716 717
717 718 (void) setlocale(LC_ALL, "");
718 719 (void) textdomain(TEXT_DOMAIN);
719 720
720 721 opterr = 0;
721 722
722 723 /* Make sure the user has specified some command. */
723 724 if (argc < 2) {
724 725 (void) fprintf(stderr, gettext("Missing command.\n"));
725 726 usage(B_FALSE, current_command);
726 727 }
727 728
728 729 cmdname = argv[1];
729 730
730 731 /*
731 732 * Special case '-?'
732 733 */
733 734 if (strcmp(cmdname, "-?") == 0)
734 735 usage(B_TRUE, current_command);
735 736
736 737 /*
737 738 * Run the appropriate sub-command.
738 739 */
739 740 for (i = 0; i < NCOMMAND; i++) {
740 741 if (strcmp(cmdname, command_table[i].nc_name) == 0) {
741 742 current_command = &command_table[i];
742 743 ret = command_table[i].func(argc - 1, argv + 1,
743 744 current_command);
744 745 break;
745 746 }
746 747 }
747 748
748 749 if (i == NCOMMAND) {
749 750 (void) fprintf(stderr, gettext("Unrecognized "
750 751 "command '%s'\n"), cmdname);
751 752 usage(B_FALSE, current_command);
752 753 }
753 754
754 755 return (ret);
755 756 }
↓ open down ↓ |
229 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX