summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/Makefile.in6
-rw-r--r--source3/utils/smbtree.c121
2 files changed, 26 insertions, 101 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in
index c4bdbe3b11..8fe7bff1ee 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -378,7 +378,7 @@ SMBCONTROL_OBJ = utils/smbcontrol.o $(LOCKING_OBJ) $(PARAM_OBJ) \
SMBTREE_OBJ = utils/smbtree.o $(LOCKING_OBJ) $(PARAM_OBJ) \
$(UBIQX_OBJ) $(PROFILE_OBJ) $(LIB_OBJ) $(LIBSMB_OBJ) \
- $(KRBCLIENT_OBJ)
+ $(KRBCLIENT_OBJ) $(POPT_LIB_OBJ)
TESTPARM_OBJ = utils/testparm.o \
$(PARAM_OBJ) $(UBIQX_OBJ) $(LIB_OBJ) $(POPT_LIB_OBJ)
@@ -765,9 +765,9 @@ bin/smbcontrol@EXEEXT@: $(SMBCONTROL_OBJ) bin/.dummy
@echo Linking $@
@$(CC) -DUSING_SMBCONTROL $(FLAGS) -o $@ $(SMBCONTROL_OBJ) $(LDFLAGS) $(LIBS)
-bin/smbtree@EXEEXT@: $(SMBTREE_OBJ) bin/.dummy
+bin/smbtree@EXEEXT@: $(SMBTREE_OBJ) @BUILD_POPT@ bin/.dummy
@echo Linking $@
- @$(CC) $(FLAGS) -o $@ $(SMBTREE_OBJ) $(LDFLAGS) $(LIBS)
+ @$(CC) $(FLAGS) -o $@ $(SMBTREE_OBJ) $(LDFLAGS) $(LIBS) @BUILD_POPT@
bin/smbpasswd@EXEEXT@: $(SMBPASSWD_OBJ) bin/.dummy
@echo Linking $@
diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c
index 940120d644..a55dd4dd00 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 {
@@ -267,13 +245,19 @@ 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
+ { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_credentials },
+ { 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 },
+ { "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" },
+ { 0 }
+ };
+ poptContext pc;
+
/* Initialise samba stuff */
setlinebuf(stdout);
@@ -282,86 +266,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;