diff options
author | Tim Potter <tpot@samba.org> | 2003-04-14 03:30:20 +0000 |
---|---|---|
committer | Tim Potter <tpot@samba.org> | 2003-04-14 03:30:20 +0000 |
commit | 63cbbe26923b8f6bbed11428a3a218a88d17ffe7 (patch) | |
tree | 52dd470aabad3507df6bc9f68f5b90a6c2b86c12 /source3/utils | |
parent | be67b58247680af0d672675f76e7b2af9dc94bcd (diff) | |
download | samba-63cbbe26923b8f6bbed11428a3a218a88d17ffe7.tar.gz samba-63cbbe26923b8f6bbed11428a3a218a88d17ffe7.tar.bz2 samba-63cbbe26923b8f6bbed11428a3a218a88d17ffe7.zip |
Merge Jelmer's popt updates from HEAD.
(This used to be commit 98e84b3e83d2a365c818ea64f9418edb29d690f2)
Diffstat (limited to 'source3/utils')
-rw-r--r-- | source3/utils/pdbedit.c | 9 | ||||
-rw-r--r-- | source3/utils/smbtree.c | 191 | ||||
-rw-r--r-- | source3/utils/status.c | 6 |
3 files changed, 36 insertions, 170 deletions
diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index 99d3e01fd2..bf42fb805f 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -516,7 +516,7 @@ int main (int argc, char **argv) poptContext pc; struct poptOption long_options[] = { POPT_AUTOHELP - {"list", 'l', POPT_ARG_NONE, &list_users, 0, "list all users", NULL}, + {"list", 'L', POPT_ARG_NONE, &list_users, 0, "list all users", NULL}, {"verbose", 'v', POPT_ARG_NONE, &verbose, 0, "be verbose", NULL }, {"smbpasswd-style", 'w',POPT_ARG_NONE, &spstyle, 0, "give output in smbpasswd style", NULL}, {"user", 'u', POPT_ARG_STRING, &user_name, 0, "use username", "USER" }, @@ -534,11 +534,10 @@ int main (int argc, char **argv) {"export", 'e', POPT_ARG_STRING, &backend_out, 0, "export user accounts to this backend", NULL}, {"group", 'g', POPT_ARG_NONE, &transfer_groups, 0, "use -i and -e for groups", NULL}, {"account-policy", 'P', POPT_ARG_STRING, &account_policy, 0,"value of an account policy (like maximum password age)",NULL}, - {"value", 'V', POPT_ARG_LONG, &account_policy_value, 'V',"set the account policy to this value", NULL}, + {"value", 'C', POPT_ARG_LONG, &account_policy_value, 'C',"set the account policy to this value", NULL}, {"account-control", 'c', POPT_ARG_STRING, &account_control, 0, "Values of account control", NULL}, - { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug }, - { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile }, - {0,0,0,0} + POPT_COMMON_SAMBA + POPT_TABLEEND }; setup_logging("pdbedit", True); diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 940120d644..cbe1bd448f 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -3,6 +3,7 @@ Network neighbourhood browser. Copyright (C) Tim Potter 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,34 +24,11 @@ static BOOL use_bcast; -struct user_auth_info { - pstring username; - pstring password; - pstring workgroup; -}; - /* How low can we go? */ enum tree_level {LEV_WORKGROUP, LEV_SERVER, LEV_SHARE}; static enum tree_level level = LEV_SHARE; -static void usage(void) -{ - printf( -"Usage: smbtree [options]\n\ -\n\ -\t-d debuglevel set debug output level\n\ -\t-U username user to autheticate as\n\ -\t-W workgroup workgroup of user to authenticate as\n\ -\t-D list only domains (workgroups) of tree\n\ -\t-S list domains and servers of tree\n\ -\t-b use bcast instead of using the master browser\n\ -\n\ -The username can be of the form username%%password or\n\ -workgroup\\username%%password.\n\n\ -"); -} - /* Holds a list of workgroups or servers */ struct name_list { @@ -87,62 +65,6 @@ static void add_name(const char *machine_name, uint32 server_type, DLIST_ADD(*name_list, new_name); } -/* Return a cli_state pointing at the IPC$ share for the given server */ - -static struct cli_state *get_ipc_connect(char *server, struct in_addr *server_ip, - struct user_auth_info *user_info) -{ - struct cli_state *cli; - pstring myname; - NTSTATUS nt_status; - - get_myname(myname); - - nt_status = cli_full_connection(&cli, myname, server, server_ip, 0, "IPC$", "IPC", - user_info->username, lp_workgroup(), user_info->password, - CLI_FULL_CONNECTION_ANNONYMOUS_FALLBACK, NULL); - - if (NT_STATUS_IS_OK(nt_status)) { - return cli; - } else { - return NULL; - } -} - -/* Return the IP address and workgroup of a master browser on the - network. */ - -static BOOL find_master_ip_bcast(pstring workgroup, struct in_addr *server_ip) -{ - struct in_addr *ip_list; - int i, count; - - /* Go looking for workgroups by broadcasting on the local network */ - - if (!name_resolve_bcast(MSBROWSE, 1, &ip_list, &count)) { - return False; - } - - for (i = 0; i < count; i++) { - static fstring name; - - if (!name_status_find("*", 0, 0x1d, ip_list[i], name)) - continue; - - if (!find_master_ip(name, server_ip)) - continue; - - pstrcpy(workgroup, name); - - DEBUG(4, ("found master browser %s, %s\n", - name, inet_ntoa(ip_list[i]))); - - return True; - } - - return False; -} - /**************************************************************************** display tree of smb workgroups, servers and shares ****************************************************************************/ @@ -158,19 +80,21 @@ static BOOL get_workgroups(struct user_auth_info *user_info) pstrcpy(master_workgroup, lp_workgroup()); - if (use_bcast || !find_master_ip(lp_workgroup(), &server_ip)) { - DEBUG(4, ("Unable to find master browser for workgroup %s\n", + if (!use_bcast && !find_master_ip(lp_workgroup(), &server_ip)) { + DEBUG(4, ("Unable to find master browser for workgroup %s, falling back to broadcast\n", master_workgroup)); - if (!find_master_ip_bcast(master_workgroup, &server_ip)) { + use_bcast = True; + } else if(!use_bcast) { + if (!(cli = get_ipc_connect(inet_ntoa(server_ip), &server_ip, user_info))) + return False; + } + + if (!(cli = get_ipc_connect_master_ip_bcast(master_workgroup, user_info))) { DEBUG(4, ("Unable to find master browser by " "broadcast\n")); return False; - } } - if (!(cli = get_ipc_connect(inet_ntoa(server_ip), &server_ip, user_info))) - return False; - if (!cli_NetServerEnum(cli, master_workgroup, SV_TYPE_DOMAIN_ENUM, add_name, &workgroups)) return False; @@ -267,13 +191,17 @@ static BOOL print_tree(struct user_auth_info *user_info) ****************************************************************************/ int main(int argc,char *argv[]) { - extern char *optarg; - extern int optind; - int opt; - char *p; - struct user_auth_info user_info; - BOOL got_pass = False; - + struct poptOption long_options[] = { + POPT_AUTOHELP + { "broadcast", 'b', POPT_ARG_VAL, &use_bcast, True, "Use broadcast instead of using the master browser" }, + { "domains", 'D', POPT_ARG_VAL, &level, LEV_WORKGROUP, "List only domains (workgroups) of tree" }, + { "servers", 'S', POPT_ARG_VAL, &level, LEV_SERVER, "List domains(workgroups) and servers of tree" }, + POPT_COMMON_SAMBA + POPT_COMMON_CREDENTIALS + POPT_TABLEEND + }; + poptContext pc; + /* Initialise samba stuff */ setlinebuf(stdout); @@ -282,86 +210,27 @@ static BOOL print_tree(struct user_auth_info *user_info) setup_logging(argv[0],True); + pc = poptGetContext("smbtree", argc, (const char **)argv, long_options, + POPT_CONTEXT_KEEP_FIRST); + while(poptGetNextOpt(pc) != -1); + poptFreeContext(pc); + lp_load(dyn_CONFIGFILE,True,False,False); load_interfaces(); - if (getenv("USER")) { - pstrcpy(user_info.username, getenv("USER")); - - if ((p=strchr(user_info.username, '%'))) { - *p = 0; - pstrcpy(user_info.password, p+1); - got_pass = True; - memset(strchr(getenv("USER"), '%') + 1, 'X', - strlen(user_info.password)); - } - } - - pstrcpy(user_info.workgroup, lp_workgroup()); - /* Parse command line args */ - while ((opt = getopt(argc, argv, "U:hd:W:DSb")) != EOF) { - switch (opt) { - case 'U': - pstrcpy(user_info.username,optarg); - p = strchr(user_info.username,'%'); - if (p) { - *p = 0; - pstrcpy(user_info.password, p+1); - got_pass = 1; - } - break; - - case 'b': - use_bcast = True; - break; - - case 'h': - usage(); - exit(1); - - case 'd': - DEBUGLEVEL = atoi(optarg); - break; - - case 'W': - pstrcpy(user_info.workgroup, optarg); - break; - - case 'D': - level = LEV_WORKGROUP; - break; - - case 'S': - level = LEV_SERVER; - break; - - default: - printf("Unknown option %c (%d)\n", (char)opt, opt); - exit(1); - } - } - - argc -= optind; - argv += optind; - - if (argc > 0) { - usage(); - exit(1); - } - - if (!got_pass) { + if (!cmdline_auth_info.got_pass) { char *pass = getpass("Password: "); if (pass) { - pstrcpy(user_info.password, pass); + pstrcpy(cmdline_auth_info.password, pass); } - got_pass = True; + cmdline_auth_info.got_pass = True; } /* Now do our stuff */ - if (!print_tree(&user_info)) + if (!print_tree(&cmdline_auth_info)) return 1; return 0; diff --git a/source3/utils/status.c b/source3/utils/status.c index 8014b133d9..7e87701752 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -559,10 +559,8 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo {"profile", 'P', POPT_ARG_NONE, &profile_only, 'P', "Do profiling" }, #endif /* WITH_PROFILE */ {"byterange", 'B', POPT_ARG_NONE, &show_brl, 'B', "Include byte range locks"}, - { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug }, - { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version}, - { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile }, - { 0, 0, 0, 0} + POPT_COMMON_SAMBA + POPT_TABLEEND }; setup_logging(argv[0],True); |