diff options
author | Tim Potter <tpot@samba.org> | 2003-04-14 03:59:04 +0000 |
---|---|---|
committer | Tim Potter <tpot@samba.org> | 2003-04-14 03:59:04 +0000 |
commit | 5f82e261c664707a57c94424b7db20040c65237d (patch) | |
tree | 79ff2ed60ea988f2cab1897c16079cb26bdf0228 /source3 | |
parent | c89a7057e5334ab8dadb4a847c2dc74434c1cc49 (diff) | |
download | samba-5f82e261c664707a57c94424b7db20040c65237d.tar.gz samba-5f82e261c664707a57c94424b7db20040c65237d.tar.bz2 samba-5f82e261c664707a57c94424b7db20040c65237d.zip |
Merge:
- Jelmer's latest popt changes
(This used to be commit 6a54d9a0a77c71664dc6cdbed1adf492c28c0cce)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/utils/net.c | 27 | ||||
-rw-r--r-- | source3/utils/nmblookup.c | 224 | ||||
-rw-r--r-- | source3/utils/ntlm_auth.c | 3 | ||||
-rw-r--r-- | source3/utils/profiles.c | 126 | ||||
-rw-r--r-- | source3/utils/smbcacls.c | 166 | ||||
-rw-r--r-- | source3/utils/testparm.c | 11 | ||||
-rw-r--r-- | source3/wrepld/server.c | 117 |
7 files changed, 242 insertions, 432 deletions
diff --git a/source3/utils/net.c b/source3/utils/net.c index 7588771fbc..f8ed590d4b 100644 --- a/source3/utils/net.c +++ b/source3/utils/net.c @@ -70,7 +70,6 @@ int opt_maxusers = -1; const char *opt_comment = ""; char *opt_container = "cn=Users"; int opt_flags = -1; -int opt_jobid = 0; int opt_timeout = 0; const char *opt_target_workgroup = NULL; static int opt_machine_pass = 0; @@ -78,8 +77,6 @@ static int opt_machine_pass = 0; BOOL opt_have_ip = False; struct in_addr opt_dest_ip; -extern BOOL AllowDebugChange; - /* run a function from a function table. If not found then call the specified usage function @@ -454,7 +451,7 @@ static int net_maxrid(int argc, const char **argv) uint32 rid; if (argc != 0) { - DEBUG(0, ("usage: net initrid\n")); + DEBUG(0, ("usage: net maxrid\n")); return 1; } @@ -513,31 +510,26 @@ static struct functable net_func[] = { int argc_new = 0; const char ** argv_new; poptContext pc; - static char *servicesf = dyn_CONFIGFILE; - static char *debuglevel = NULL; struct poptOption long_options[] = { {"help", 'h', POPT_ARG_NONE, 0, 'h'}, {"workgroup", 'w', POPT_ARG_STRING, &opt_target_workgroup}, - {"myworkgroup", 'W', POPT_ARG_STRING, &opt_workgroup}, {"user", 'U', POPT_ARG_STRING, &opt_user_name, 'U'}, {"ipaddress", 'I', POPT_ARG_STRING, 0,'I'}, {"port", 'p', POPT_ARG_INT, &opt_port}, {"myname", 'n', POPT_ARG_STRING, &opt_requester_name}, - {"conf", 's', POPT_ARG_STRING, &servicesf}, {"server", 'S', POPT_ARG_STRING, &opt_host}, {"container", 'c', POPT_ARG_STRING, &opt_container}, {"comment", 'C', POPT_ARG_STRING, &opt_comment}, {"maxusers", 'M', POPT_ARG_INT, &opt_maxusers}, {"flags", 'F', POPT_ARG_INT, &opt_flags}, - {"jobid", 'j', POPT_ARG_INT, &opt_jobid}, {"long", 'l', POPT_ARG_NONE, &opt_long_list_entries}, {"reboot", 'r', POPT_ARG_NONE, &opt_reboot}, {"force", 'f', POPT_ARG_NONE, &opt_force}, {"timeout", 't', POPT_ARG_INT, &opt_timeout}, {"machine-pass",'P', POPT_ARG_NONE, &opt_machine_pass}, - {"debuglevel", 'd', POPT_ARG_STRING, &debuglevel}, - {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version}, + {"myworkgroup", 'W', POPT_ARG_STRING, &opt_workgroup}, + POPT_COMMON_SAMBA { 0, 0, 0, 0} }; @@ -577,13 +569,8 @@ static struct functable net_func[] = { exit(1); } } - - if (debuglevel) { - debug_parse_levels(debuglevel); - AllowDebugChange = False; - } - - lp_load(servicesf,True,False,False); + + lp_load(dyn_CONFIGFILE,True,False,False); argv_new = (const char **)poptGetArgs(pc); @@ -636,6 +623,10 @@ static struct functable net_func[] = { exit(1); } } + + if (!opt_password) { + opt_password = getenv("PASSWD"); + } rc = net_run_function(argc_new-1, argv_new+1, net_func, net_help); diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 7e0ed4a203..d2c5cbc00e 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -2,6 +2,7 @@ Unix SMB/CIFS implementation. NBT client - used to lookup netbios names Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Jelmer Vernooij 2003 (Conversion to popt) 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 @@ -54,31 +55,6 @@ static BOOL open_sockets(void) return True; } - -/**************************************************************************** -usage on the program -****************************************************************************/ -static void usage(void) -{ - d_printf("Usage: nmblookup [options] name\n"); - d_printf("Version %s\n",VERSION); - d_printf("\t-d debuglevel set the debuglevel\n"); - d_printf("\t-B broadcast address the address to use for broadcasts\n"); - d_printf("\t-f list the NMB flags returned\n"); - d_printf("\t-U unicast address the address to use for unicast\n"); - d_printf("\t-M searches for a master browser\n"); - d_printf("\t-R set recursion desired in packet\n"); - d_printf("\t-S lookup node status as well\n"); - d_printf("\t-T translate IP addresses into names\n"); - d_printf("\t-r Use root port 137 (Win95 only replies to this)\n"); - d_printf("\t-A Do a node status on <name> as an IP Address\n"); - d_printf("\t-i NetBIOS scope Use the given NetBIOS scope for name queries\n"); - d_printf("\t-s smb.conf file Use the given path to the smb.conf file\n"); - d_printf("\t-h Print this help message.\n"); - d_printf("\n If you specify -M and name is \"-\", nmblookup looks up __MSBROWSE__<01>\n"); - d_printf("\n"); -} - /**************************************************************************** turn a node status flags field into a string ****************************************************************************/ @@ -211,130 +187,106 @@ int main(int argc,char *argv[]) int opt; unsigned int lookup_type = 0x0; fstring lookup; - extern int optind; - extern char *optarg; - BOOL find_master=False; - int i; - BOOL lookup_by_ip = False; - int commandline_debuglevel = -2; - - DEBUGLEVEL = 1; - /* Prevent smb.conf setting from overridding */ - AllowDebugChange = False; - + static BOOL find_master=False; + static BOOL lookup_by_ip = False; + poptContext pc; + + struct poptOption long_options[] = { + POPT_AUTOHELP + { "broadcast", 'B', POPT_ARG_STRING, NULL, 'B', "Specify address to use for broadcasts", "BROADCAST-ADDRESS" }, + { "flags", 'f', POPT_ARG_VAL, &give_flags, True, "List the NMB flags returned" }, + { "unicast", 'U', POPT_ARG_STRING, NULL, 'U', "Specify address to use for unicast" }, + { "master-browser", 'M', POPT_ARG_VAL, &find_master, True, "Search for a master browser" }, + { "recursion", 'R', POPT_ARG_VAL, &recursion_desired, True, "Set recursion desired in package" }, + { "status", 'S', POPT_ARG_VAL, &find_status, True, "Lookup node status as well" }, + { "translate", 'T', POPT_ARG_NONE, NULL, 'T', "Translate IP addresses into names" }, + { "root-port", 'r', POPT_ARG_VAL, &RootPort, True, "Use root port 137 (Win95 only replies to this)" }, + { "lookup-by-ip", 'A', POPT_ARG_VAL, &lookup_by_ip, True, "Do a node status on <name> as an IP Address" }, + POPT_COMMON_SAMBA + POPT_COMMON_CONNECTION + { 0, 0, 0, 0 } + }; + *lookup = 0; setup_logging(argv[0],True); - while ((opt = getopt(argc, argv, "d:fB:U:i:s:SMrhART")) != EOF) - switch (opt) - { - case 'B': - bcast_addr = *interpret_addr2(optarg); - got_bcast = True; - use_bcast = True; - break; - case 'f': - give_flags = True; - break; - case 'U': - bcast_addr = *interpret_addr2(optarg); - got_bcast = True; - use_bcast = False; - break; - case 'T': - translate_addresses = !translate_addresses; - break; - case 'i': - set_global_scope(optarg); - break; - case 'M': - find_master = True; - break; - case 'S': - find_status = True; - break; - case 'R': - recursion_desired = True; - break; - case 'd': - commandline_debuglevel = DEBUGLEVEL = atoi(optarg); - break; - case 's': - pstrcpy(dyn_CONFIGFILE, optarg); - break; - case 'r': - RootPort = True; - break; - case 'h': - usage(); - exit(0); - break; - case 'A': - lookup_by_ip = True; - break; - default: - usage(); - exit(1); - } - - if (argc < 2) { - usage(); - exit(1); + pc = poptGetContext("nmblookup", argc, (const char **)argv, long_options, + POPT_CONTEXT_KEEP_FIRST); + + poptSetOtherOptionHelp(pc, "<NODE> ..."); + + while ((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case 'B': + bcast_addr = *interpret_addr2(poptGetOptArg(pc)); + got_bcast = True; + use_bcast = True; + break; + case 'U': + bcast_addr = *interpret_addr2(poptGetOptArg(pc)); + got_bcast = True; + use_bcast = False; + break; + case 'T': + translate_addresses = !translate_addresses; + break; + } } - if (!lp_load(dyn_CONFIGFILE,True,False,False)) { - fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE); - } + poptGetArg(pc); /* Remove argv[0] */ - /* - * Ensure we reset DEBUGLEVEL if someone specified it - * on the command line. - */ + if(!poptPeekArg(pc)) { + poptPrintUsage(pc, stderr, 0); + exit(1); + } - if(commandline_debuglevel != -2) - DEBUGLEVEL = commandline_debuglevel; + if (!lp_load(dyn_CONFIGFILE,True,False,False)) { + fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE); + } load_interfaces(); if (!open_sockets()) return(1); - for (i=optind;i<argc;i++) + while(poptPeekArg(pc)) { - char *p; - struct in_addr ip; - - fstrcpy(lookup,argv[i]); - - if(lookup_by_ip) - { - fstrcpy(lookup,"*"); - ip = *interpret_addr2(argv[i]); - do_node_status(ServerFD, lookup, lookup_type, ip); - continue; - } - - if (find_master) { - if (*lookup == '-') { - fstrcpy(lookup,"\01\02__MSBROWSE__\02"); - lookup_type = 1; - } else { - lookup_type = 0x1d; - } - } - - p = strchr_m(lookup,'#'); - if (p) { - *p = '\0'; - sscanf(++p,"%x",&lookup_type); - } - - if (!query_one(lookup, lookup_type)) { - d_printf( "name_query failed to find name %s", lookup ); - if( 0 != lookup_type ) - d_printf( "#%02x", lookup_type ); - d_printf( "\n" ); - } + char *p; + struct in_addr ip; + + fstrcpy(lookup,poptGetArg(pc)); + + if(lookup_by_ip) + { + ip = *interpret_addr2(lookup); + fstrcpy(lookup,"*"); + do_node_status(ServerFD, lookup, lookup_type, ip); + continue; + } + + if (find_master) { + if (*lookup == '-') { + fstrcpy(lookup,"\01\02__MSBROWSE__\02"); + lookup_type = 1; + } else { + lookup_type = 0x1d; + } + } + + p = strchr_m(lookup,'#'); + if (p) { + *p = '\0'; + sscanf(++p,"%x",&lookup_type); + } + + if (!query_one(lookup, lookup_type)) { + d_printf( "name_query failed to find name %s", lookup ); + if( 0 != lookup_type ) + d_printf( "#%02x", lookup_type ); + d_printf( "\n" ); + } } - + + poptFreeContext(pc); + return(0); } diff --git a/source3/utils/ntlm_auth.c b/source3/utils/ntlm_auth.c index 0bead042fd..88913c8051 100644 --- a/source3/utils/ntlm_auth.c +++ b/source3/utils/ntlm_auth.c @@ -735,7 +735,8 @@ enum { { "request-lm-key", 0, POPT_ARG_NONE, &request_lm_key, OPT_LM_KEY, "Retreive LM session key"}, { "request-nt-key", 0, POPT_ARG_NONE, &request_nt_key, OPT_NT_KEY, "Retreive NT session key"}, { "diagnostics", 0, POPT_ARG_NONE, &diagnostics, OPT_DIAGNOSTICS, "Perform diagnostics on the authentictaion chain"}, - { NULL, 0, 0, NULL, 0, NULL} + POPT_COMMON_SAMBA + POPT_TABLEEND }; /* Samba client initialisation */ diff --git a/source3/utils/profiles.c b/source3/utils/profiles.c index 2ed102b677..7c2d820c81 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 (conversion to popt) 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 @@ -34,7 +35,7 @@ times... the "regf"-Block ================ -"regf" is obviosly the abbreviation for "Registry file". "regf" is the +"regf" is obviously the abbreviation for "Registry file". "regf" is the signature of the header-block which is always 4kb in size, although only the first 64 bytes seem to be used and a checksum is calculated over the first 0x200 bytes only! @@ -391,14 +392,14 @@ typedef struct acl_struct { #define OFF(f) (0x1000 + (f) + 4) -void print_sid(DOM_SID *sid); +static void print_sid(DOM_SID *sid); int verbose = 1; DOM_SID old_sid, new_sid; int change = 0, new = 0; /* Compare two SIDs for equality */ -int my_sid_equal(DOM_SID *s1, DOM_SID *s2) +static int my_sid_equal(DOM_SID *s1, DOM_SID *s2) { int sa1, sa2; @@ -417,7 +418,7 @@ int my_sid_equal(DOM_SID *s1, DOM_SID *s2) * Quick and dirty to read a SID in S-1-5-21-x-y-z-rid format and * construct a DOM_SID */ -int get_sid(DOM_SID *sid, char *sid_str) +static int get_sid(DOM_SID *sid, char *sid_str) { int i = 0, auth; char *lstr; @@ -460,7 +461,7 @@ int get_sid(DOM_SID *sid, char *sid_str) * This routine does not need to deal with endianism as * long as the incoming SIDs are both in the same (LE) format. */ -void change_sid(DOM_SID *s1, DOM_SID *s2) +static void change_sid(DOM_SID *s1, DOM_SID *s2) { int i; @@ -469,7 +470,7 @@ void change_sid(DOM_SID *s1, DOM_SID *s2) } } -void print_sid(DOM_SID *sid) +static void print_sid(DOM_SID *sid) { int i, comps = sid->num_auths; fprintf(stdout, "S-%u-%u", sid->sid_rev_num, sid->id_auth[5]); @@ -482,7 +483,7 @@ void print_sid(DOM_SID *sid) fprintf(stdout, "\n"); } -void process_sid(DOM_SID *sid, DOM_SID *o_sid, DOM_SID *n_sid) +static void process_sid(DOM_SID *sid, DOM_SID *o_sid, DOM_SID *n_sid) { int i; if (my_sid_equal(sid, o_sid)) { @@ -496,7 +497,7 @@ void process_sid(DOM_SID *sid, DOM_SID *o_sid, DOM_SID *n_sid) } -void process_acl(ACL *acl, const char *prefix) +static void process_acl(ACL *acl, const char *prefix) { int ace_cnt, i; ACE *ace; @@ -514,21 +515,8 @@ void process_acl(ACL *acl, const char *prefix) } } -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; } diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 069ac56c67..9d8a657726 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -5,6 +5,7 @@ Copyright (C) Andrew Tridgell 2000 Copyright (C) Tim Potter 2000 Copyright (C) Jeremy Allison 2000 + Copyright (C) Jelmer Vernooij 2003 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 @@ -23,12 +24,9 @@ #include "includes.h" -static fstring password; -static pstring username; static pstring owner_username; static fstring server; -static int got_pass; -static int test_args; +static int test_args = False; static TALLOC_CTX *ctx; #define CREATE_ACCESS_READ READ_CONTROL_ACCESS @@ -36,7 +34,7 @@ static TALLOC_CTX *ctx; /* numeric is set when the user wants numeric SIDs and ACEs rather than going via LSA calls to resolve them */ -static int numeric; +static BOOL numeric = False; enum acl_mode {SMB_ACL_SET, SMB_ACL_DELETE, SMB_ACL_MODIFY, SMB_ACL_ADD }; enum chown_mode {REQUEST_NONE, REQUEST_CHOWN, REQUEST_CHGRP}; @@ -715,19 +713,19 @@ static struct cli_state *connect_one(const char *share) NTSTATUS nt_status; zero_ip(&ip); - if (!got_pass) { + if (!cmdline_auth_info.got_pass) { char *pass = getpass("Password: "); if (pass) { - fstrcpy(password, pass); - got_pass = True; + pstrcpy(cmdline_auth_info.password, pass); + cmdline_auth_info.got_pass = True; } } if (NT_STATUS_IS_OK(nt_status = cli_full_connection(&c, global_myname(), server, &ip, 0, share, "?????", - username, lp_workgroup(), - password, 0, NULL))) { + cmdline_auth_info.username, lp_workgroup(), + cmdline_auth_info.password, 0, NULL))) { return c; } else { DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status))); @@ -735,45 +733,34 @@ static struct cli_state *connect_one(const char *share) } } - -static void usage(void) -{ - printf( -"Usage: smbcacls //server1/share1 filename [options]\n\ -\n\ -\t-D <acls> delete an acl\n\ -\t-M <acls> modify an acl\n\ -\t-A <acls> add an acl\n\ -\t-S <acls> set acls\n\ -\t-C username change ownership of a file\n\ -\t-G username change group ownership of a file\n\ -\t-n don't resolve sids or masks to names\n\ -\t-h print help\n\ -\t-d debuglevel set debug output level\n\ -\t-U username user to autheticate as\n\ -\n\ -The username can be of the form username%%password or\n\ -workgroup\\username%%password.\n\n\ -An acl is of the form ACL:<SID>:type/flags/mask\n\ -You can string acls together with spaces, commas or newlines\n\ -"); -} - /**************************************************************************** main program ****************************************************************************/ - int main(int argc,char *argv[]) + int main(int argc, const char *argv[]) { char *share; - pstring filename; - extern char *optarg; - extern int optind; int opt; - char *p; enum acl_mode mode = SMB_ACL_SET; - char *the_acl = NULL; + static char *the_acl = NULL; enum chown_mode change_mode = REQUEST_NONE; int result; + fstring path; + pstring filename; + poptContext pc; + struct poptOption long_options[] = { + POPT_AUTOHELP + { "delete", 'D', POPT_ARG_STRING, NULL, 'D', "Delete an acl", "ACL" }, + { "modify", 'M', POPT_ARG_STRING, NULL, 'M', "Modify an acl", "ACL" }, + { "add", 'A', POPT_ARG_STRING, NULL, 'A', "Add an acl", "ACL" }, + { "set", 'S', POPT_ARG_STRING, NULL, 'S', "Set acls", "ACLS" }, + { "chown", 'C', POPT_ARG_STRING, NULL, 'C', "Change ownership of a file", "USERNAME" }, + { "chgrp", 'G', POPT_ARG_STRING, NULL, 'G', "Change group ownership of a file", "GROUPNAME" }, + { "numeric", 0, POPT_ARG_NONE, &numeric, True, "Don't resolve sids or masks to names" }, + { "test-args", 't', POPT_ARG_NONE, &test_args, True, "Test arguments"}, + POPT_COMMON_SAMBA + POPT_COMMON_CREDENTIALS + { NULL } + }; struct cli_state *cli; @@ -783,118 +770,72 @@ You can string acls together with spaces, commas or newlines\n\ dbf = x_stderr; - if (argc < 3 || argv[1][0] == '-') { - usage(); - talloc_destroy(ctx); - exit(EXIT_PARSE_ERROR); - } - setup_logging(argv[0],True); - share = argv[1]; - pstrcpy(filename, argv[2]); - all_string_sub(share,"/","\\",0); - - argc -= 2; - argv += 2; - lp_load(dyn_CONFIGFILE,True,False,False); load_interfaces(); - if (getenv("USER")) { - pstrcpy(username,getenv("USER")); - - if ((p=strchr_m(username,'%'))) { - *p = 0; - fstrcpy(password,p+1); - got_pass = True; - memset(strchr_m(getenv("USER"), '%') + 1, 'X', - strlen(password)); - } - } + pc = poptGetContext("smbcacls", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "//server1/share1 filename"); - while ((opt = getopt(argc, argv, "U:nhS:D:A:M:C:G:td:")) != EOF) { + while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { - case 'U': - pstrcpy(username,optarg); - p = strchr_m(username,'%'); - if (p) { - *p = 0; - fstrcpy(password, p+1); - got_pass = 1; - } - break; - case 'S': - the_acl = optarg; + the_acl = smb_xstrdup(poptGetOptArg(pc)); mode = SMB_ACL_SET; break; case 'D': - the_acl = optarg; + the_acl = smb_xstrdup(poptGetOptArg(pc)); mode = SMB_ACL_DELETE; break; case 'M': - the_acl = optarg; + the_acl = smb_xstrdup(poptGetOptArg(pc)); mode = SMB_ACL_MODIFY; break; case 'A': - the_acl = optarg; + the_acl = smb_xstrdup(poptGetOptArg(pc)); mode = SMB_ACL_ADD; break; case 'C': - pstrcpy(owner_username,optarg); + pstrcpy(owner_username,poptGetOptArg(pc)); change_mode = REQUEST_CHOWN; break; case 'G': - pstrcpy(owner_username,optarg); + pstrcpy(owner_username,poptGetOptArg(pc)); change_mode = REQUEST_CHGRP; break; - - case 'n': - numeric = 1; - break; - - case 't': - test_args = 1; - break; - - case 'h': - usage(); - talloc_destroy(ctx); - exit(EXIT_PARSE_ERROR); - - case 'd': - DEBUGLEVEL = atoi(optarg); - break; - - default: - printf("Unknown option %c (%d)\n", (char)opt, opt); - talloc_destroy(ctx); - exit(EXIT_PARSE_ERROR); } } - argc -= optind; - argv += optind; - - if (argc > 0) { - usage(); - talloc_destroy(ctx); - exit(EXIT_PARSE_ERROR); + /* Make connection to server */ + if(!poptPeekArg(pc)) { + poptPrintUsage(pc, stderr, 0); + return -1; } + + fstrcpy(path, poptGetArg(pc)); + + if(!poptPeekArg(pc)) { + poptPrintUsage(pc, stderr, 0); + return -1; + } + + pstrcpy(filename, poptGetArg(pc)); - /* Make connection to server */ + all_string_sub(path,"/","\\",0); - fstrcpy(server,share+2); + fstrcpy(server,path+2); share = strchr_m(server,'\\'); if (!share) { share = strchr_m(server,'/'); if (!share) { + printf("Invalid argument: %s\n", share); return -1; } } @@ -934,4 +875,3 @@ You can string acls together with spaces, commas or newlines\n\ return result; } - diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index ec58f906ed..5f3a7de1c7 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -180,15 +180,12 @@ via the %%o substitution. With encrypted passwords this is not possible.\n", lp_ return ret; } -int main(int argc, const char *argv[]) + int main(int argc, const char *argv[]) { - extern char *optarg; - extern int optind; const char *config_file = dyn_CONFIGFILE; int s; static BOOL silent_mode = False; int ret = 0; - int opt; poptContext pc; static const char *term_code = ""; static char *new_local_machine = NULL; @@ -202,15 +199,15 @@ int main(int argc, const char *argv[]) {"verbose", 'v', POPT_ARG_NONE, &show_defaults, 1, "Show default options too"}, {"server", 'L',POPT_ARG_STRING, &new_local_machine, 0, "Set %%L macro to servername\n"}, {"encoding", 't', POPT_ARG_STRING, &term_code, 0, "Print parameters with encoding"}, - {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version}, - {0,0,0,0} + POPT_COMMON_VERSION + POPT_TABLEEND }; pc = poptGetContext(NULL, argc, argv, long_options, POPT_CONTEXT_KEEP_FIRST); poptSetOtherOptionHelp(pc, "[OPTION...] <config-file> [host-name] [host-ip]"); - while((opt = poptGetNextOpt(pc)) != -1); + while(poptGetNextOpt(pc) != -1); setup_logging(poptGetArg(pc), True); diff --git a/source3/wrepld/server.c b/source3/wrepld/server.c index 31f260e94c..504818b8d5 100644 --- a/source3/wrepld/server.c +++ b/source3/wrepld/server.c @@ -160,32 +160,6 @@ void exit_server(const char *reason) } /**************************************************************************** - Usage of the program. -****************************************************************************/ - -static void usage(char *pname) -{ - - d_printf("Usage: %s [-DFSaioPh?V] [-d debuglevel] [-l log basename] [-p port]\n", pname); - d_printf(" [-O socket options] [-s services file]\n"); - d_printf("\t-D Become a daemon (default)\n"); - d_printf("\t-F Run daemon in foreground (for daemontools, etc)\n"); - d_printf("\t-S Log to stdout\n"); - d_printf("\t-a Append to log file (default)\n"); - d_printf("\t-i Run interactive (not a daemon)\n" ); - d_printf("\t-o Overwrite log file, don't append\n"); - d_printf("\t-h Print usage\n"); - d_printf("\t-? Print usage\n"); - d_printf("\t-V Print version\n"); - d_printf("\t-d debuglevel Set the debuglevel\n"); - d_printf("\t-l log basename. Basename for log/debug files\n"); - d_printf("\t-p port Listen on the specified port\n"); - d_printf("\t-O socket options Socket options\n"); - d_printf("\t-s services file. Filename of services file\n"); - d_printf("\n"); -} - -/**************************************************************************** Create an fd_set containing all the sockets in the subnet structures, plus the broadcast sockets. ***************************************************************************/ @@ -520,87 +494,45 @@ static void process(void) ****************************************************************************/ int main(int argc,char *argv[]) { - extern char *optarg; /* shall I run as a daemon */ - BOOL is_daemon = False; - BOOL interactive = False; - BOOL specified_logfile = False; - BOOL Fork = True; - BOOL log_stdout = False; + static BOOL is_daemon = False; + static BOOL interactive = False; + static BOOL Fork = True; + static BOOL log_stdout = False; + struct poptOption long_options[] = { + POPT_AUTOHELP + { "daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon (default)" }, + { "foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools, etc)" }, + { "stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, + { "interactive", 'i', POPT_ARG_NONE, NULL, 'i', "Run interactive (not a daemon)" }, + { "port", 'p', POPT_ARG_INT, &wins_port, 'p', "Listen on the specified port" }, + POPT_COMMON_SAMBA + POPT_TABLEEND + }; int opt; - pstring logfile; + poptContext pc; #ifdef HAVE_SET_AUTH_PARAMETERS set_auth_parameters(argc,argv); #endif - /* this is for people who can't start the program correctly */ - while (argc > 1 && (*argv[1] != '-')) { - argv++; - argc--; - } + pc = poptGetContext("wrepld", argc, (const char **)argv, long_options, + POPT_CONTEXT_KEEP_FIRST); - while ( EOF != (opt = getopt(argc, argv, "FSO:l:s:d:Dp:h?Vaiof:")) ) + while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { - case 'F': - Fork = False; - break; - case 'S': - log_stdout = True; - break; - case 'O': - pstrcpy(user_socket_options,optarg); - break; - - case 's': - pstrcpy(dyn_CONFIGFILE,optarg); - break; - - case 'l': - specified_logfile = True; - slprintf(logfile, sizeof(logfile)-1, "%s/log.wrepld", optarg); - lp_set_logfile(logfile); - break; - case 'i': interactive = True; Fork = False; log_stdout = True; break; + } + } - case 'D': - is_daemon = True; - break; - - case 'd': - if (*optarg == 'A') - DEBUGLEVEL = 10000; - else - DEBUGLEVEL = atoi(optarg); - break; - - case 'p': - wins_port = atoi(optarg); - break; - - case 'h': - case '?': - usage(argv[0]); - exit(0); - break; - case 'V': - d_printf("Version %s\n",VERSION); - exit(0); - break; - default: - DEBUG(0,("Incorrect program usage - are you sure the command line is correct?\n")); - usage(argv[0]); - exit(1); - } if (log_stdout && Fork) { d_printf("Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n"); - usage(argv[0]); + poptPrintUsage(pc, stderr, 0); exit(1); } @@ -613,12 +545,6 @@ static void process(void) load_case_tables(); - if(!specified_logfile) { - slprintf(logfile, sizeof(logfile)-1, "%s/log.wrepld", - dyn_LOGFILEBASE); - lp_set_logfile(logfile); - } - set_remote_machine_name("wrepld", False); setup_logging(argv[0],log_stdout); @@ -734,6 +660,7 @@ static void process(void) process(); + poptFreeContext(pc); exit_server("normal exit"); return(0); } |