diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2003-03-23 00:18:44 +0000 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2003-03-23 00:18:44 +0000 |
commit | 6ab85f1997b8842646abb4f5d3299c7027f9e6aa (patch) | |
tree | fe7dbff6998942335ed29d250edff9871e9e11f5 /source3/utils | |
parent | 42879b0bf3b1ae6a74dfb9932532f8fdf63d691d (diff) | |
download | samba-6ab85f1997b8842646abb4f5d3299c7027f9e6aa.tar.gz samba-6ab85f1997b8842646abb4f5d3299c7027f9e6aa.tar.bz2 samba-6ab85f1997b8842646abb4f5d3299c7027f9e6aa.zip |
Convert to popt.
(This used to be commit 633b3eb7812dc0a58785536a1e7d28329d488b43)
Diffstat (limited to 'source3/utils')
-rw-r--r-- | source3/utils/profiles.c | 110 |
1 files changed, 56 insertions, 54 deletions
diff --git a/source3/utils/profiles.c b/source3/utils/profiles.c index 4f40b93810..b2b351b2fc 100644 --- a/source3/utils/profiles.c +++ b/source3/utils/profiles.c @@ -1,6 +1,7 @@ /* Samba Unix/Linux SMB client utility profiles.c Copyright (C) 2002 Richard Sharpe, rsharpe@richardsharpe.com + Copyright (C) 2003 Jelmer Vernooij This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -514,21 +515,8 @@ static void process_acl(ACL *acl, const char *prefix) } } -static void usage(void) -{ - fprintf(stderr, "usage: profiles [-c <OLD-SID> -n <NEW-SID>] <profilefile>\n"); - fprintf(stderr, "Version: %s\n", VERSION); - fprintf(stderr, "\n\t-v\t sets verbose mode"); - fprintf(stderr, "\n\t-c S-1-5-21-z-y-x-oldrid - provides SID to change"); - fprintf(stderr, "\n\t-n S-1-5-21-a-b-c-newrid - provides SID to change to"); - fprintf(stderr, "\n\t\tBoth must be present if the other is."); - fprintf(stderr, "\n\t\tIf neither present, just report the SIDs found\n"); -} - int main(int argc, char *argv[]) { - extern char *optarg; - extern int optind; int opt; int fd, start = 0; char *base; @@ -540,63 +528,75 @@ int main(int argc, char *argv[]) DWORD first_sk_off, sk_off; MY_SEC_DESC *sec_desc; int *ptr; + struct poptOption long_options[] = { + POPT_AUTOHELP + { "verbose", 'v', POPT_ARG_NONE, NULL, 'v', "Sets verbose mode" }, + { "change-sid", 'c', POPT_ARG_STRING, NULL, 'c', "Provides SID to change" }, + { "new-sid", 'n', POPT_ARG_STRING, NULL, 'n', "Provides SID to change to" }, + { 0, 0, 0, 0 } + }; - if (argc < 2) { - usage(); - exit(1); - } + poptContext pc; + + pc = poptGetContext("profiles", argc, (const char **)argv, long_options, + POPT_CONTEXT_KEEP_FIRST); + + poptSetOtherOptionHelp(pc, "<profilefile>"); /* * Now, process the arguments */ - while ((opt = getopt(argc, argv, "c:n:v")) != EOF) { + while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { - case 'c': - change = 1; - if (!get_sid(&old_sid, optarg)) { - fprintf(stderr, "Argument to -c should be a SID in form of S-1-5-...\n"); - usage(); - exit(254); - } - break; - - case 'n': - new = 1; - if (!get_sid(&new_sid, optarg)) { - fprintf(stderr, "Argument to -n should be a SID in form of S-1-5-...\n"); - usage(); - exit(253); - } - - break; - - case 'v': - verbose++; - break; + case 'c': + change = 1; + if (!get_sid(&old_sid, poptGetOptArg(pc))) { + fprintf(stderr, "Argument to -c should be a SID in form of S-1-5-...\n"); + poptPrintUsage(pc, stderr, 0); + exit(254); + } + break; + + case 'n': + new = 1; + if (!get_sid(&new_sid, poptGetOptArg(pc))) { + fprintf(stderr, "Argument to -n should be a SID in form of S-1-5-...\n"); + poptPrintUsage(pc, stderr, 0); + exit(253); + } + + break; + + case 'v': + verbose++; + break; + } + } - default: - usage(); - exit(255); - } + if (!poptPeekArg(pc)) { + poptPrintUsage(pc, stderr, 0); + exit(1); } if ((!change & new) || (change & !new)) { - fprintf(stderr, "You must specify both -c and -n if one or the other is set!\n"); - usage(); - exit(252); + fprintf(stderr, "You must specify both -c and -n if one or the other is set!\n"); + poptPrintUsage(pc, stderr, 0); + exit(252); } - fd = open(argv[optind], O_RDWR, 0000); + poptGetArg(pc); /* To get argv[0] */ + + fd = open(poptPeekArg(pc), O_RDWR, 0000); if (fd < 0) { - fprintf(stderr, "Could not open %s: %s\n", argv[optind], + fprintf(stderr, "Could not open %s: %s\n", poptPeekArg(pc), strerror(errno)); exit(2); } if (fstat(fd, &sbuf) < 0) { - fprintf(stderr, "Could not stat file %s, %s\n", argv[optind], + fprintf(stderr, "Could not stat file %s, %s\n", poptPeekArg(pc), strerror(errno)); exit(3); } @@ -609,7 +609,7 @@ int main(int argc, char *argv[]) base = mmap(&start, sbuf.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if ((int)base == -1) { - fprintf(stderr, "Could not mmap file: %s, %s\n", argv[optind], + fprintf(stderr, "Could not mmap file: %s, %s\n", poptPeekArg(pc), strerror(errno)); exit(4); } @@ -640,7 +640,7 @@ int main(int argc, char *argv[]) if (verbose) fprintf(stdout, "Registry file size: %u\n", (unsigned int)sbuf.st_size); if (IVAL(®f_hdr->REGF_ID, 0) != REG_REGF_ID) { - fprintf(stderr, "Incorrect Registry file (doesn't have header ID): %s\n", argv[optind]); + fprintf(stderr, "Incorrect Registry file (doesn't have header ID): %s\n", poptPeekArg(pc)); exit(5); } @@ -655,7 +655,7 @@ int main(int argc, char *argv[]) */ if (IVAL(&hbin_hdr->HBIN_ID, 0) != REG_HBIN_ID) { - fprintf(stderr, "Incorrect hbin hdr: %s\n", argv[optind]); + fprintf(stderr, "Incorrect hbin hdr: %s\n", poptPeekArg(pc)); exit(6); } @@ -666,7 +666,7 @@ int main(int argc, char *argv[]) nk_hdr = (NK_HDR *)(base + 0x1000 + IVAL(®f_hdr->first_key, 0) + 4); if (SVAL(&nk_hdr->NK_ID, 0) != REG_NK_ID) { - fprintf(stderr, "Incorrect NK Header: %s\n", argv[optind]); + fprintf(stderr, "Incorrect NK Header: %s\n", poptPeekArg(pc)); exit(7); } @@ -724,6 +724,8 @@ int main(int argc, char *argv[]) munmap(base, sbuf.st_size); + poptFreeContext(pc); + close(fd); return 0; } |