From 2036ce8a5d72f8e14f59d1c41b129f2787df2c66 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 6 Jul 2001 10:49:34 +0000 Subject: A program to display a tree of domains, servers and shares similar to the network neighbourhood graph. Still needs a bit of work. (This used to be commit 6b4559506d1434e6114d9707dd11fdc8ee8d54be) --- source3/utils/smbtree.c | 419 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 419 insertions(+) create mode 100644 source3/utils/smbtree.c (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c new file mode 100644 index 0000000000..26db717668 --- /dev/null +++ b/source3/utils/smbtree.c @@ -0,0 +1,419 @@ +/* + Unix SMB/Netbios implementation. + Network neighbourhood browser. + Version 3.0 + + Copyright (C) Tim Potter 2000 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +struct user_auth_info { + pstring username; + pstring password; + pstring workgroup; +}; + +/* How low can we go? */ + +enum tree_level {LEV_WORKGROUP, LEV_SERVER, LEV_SHARE}; +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\ +\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 { + struct name_list *prev, *next; + pstring name, comment; + uint32 server_type; +}; + +static struct name_list *workgroups, *servers, *shares; + +static void free_name_list(struct name_list *list) +{ + while(list) + DLIST_REMOVE(list, list); +} + +static void add_name(const char *machine_name, uint32 server_type, + const char *comment, void *state) +{ + struct name_list **name_list = (struct name_list **)state; + struct name_list *new_name; + + new_name = (struct name_list *)malloc(sizeof(struct name_list)); + + if (!new_name) + return; + + ZERO_STRUCTP(new_name); + + pstrcpy(new_name->name, machine_name); + pstrcpy(new_name->comment, comment); + new_name->server_type = server_type; + + DLIST_ADD(*name_list, new_name); +} + +/* Return a cli_state pointing at the IPC$ share for the given workgroup */ + +static struct cli_state *get_ipc_connect(char *server, + struct user_auth_info *user_info) +{ + struct nmb_name calling, called; + extern struct in_addr ipzero; + struct in_addr server_ip = ipzero; + struct cli_state *cli; + pstring myname; + + get_myname(myname); + + make_nmb_name(&called, myname, 0x0); + make_nmb_name(&calling, server, 0x20); + + if (is_ipaddress(server)) + if (!resolve_name(server, &server_ip, 0x20)) + return False; + + again: + if (!(cli = cli_initialise(NULL))) { + DEBUG(4, ("Unable to initialise cli structure\n")); + goto error; + } + + if (!cli_connect(cli, server, &server_ip)) { + DEBUG(4, ("Unable to connect to %s\n", server)); + goto error; + } + + if (!cli_session_request(cli, &calling, &called)) { + cli_shutdown(cli); + if (!strequal(called.name, "*SMBSERVER")) { + make_nmb_name(&called , "*SMBSERVER", 0x20); + goto again; + } + DEBUG(4, ("Session request failed to %s\n", called.name)); + goto error; + } + + if (!cli_negprot(cli)) { + DEBUG(4, ("Negprot failed\n")); + goto error; + } + + if (!cli_session_setup(cli, user_info->username, user_info->password, + strlen(user_info->password), + user_info->password, + strlen(user_info->password), server) && + /* try an anonymous login if it failed */ + !cli_session_setup(cli, "", "", 1,"", 0, server)) { + DEBUG(4, ("Session setup failed\n")); + goto error; + } + + DEBUG(4,(" session setup ok\n")); + + if (!cli_send_tconX(cli, "IPC$", "?????", + user_info->password, + strlen(user_info->password)+1)) { + DEBUG(4, ("Tconx failed\n")); + goto error; + } + + return cli; + + /* Clean up after error */ + + error: + if (cli && cli->initialised) + cli_shutdown(cli); + + free(cli); + 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(0x1d, ip_list[i], name)) + return False; + + if (!find_master_ip(name, server_ip)) + return False; + + 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 +****************************************************************************/ +static BOOL get_workgroups(struct user_auth_info *user_info) +{ + struct cli_state *cli; + struct in_addr server_ip; + pstring master_workgroup; + + /* Try to connect to a #1d name of our current workgroup. If that + doesn't work broadcast for a master browser and then jump off + that workgroup. */ + + pstrcpy(master_workgroup, lp_workgroup()); + + if (!find_master_ip(lp_workgroup(), &server_ip)) { + DEBUG(4, ("Unable to find master browser for workgroup %s\n", + master_workgroup)); + if (!find_master_ip_bcast(master_workgroup, &server_ip)) { + DEBUG(4, ("Unable to find master browser by " + "broadcast\n")); + return False; + } + } + + if (!(cli = get_ipc_connect(inet_ntoa(server_ip), user_info))) + return False; + + if (!cli_NetServerEnum(cli, master_workgroup, + SV_TYPE_DOMAIN_ENUM, add_name, &workgroups)) + return False; + + return True; +} + +/* Retrieve the list of servers for a given workgroup */ + +static BOOL get_servers(char *workgroup, struct user_auth_info *user_info) +{ + struct cli_state *cli; + struct in_addr server_ip; + + /* Open an IPC$ connection to the master browser for the workgroup */ + + if (!find_master_ip(workgroup, &server_ip)) { + DEBUG(4, ("Cannot find master browser for workgroup %s\n", + workgroup)); + return False; + } + + if (!(cli = get_ipc_connect(inet_ntoa(server_ip), user_info))) + return False; + + if (!cli_NetServerEnum(cli, workgroup, SV_TYPE_ALL, add_name, + &servers)) + return False; + + return True; +} + +static BOOL get_shares(char *server_name, struct user_auth_info *user_info) +{ + struct cli_state *cli; + + if (!(cli = get_ipc_connect(server_name, user_info))) + return False; + + if (!cli_RNetShareEnum(cli, add_name, &shares)) + return False; + + return True; +} + +static BOOL print_tree(struct user_auth_info *user_info) +{ + struct name_list *wg, *sv, *sh; + + /* List workgroups */ + + if (!get_workgroups(user_info)) + return False; + + for (wg = workgroups; wg; wg = wg->next) { + + printf("%s\n", wg->name); + + /* List servers */ + + free_name_list(servers); + servers = NULL; + + if (level == LEV_WORKGROUP || + !get_servers(wg->name, user_info)) + continue; + + for (sv = servers; sv; sv = sv->next) { + + printf("\t%s\n", sv->name); + + /* List shares */ + + free_name_list(shares); + shares = NULL; + + if (level == LEV_SERVER || + !get_shares(sv->name, user_info)) + continue; + + for (sh = shares; sh; sh = sh->next) { + printf("\t\t%s\n", sh->name); + } + } + } + + return True; +} + +/**************************************************************************** + main program +****************************************************************************/ + int main(int argc,char *argv[]) +{ + extern char *optarg; + extern int optind; + extern FILE *dbf; + int opt; + char *p; + pstring servicesf = CONFIGFILE; + struct user_auth_info user_info; + BOOL got_pass = False; + + /* Initialise samba stuff */ + + setlinebuf(stdout); + + dbf = stderr; + + setup_logging(argv[0],True); + + TimeInit(); + + lp_load(servicesf,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:DS")) != 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 '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) { + char *pass = getpass("Password: "); + if (pass) { + pstrcpy(user_info.password, pass); + } + got_pass = True; + } + + /* Now do our stuff */ + + if (!print_tree(&user_info)) + return 1; + + return 0; +} -- cgit From e3bbe5d5915d6947ce85c4473b2eebb2ba321fea Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 25 Jul 2001 04:09:44 +0000 Subject: nicer smbtree output (This used to be commit b840d7d65e0e8e437e016318d7ee702db2fa561b) --- source3/utils/smbtree.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 26db717668..f3d3d2ae31 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -293,7 +293,8 @@ static BOOL print_tree(struct user_auth_info *user_info) for (sv = servers; sv; sv = sv->next) { - printf("\t%s\n", sv->name); + printf("\t\\\\%-15s\t\t%s\n", + sv->name, sv->comment); /* List shares */ @@ -305,7 +306,8 @@ static BOOL print_tree(struct user_auth_info *user_info) continue; for (sh = shares; sh; sh = sh->next) { - printf("\t\t%s\n", sh->name); + printf("\t\t\\\\%s\\%-15s\t%s\n", + sv->name, sh->name, sh->comment); } } } -- cgit From 5eccc9061bcaa1e225dea189ec99e9f53df66bca Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 20 Aug 2001 17:38:37 +0000 Subject: added -b option (This used to be commit 1c2618df450ddde7e52ab8784fcdd2b64a85771e) --- source3/utils/smbtree.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index f3d3d2ae31..0f824f7ecf 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -22,6 +22,8 @@ #include "includes.h" +static BOOL use_bcast; + struct user_auth_info { pstring username; pstring password; @@ -43,6 +45,7 @@ static void usage(void) \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\ @@ -211,7 +214,7 @@ static BOOL get_workgroups(struct user_auth_info *user_info) pstrcpy(master_workgroup, lp_workgroup()); - if (!find_master_ip(lp_workgroup(), &server_ip)) { + if (use_bcast || !find_master_ip(lp_workgroup(), &server_ip)) { DEBUG(4, ("Unable to find master browser for workgroup %s\n", master_workgroup)); if (!find_master_ip_bcast(master_workgroup, &server_ip)) { @@ -358,7 +361,7 @@ static BOOL print_tree(struct user_auth_info *user_info) /* Parse command line args */ - while ((opt = getopt(argc, argv, "U:hd:W:DS")) != EOF) { + while ((opt = getopt(argc, argv, "U:hd:W:DSb")) != EOF) { switch (opt) { case 'U': pstrcpy(user_info.username,optarg); @@ -370,6 +373,10 @@ static BOOL print_tree(struct user_auth_info *user_info) } break; + case 'b': + use_bcast = True; + break; + case 'h': usage(); exit(1); -- cgit From 7844aa868b02f99c013f336ee03ef05adbd11a7b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 5 Sep 2001 08:11:17 +0000 Subject: more warning fixes on solaris (This used to be commit c04c67fec85b1c81ef0b3cebacde304a1de0d854) --- source3/utils/smbtree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 0f824f7ecf..41940d9a6c 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -183,10 +183,10 @@ static BOOL find_master_ip_bcast(pstring workgroup, struct in_addr *server_ip) static fstring name; if (!name_status_find(0x1d, ip_list[i], name)) - return False; + continue; if (!find_master_ip(name, server_ip)) - return False; + continue; pstrcpy(workgroup, name); -- cgit From b30e75692d68233448b3ad3d7ddd4b4ac423d3ab Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Sep 2001 11:08:57 +0000 Subject: replaced stdio in many parts of samba with a XFILE. XFILE is a cut-down replacemnt of stdio that doesn't suffer from the 8-bit filedescriptor limit that we hit with nasty consequences on some systems I would eventually prefer us to have a configure test to see if we need to replace stdio, but for now this code needs to be tested widely so I'm enabling it by default. (This used to be commit 1af8bf34f1caa3e7ec312d8109c07d32a945a448) --- source3/utils/smbtree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 41940d9a6c..75390965b3 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -325,7 +325,7 @@ static BOOL print_tree(struct user_auth_info *user_info) { extern char *optarg; extern int optind; - extern FILE *dbf; + extern XFILE *dbf; int opt; char *p; pstring servicesf = CONFIGFILE; @@ -336,7 +336,7 @@ static BOOL print_tree(struct user_auth_info *user_info) setlinebuf(stdout); - dbf = stderr; + dbf = x_stderr; setup_logging(argv[0],True); -- cgit From b12a4dd9b655485420d5c67dd143d8f49ac28a40 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Sep 2001 12:14:18 +0000 Subject: declare dbf in one spot (This used to be commit f41c3bb80f1e498a9d27f6e236b0ff3a742764c9) --- source3/utils/smbtree.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 75390965b3..191a9124f7 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -325,7 +325,6 @@ static BOOL print_tree(struct user_auth_info *user_info) { extern char *optarg; extern int optind; - extern XFILE *dbf; int opt; char *p; pstring servicesf = CONFIGFILE; -- cgit From c0ef0e113e8d3117891b4b137f660ca3c4c6b1f0 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 17 Sep 2001 11:48:29 +0000 Subject: move to SAFE_FREE() (This used to be commit 67db8f03c5c9e81e11b5f3276b50ee23e09a2659) --- source3/utils/smbtree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 191a9124f7..d7842d1e02 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -161,7 +161,7 @@ static struct cli_state *get_ipc_connect(char *server, if (cli && cli->initialised) cli_shutdown(cli); - free(cli); + SAFE_FREE(cli); return NULL; } -- cgit From f741f656737f4ec46cd318e986b6bf412ed309d2 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 19 Nov 2001 02:49:53 +0000 Subject: Store some path names in global variables initialized to configure default, rather than in preprocessor macros. (This used to be commit 79ec88f0da40faebe1e587f1b3e87b5f2b184f58) --- source3/utils/smbtree.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index d7842d1e02..857b858bec 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -327,7 +327,6 @@ static BOOL print_tree(struct user_auth_info *user_info) extern int optind; int opt; char *p; - pstring servicesf = CONFIGFILE; struct user_auth_info user_info; BOOL got_pass = False; @@ -341,7 +340,7 @@ static BOOL print_tree(struct user_auth_info *user_info) TimeInit(); - lp_load(servicesf,True,False,False); + lp_load(dyn_CONFIGFILE,True,False,False); load_interfaces(); if (getenv("USER")) { -- cgit From f146325e7df80b26616225017ef6a60ff5f2e349 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 21 Nov 2001 23:00:59 +0000 Subject: W2K doesn't seem to respond to *#0 names in node status. Ensure name lookup uses password server parameter when looking for PDCs. Jeremy. (This used to be commit 54c968913d6553c6d834b068234ab176917075eb) --- source3/utils/smbtree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 857b858bec..9ce8120bba 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -182,7 +182,7 @@ static BOOL find_master_ip_bcast(pstring workgroup, struct in_addr *server_ip) for (i = 0; i < count; i++) { static fstring name; - if (!name_status_find(0x1d, ip_list[i], name)) + if (!name_status_find("*", 0, 0x1d, ip_list[i], name)) continue; if (!find_master_ip(name, server_ip)) -- cgit From 79b34d1b11e685d068b9c0ac9a0ec06eaa263d82 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 23 Nov 2001 00:52:29 +0000 Subject: Removed TimeInit() call from every client program (except for one place in smbd/process.c where the timezone is reinitialised. Was replaced with check for a static is_initialised boolean. (This used to be commit 8fc772c9e5770cd3a8857670214dcff033ebae32) --- source3/utils/smbtree.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 9ce8120bba..13df0451f0 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -338,8 +338,6 @@ static BOOL print_tree(struct user_auth_info *user_info) setup_logging(argv[0],True); - TimeInit(); - lp_load(dyn_CONFIGFILE,True,False,False); load_interfaces(); -- cgit From 585d0efbc6428e5876d354fee49c241c1bad809d Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 26 Nov 2001 03:11:44 +0000 Subject: Got medieval on another pointless extern. Removed extern struct ipzero and replaced with two functions: void zero_ip(struct in_adder *ip); BOOL is_zero_ip(struct in_addr ip); (This used to be commit 778f5f77a66cda76348a7c6f64cd63afe2bfe077) --- source3/utils/smbtree.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 13df0451f0..5b7e8a73c1 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -94,11 +94,12 @@ static struct cli_state *get_ipc_connect(char *server, struct user_auth_info *user_info) { struct nmb_name calling, called; - extern struct in_addr ipzero; - struct in_addr server_ip = ipzero; + struct in_addr server_ip; struct cli_state *cli; pstring myname; + zero_ip(&server_ip); + get_myname(myname); make_nmb_name(&called, myname, 0x0); -- cgit From eec9e8a052407611df223fec982588e7a2bd7f49 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 28 Nov 2001 03:56:30 +0000 Subject: fix a bunch of places where we can double-free a cli structure (This used to be commit e2ba2383c9f679c076749a8f4fccefc3559e37ec) --- source3/utils/smbtree.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 5b7e8a73c1..b06920418d 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -162,7 +162,6 @@ static struct cli_state *get_ipc_connect(char *server, if (cli && cli->initialised) cli_shutdown(cli); - SAFE_FREE(cli); return NULL; } -- cgit From cd68afe31256ad60748b34f7318a180cfc2127cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 30 Jan 2002 06:08:46 +0000 Subject: Removed version number from file header. Changed "SMB/Netbios" to "SMB/CIFS" in file header. (This used to be commit 6a58c9bd06d0d7502a24bf5ce5a2faf0a146edfa) --- source3/utils/smbtree.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index b06920418d..b80a27eb37 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -1,7 +1,6 @@ /* - Unix SMB/Netbios implementation. + Unix SMB/CIFS implementation. Network neighbourhood browser. - Version 3.0 Copyright (C) Tim Potter 2000 -- cgit From e90b65284812aaa5ff9e9935ce9bbad7791cbbcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- source3/utils/smbtree.c | 85 +++++++++---------------------------------------- 1 file changed, 15 insertions(+), 70 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index b80a27eb37..bcb460ee0b 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -87,81 +87,26 @@ 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 workgroup */ +/* Return a cli_state pointing at the IPC$ share for the given server */ -static struct cli_state *get_ipc_connect(char *server, +static struct cli_state *get_ipc_connect(char *server, struct in_addr *server_ip, struct user_auth_info *user_info) { - struct nmb_name calling, called; - struct in_addr server_ip; struct cli_state *cli; pstring myname; - - zero_ip(&server_ip); + NTSTATUS nt_status; get_myname(myname); - - make_nmb_name(&called, myname, 0x0); - make_nmb_name(&calling, server, 0x20); - - if (is_ipaddress(server)) - if (!resolve_name(server, &server_ip, 0x20)) - return False; - - again: - if (!(cli = cli_initialise(NULL))) { - DEBUG(4, ("Unable to initialise cli structure\n")); - goto error; - } - - if (!cli_connect(cli, server, &server_ip)) { - DEBUG(4, ("Unable to connect to %s\n", server)); - goto error; - } - - if (!cli_session_request(cli, &calling, &called)) { - cli_shutdown(cli); - if (!strequal(called.name, "*SMBSERVER")) { - make_nmb_name(&called , "*SMBSERVER", 0x20); - goto again; - } - DEBUG(4, ("Session request failed to %s\n", called.name)); - goto error; - } - - if (!cli_negprot(cli)) { - DEBUG(4, ("Negprot failed\n")); - goto error; - } - - if (!cli_session_setup(cli, user_info->username, user_info->password, - strlen(user_info->password), - user_info->password, - strlen(user_info->password), server) && - /* try an anonymous login if it failed */ - !cli_session_setup(cli, "", "", 1,"", 0, server)) { - DEBUG(4, ("Session setup failed\n")); - goto error; - } - - DEBUG(4,(" session setup ok\n")); - - if (!cli_send_tconX(cli, "IPC$", "?????", - user_info->password, - strlen(user_info->password)+1)) { - DEBUG(4, ("Tconx failed\n")); - goto error; + + 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); + + if (NT_STATUS_IS_OK(nt_status)) { + return cli; + } else { + return NULL; } - - return cli; - - /* Clean up after error */ - - error: - if (cli && cli->initialised) - cli_shutdown(cli); - - return NULL; } /* Return the IP address and workgroup of a master browser on the @@ -223,7 +168,7 @@ static BOOL get_workgroups(struct user_auth_info *user_info) } } - if (!(cli = get_ipc_connect(inet_ntoa(server_ip), user_info))) + if (!(cli = get_ipc_connect(inet_ntoa(server_ip), &server_ip, user_info))) return False; if (!cli_NetServerEnum(cli, master_workgroup, @@ -248,7 +193,7 @@ static BOOL get_servers(char *workgroup, struct user_auth_info *user_info) return False; } - if (!(cli = get_ipc_connect(inet_ntoa(server_ip), user_info))) + if (!(cli = get_ipc_connect(inet_ntoa(server_ip), &server_ip, user_info))) return False; if (!cli_NetServerEnum(cli, workgroup, SV_TYPE_ALL, add_name, @@ -262,7 +207,7 @@ static BOOL get_shares(char *server_name, struct user_auth_info *user_info) { struct cli_state *cli; - if (!(cli = get_ipc_connect(server_name, user_info))) + if (!(cli = get_ipc_connect(server_name, NULL, user_info))) return False; if (!cli_RNetShareEnum(cli, add_name, &shares)) -- cgit From f0255b38bc17f4da9a63b2be4c3ce505688e933e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 17 Aug 2002 14:45:04 +0000 Subject: sync 3.0 branch with HEAD (This used to be commit 1b83b78e332b9d28914eff155530e81cf2073a58) --- source3/utils/smbtree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index bcb460ee0b..b733f8112f 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -32,7 +32,7 @@ struct user_auth_info { /* How low can we go? */ enum tree_level {LEV_WORKGROUP, LEV_SERVER, LEV_SHARE}; -enum tree_level level = LEV_SHARE; +static enum tree_level level = LEV_SHARE; static void usage(void) { -- cgit From c53eb2ed540e79d6deae5f41e17febc5bf5dbf57 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 17 Oct 2002 17:10:24 +0000 Subject: Added new error codes. Fix up connection code to retry in the same way that app-head does. Jeremy. (This used to be commit ec7953f20145799f6286a295472df4826bfdfb8f) --- source3/utils/smbtree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index b733f8112f..940120d644 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -100,7 +100,7 @@ static struct cli_state *get_ipc_connect(char *server, struct in_addr *server_ip 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); + CLI_FULL_CONNECTION_ANNONYMOUS_FALLBACK, NULL); if (NT_STATUS_IS_OK(nt_status)) { return cli; -- cgit From 63cbbe26923b8f6bbed11428a3a218a88d17ffe7 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 14 Apr 2003 03:30:20 +0000 Subject: Merge Jelmer's popt updates from HEAD. (This used to be commit 98e84b3e83d2a365c818ea64f9418edb29d690f2) --- source3/utils/smbtree.c | 191 ++++++++---------------------------------------- 1 file changed, 30 insertions(+), 161 deletions(-) (limited to 'source3/utils/smbtree.c') 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; -- cgit From c507ebe56741d773bf6e7ad547863a2da1aee687 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 10 May 2003 10:53:48 +0000 Subject: Patch from metze and me that adds dummy smb_register_*() functions so that is now possible to, for example, load a module which contains an auth method into a binary without the auth/ subsystem built in. (This used to be commit 74d9ecfe2dd7364643d32acb62ade957bd71cd0d) --- source3/utils/smbtree.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index cbe1bd448f..bc669b4aa1 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -22,6 +22,8 @@ #include "includes.h" +#include "module_dummy.h" + static BOOL use_bcast; /* How low can we go? */ -- cgit From 0914e541f5480834c1b0ddc98b5f71f7f7abf9cb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 10 May 2003 11:49:51 +0000 Subject: Reverse previous patch from Stefan and me after comments by Andrew Bartlett (This used to be commit d817eaf0ecca2d878ab1ffcf7a747a02d71c811e) --- source3/utils/smbtree.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index bc669b4aa1..cbe1bd448f 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -22,8 +22,6 @@ #include "includes.h" -#include "module_dummy.h" - static BOOL use_bcast; /* How low can we go? */ -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/utils/smbtree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index cbe1bd448f..00f6a74f2f 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -51,7 +51,7 @@ static void add_name(const char *machine_name, uint32 server_type, struct name_list **name_list = (struct name_list **)state; struct name_list *new_name; - new_name = (struct name_list *)malloc(sizeof(struct name_list)); + new_name = SMB_MALLOC_P(struct name_list); if (!new_name) return; -- cgit From c8f28c92a7a96e278031b85f04b4671206bf3502 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 28 Dec 2005 22:48:54 +0000 Subject: r12555: Fix more load_case_table swegfaults. Arggg. What I'd give for a global constructor... Jeremy. (This used to be commit c970d7d0a5ba225465dfb0980989b8817b17c643) --- source3/utils/smbtree.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 00f6a74f2f..3755b7f8e5 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -203,6 +203,7 @@ static BOOL print_tree(struct user_auth_info *user_info) poptContext pc; /* Initialise samba stuff */ + load_case_tables(); setlinebuf(stdout); -- cgit From 9c15bd311db76885b27f30ba92d885833f668550 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sat, 28 Jan 2006 22:53:04 +0000 Subject: r13212: r12414@cabra: derrell | 2006-01-28 17:52:17 -0500 lp_load() could not be called multiple times to modify parameter settings based on reading from multiple configuration settings. Each time, it initialized all of the settings back to their defaults before reading the specified configuration file. This patch adds a parameter to lp_load() specifying whether the settings should be initialized. It does, however, still force the settings to be initialized the first time, even if the request was to not initialize them. (Not doing so could wreak havoc due to uninitialized values.) (This used to be commit f2a24de769d1b2266e576597c57a8e3b1e2a2b51) --- source3/utils/smbtree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 3755b7f8e5..853a46f379 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -216,7 +216,7 @@ static BOOL print_tree(struct user_auth_info *user_info) while(poptGetNextOpt(pc) != -1); poptFreeContext(pc); - lp_load(dyn_CONFIGFILE,True,False,False); + lp_load(dyn_CONFIGFILE,True,False,False,True); load_interfaces(); /* Parse command line args */ -- cgit From 62f61caff4cb36070a0987bfccc679ade091f73b Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Tue, 16 May 2006 01:21:16 +0000 Subject: r15630: adapt smbclient fix to smbtree to enable long share names (This used to be commit ae56154fc7694042496a55d4dade8ef1a7ba361c) --- source3/utils/smbtree.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 853a46f379..d9cd446f6c 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -127,6 +127,60 @@ static BOOL get_servers(char *workgroup, struct user_auth_info *user_info) return True; } +static BOOL get_rpc_shares(struct cli_state *cli, + void (*fn)(const char *, uint32, const char *, void *), + void *state) +{ + NTSTATUS status; + struct rpc_pipe_client *pipe_hnd; + TALLOC_CTX *mem_ctx; + ENUM_HND enum_hnd; + WERROR werr; + SRV_SHARE_INFO_CTR ctr; + int i; + + mem_ctx = talloc_new(NULL); + if (mem_ctx == NULL) { + DEBUG(0, ("talloc_new failed\n")); + return False; + } + + init_enum_hnd(&enum_hnd, 0); + + pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, &status); + + if (pipe_hnd == NULL) { + DEBUG(10, ("Could not connect to srvsvc pipe: %s\n", + nt_errstr(status))); + TALLOC_FREE(mem_ctx); + return False; + } + + werr = rpccli_srvsvc_net_share_enum(pipe_hnd, mem_ctx, 1, &ctr, + 0xffffffff, &enum_hnd); + + if (!W_ERROR_IS_OK(werr)) { + TALLOC_FREE(mem_ctx); + cli_rpc_pipe_close(pipe_hnd); + return False; + } + + for (i=0; iinfo_1_str.uni_netname); + comment = rpcstr_pull_unistr2_talloc( + mem_ctx, &info->info_1_str.uni_remark); + fn(name, info->info_1.type, comment, state); + } + + TALLOC_FREE(mem_ctx); + cli_rpc_pipe_close(pipe_hnd); + return True; +} + + static BOOL get_shares(char *server_name, struct user_auth_info *user_info) { struct cli_state *cli; @@ -134,6 +188,9 @@ static BOOL get_shares(char *server_name, struct user_auth_info *user_info) if (!(cli = get_ipc_connect(server_name, NULL, user_info))) return False; + if (get_rpc_shares(cli, add_name, &shares)) + return True; + if (!cli_RNetShareEnum(cli, add_name, &shares)) return False; -- cgit From 7ba2554d88a187ca1f4f40014363fdf9de2223a0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 21 Sep 2006 23:57:32 +0000 Subject: r18802: Use the pidl-generated code for the srvsvc interface, both client and server code. This has had some basic testing. I'll do more during the next couple of days and hopefully also make RPC-SRVSVC from Samba4 pass against it. (This used to be commit ef10672399c4b82700dc431b4d93431ffdd42d98) --- source3/utils/smbtree.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index d9cd446f6c..1feb5b7e1d 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -134,10 +134,12 @@ static BOOL get_rpc_shares(struct cli_state *cli, NTSTATUS status; struct rpc_pipe_client *pipe_hnd; TALLOC_CTX *mem_ctx; - ENUM_HND enum_hnd; + uint32 enum_hnd; WERROR werr; - SRV_SHARE_INFO_CTR ctr; + union srvsvc_NetShareCtr ctr; + uint32 numentries; int i; + uint32 info_level = 1; mem_ctx = talloc_new(NULL); if (mem_ctx == NULL) { @@ -145,8 +147,7 @@ static BOOL get_rpc_shares(struct cli_state *cli, return False; } - init_enum_hnd(&enum_hnd, 0); - + enum_hnd = 0; pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, &status); if (pipe_hnd == NULL) { @@ -156,8 +157,8 @@ static BOOL get_rpc_shares(struct cli_state *cli, return False; } - werr = rpccli_srvsvc_net_share_enum(pipe_hnd, mem_ctx, 1, &ctr, - 0xffffffff, &enum_hnd); + werr = rpccli_srvsvc_NetShareEnum(pipe_hnd, mem_ctx, NULL, &info_level, &ctr, + 0xffffffff, &numentries, &enum_hnd); if (!W_ERROR_IS_OK(werr)) { TALLOC_FREE(mem_ctx); @@ -165,14 +166,9 @@ static BOOL get_rpc_shares(struct cli_state *cli, return False; } - for (i=0; iinfo_1_str.uni_netname); - comment = rpcstr_pull_unistr2_talloc( - mem_ctx, &info->info_1_str.uni_remark); - fn(name, info->info_1.type, comment, state); + for (i=0; iarray[i].name, ctr.ctr1->array[i].type, + ctr.ctr1->array[i].comment, state); } TALLOC_FREE(mem_ctx); -- cgit From e1fa2ea7216909501c41bcc0499daea1c57ae06e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 24 Sep 2006 22:11:36 +0000 Subject: r18877: More WERROR/NTSTATUS bugs (This used to be commit 88a928a2332b96124935c547cf5ee16163865d84) --- source3/utils/smbtree.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 1feb5b7e1d..b2a4e240ff 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -135,7 +135,6 @@ static BOOL get_rpc_shares(struct cli_state *cli, struct rpc_pipe_client *pipe_hnd; TALLOC_CTX *mem_ctx; uint32 enum_hnd; - WERROR werr; union srvsvc_NetShareCtr ctr; uint32 numentries; int i; @@ -157,10 +156,12 @@ static BOOL get_rpc_shares(struct cli_state *cli, return False; } - werr = rpccli_srvsvc_NetShareEnum(pipe_hnd, mem_ctx, NULL, &info_level, &ctr, - 0xffffffff, &numentries, &enum_hnd); + status = rpccli_srvsvc_NetShareEnum(pipe_hnd, mem_ctx, NULL, + &info_level, &ctr, + 0xffffffff, &numentries, + &enum_hnd); - if (!W_ERROR_IS_OK(werr)) { + if (!NT_STATUS_IS_OK(status)) { TALLOC_FREE(mem_ctx); cli_rpc_pipe_close(pipe_hnd); return False; -- cgit From 1c16e0d642a17a247434eee0ca7c57d6383ff797 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 22 Oct 2006 10:01:55 +0000 Subject: r19450: Fix smbtree's use of netshareenum. Jelmer, how much of r18802 did you actually test?? Volker (This used to be commit d0025861c09b3a19ecd291265f10eaec5f380932) --- source3/utils/smbtree.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index b2a4e240ff..31ed763565 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -135,6 +135,7 @@ static BOOL get_rpc_shares(struct cli_state *cli, struct rpc_pipe_client *pipe_hnd; TALLOC_CTX *mem_ctx; uint32 enum_hnd; + struct srvsvc_NetShareCtr1 ctr1; union srvsvc_NetShareCtr ctr; uint32 numentries; int i; @@ -156,6 +157,10 @@ static BOOL get_rpc_shares(struct cli_state *cli, return False; } + ZERO_STRUCT(ctr1); + level = 1; + ctr.ctr1 = &ctr1; + status = rpccli_srvsvc_NetShareEnum(pipe_hnd, mem_ctx, NULL, &info_level, &ctr, 0xffffffff, &numentries, -- cgit From 01367cdfd03d2412904c57807e1ff3c62696d05f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 19 Nov 2006 18:57:52 +0000 Subject: r19797: Convert the remaining pipes to the "new" unique out ptr handling (This used to be commit bc4e0a388a2859d2ddcfb8f07920f3b121a37894) --- source3/utils/smbtree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 31ed763565..e993e5dc41 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -135,6 +135,7 @@ static BOOL get_rpc_shares(struct cli_state *cli, struct rpc_pipe_client *pipe_hnd; TALLOC_CTX *mem_ctx; uint32 enum_hnd; + uint32 *penum_hnd = &enum_hnd; struct srvsvc_NetShareCtr1 ctr1; union srvsvc_NetShareCtr ctr; uint32 numentries; @@ -164,7 +165,7 @@ static BOOL get_rpc_shares(struct cli_state *cli, status = rpccli_srvsvc_NetShareEnum(pipe_hnd, mem_ctx, NULL, &info_level, &ctr, 0xffffffff, &numentries, - &enum_hnd); + &penum_hnd); if (!NT_STATUS_IS_OK(status)) { TALLOC_FREE(mem_ctx); -- cgit From 62e11c4f1748d98f479110c8c0e656a8f65dca4d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 16 Jan 2007 15:42:03 +0000 Subject: r20832: Remove extra pointers previously added to unique [out] pointers. Instead, add [ref] pointers where necessary (top-level [ref] pointers, by spec, don't appear on the wire). This brings us closer to the DCE/RPC standard again. (This used to be commit 580f2a7197b1bc9db14a643fdd112b40ef37aaef) --- source3/utils/smbtree.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index e993e5dc41..31ed763565 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -135,7 +135,6 @@ static BOOL get_rpc_shares(struct cli_state *cli, struct rpc_pipe_client *pipe_hnd; TALLOC_CTX *mem_ctx; uint32 enum_hnd; - uint32 *penum_hnd = &enum_hnd; struct srvsvc_NetShareCtr1 ctr1; union srvsvc_NetShareCtr ctr; uint32 numentries; @@ -165,7 +164,7 @@ static BOOL get_rpc_shares(struct cli_state *cli, status = rpccli_srvsvc_NetShareEnum(pipe_hnd, mem_ctx, NULL, &info_level, &ctr, 0xffffffff, &numentries, - &penum_hnd); + &enum_hnd); if (!NT_STATUS_IS_OK(status)) { TALLOC_FREE(mem_ctx); -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/utils/smbtree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 31ed763565..5deb29a149 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -7,7 +7,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/utils/smbtree.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 5deb29a149..b30ce08c5a 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From faefb22c61568c678476b4dad36bdc5ce3afb499 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 4 Sep 2007 05:39:06 +0000 Subject: r24943: Some stackframes (This used to be commit cddb9f11d5fafcd3797cb242775c37f0c04d4f15) --- source3/utils/smbtree.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index b30ce08c5a..a29aa52fef 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -249,6 +249,7 @@ static BOOL print_tree(struct user_auth_info *user_info) ****************************************************************************/ int main(int argc,char *argv[]) { + TALLOC_CTX *frame = talloc_stackframe(); struct poptOption long_options[] = { POPT_AUTOHELP { "broadcast", 'b', POPT_ARG_VAL, &use_bcast, True, "Use broadcast instead of using the master browser" }, @@ -289,8 +290,11 @@ static BOOL print_tree(struct user_auth_info *user_info) /* Now do our stuff */ - if (!print_tree(&cmdline_auth_info)) + if (!print_tree(&cmdline_auth_info)) { + TALLOC_FREE(frame); return 1; + } + TALLOC_FREE(frame); return 0; } -- cgit From 754cfb427ba74c72c81f6501c76b5930ea9ab67f Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 28 Sep 2007 04:08:58 +0000 Subject: r25402: BUG 4997 (3.2 only): Fix enumration level for smbtree (This used to be commit f387e0f256e3f8a8c4a67f7fcc847a9dabaff8da) --- source3/utils/smbtree.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index a29aa52fef..5d5a9743d5 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -157,7 +157,6 @@ static BOOL get_rpc_shares(struct cli_state *cli, } ZERO_STRUCT(ctr1); - level = 1; ctr.ctr1 = &ctr1; status = rpccli_srvsvc_NetShareEnum(pipe_hnd, mem_ctx, NULL, -- cgit From e5a951325a6cac8567af3a66de6d2df577508ae4 Mon Sep 17 00:00:00 2001 From: "Gerald (Jerry) Carter" Date: Wed, 10 Oct 2007 15:34:30 -0500 Subject: [GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch. (This used to be commit 5c6c8e1fe93f340005110a7833946191659d88ab) --- source3/utils/smbtree.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 5d5a9743d5..7d62d65b05 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -133,12 +133,10 @@ static BOOL get_rpc_shares(struct cli_state *cli, NTSTATUS status; struct rpc_pipe_client *pipe_hnd; TALLOC_CTX *mem_ctx; - uint32 enum_hnd; - struct srvsvc_NetShareCtr1 ctr1; - union srvsvc_NetShareCtr ctr; - uint32 numentries; + ENUM_HND enum_hnd; + WERROR werr; + SRV_SHARE_INFO_CTR ctr; int i; - uint32 info_level = 1; mem_ctx = talloc_new(NULL); if (mem_ctx == NULL) { @@ -146,7 +144,8 @@ static BOOL get_rpc_shares(struct cli_state *cli, return False; } - enum_hnd = 0; + init_enum_hnd(&enum_hnd, 0); + pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, &status); if (pipe_hnd == NULL) { @@ -156,23 +155,23 @@ static BOOL get_rpc_shares(struct cli_state *cli, return False; } - ZERO_STRUCT(ctr1); - ctr.ctr1 = &ctr1; - - status = rpccli_srvsvc_NetShareEnum(pipe_hnd, mem_ctx, NULL, - &info_level, &ctr, - 0xffffffff, &numentries, - &enum_hnd); + werr = rpccli_srvsvc_net_share_enum(pipe_hnd, mem_ctx, 1, &ctr, + 0xffffffff, &enum_hnd); - if (!NT_STATUS_IS_OK(status)) { + if (!W_ERROR_IS_OK(werr)) { TALLOC_FREE(mem_ctx); cli_rpc_pipe_close(pipe_hnd); return False; } - for (i=0; iarray[i].name, ctr.ctr1->array[i].type, - ctr.ctr1->array[i].comment, state); + for (i=0; iinfo_1_str.uni_netname); + comment = rpcstr_pull_unistr2_talloc( + mem_ctx, &info->info_1_str.uni_remark); + fn(name, info->info_1.type, comment, state); } TALLOC_FREE(mem_ctx); -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/utils/smbtree.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 7d62d65b05..d3c95c024c 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -21,7 +21,7 @@ #include "includes.h" -static BOOL use_bcast; +static bool use_bcast; /* How low can we go? */ @@ -67,7 +67,7 @@ static void add_name(const char *machine_name, uint32 server_type, /**************************************************************************** display tree of smb workgroups, servers and shares ****************************************************************************/ -static BOOL get_workgroups(struct user_auth_info *user_info) +static bool get_workgroups(struct user_auth_info *user_info) { struct cli_state *cli; struct in_addr server_ip; @@ -103,7 +103,7 @@ static BOOL get_workgroups(struct user_auth_info *user_info) /* Retrieve the list of servers for a given workgroup */ -static BOOL get_servers(char *workgroup, struct user_auth_info *user_info) +static bool get_servers(char *workgroup, struct user_auth_info *user_info) { struct cli_state *cli; struct in_addr server_ip; @@ -126,7 +126,7 @@ static BOOL get_servers(char *workgroup, struct user_auth_info *user_info) return True; } -static BOOL get_rpc_shares(struct cli_state *cli, +static bool get_rpc_shares(struct cli_state *cli, void (*fn)(const char *, uint32, const char *, void *), void *state) { @@ -180,7 +180,7 @@ static BOOL get_rpc_shares(struct cli_state *cli, } -static BOOL get_shares(char *server_name, struct user_auth_info *user_info) +static bool get_shares(char *server_name, struct user_auth_info *user_info) { struct cli_state *cli; @@ -196,7 +196,7 @@ static BOOL get_shares(char *server_name, struct user_auth_info *user_info) return True; } -static BOOL print_tree(struct user_auth_info *user_info) +static bool print_tree(struct user_auth_info *user_info) { struct name_list *wg, *sv, *sh; -- cgit From 9a85533914119fb995fb61555c9f6e0018d4d181 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 19 Oct 2007 11:38:36 -0700 Subject: Fix the popt / bool issues. Some places we used BOOL where we meant int. Fix this. Thanks to metze for pointing this out. Jeremy. (This used to be commit 793a9d24a163cb6cf5a3a0aa5ae30e9f8cf4744a) --- source3/utils/smbtree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index d3c95c024c..0974039382 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -21,7 +21,7 @@ #include "includes.h" -static bool use_bcast; +static int use_bcast; /* How low can we go? */ -- cgit From 42f96941399102738494f2b28802777301c94826 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 25 Oct 2007 18:11:29 -0700 Subject: Fixed missing in_addr -> sockaddr_storage conversion (how did I miss this...). Jeremy. (This used to be commit f982774c8d95c48355bbd821c8224fadb8bb303e) --- source3/utils/smbtree.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 0974039382..0e0c993f4e 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -70,7 +70,7 @@ static void add_name(const char *machine_name, uint32 server_type, static bool get_workgroups(struct user_auth_info *user_info) { struct cli_state *cli; - struct in_addr server_ip; + struct sockaddr_storage server_ss; pstring master_workgroup; /* Try to connect to a #1d name of our current workgroup. If that @@ -79,22 +79,24 @@ 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)) { + if (!use_bcast && !find_master_ip(lp_workgroup(), &server_ss)) { DEBUG(4, ("Unable to find master browser for workgroup %s, falling back to broadcast\n", master_workgroup)); use_bcast = True; } else if(!use_bcast) { - if (!(cli = get_ipc_connect(inet_ntoa(server_ip), &server_ip, user_info))) + char addr[INET6_ADDRSTRLEN]; + print_sockaddr(addr, sizeof(addr), &server_ss); + if (!(cli = get_ipc_connect(addr, &server_ss, 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_NetServerEnum(cli, master_workgroup, + if (!cli_NetServerEnum(cli, master_workgroup, SV_TYPE_DOMAIN_ENUM, add_name, &workgroups)) return False; @@ -106,27 +108,29 @@ static bool get_workgroups(struct user_auth_info *user_info) static bool get_servers(char *workgroup, struct user_auth_info *user_info) { struct cli_state *cli; - struct in_addr server_ip; + struct sockaddr_storage server_ss; + char addr[INET6_ADDRSTRLEN]; /* Open an IPC$ connection to the master browser for the workgroup */ - if (!find_master_ip(workgroup, &server_ip)) { + if (!find_master_ip(workgroup, &server_ss)) { DEBUG(4, ("Cannot find master browser for workgroup %s\n", workgroup)); return False; } - if (!(cli = get_ipc_connect(inet_ntoa(server_ip), &server_ip, user_info))) + print_sockaddr(addr, sizeof(addr), &server_ss); + if (!(cli = get_ipc_connect(addr, &server_ss, user_info))) return False; - if (!cli_NetServerEnum(cli, workgroup, SV_TYPE_ALL, add_name, + if (!cli_NetServerEnum(cli, workgroup, SV_TYPE_ALL, add_name, &servers)) return False; return True; } -static bool get_rpc_shares(struct cli_state *cli, +static bool get_rpc_shares(struct cli_state *cli, void (*fn)(const char *, uint32, const char *, void *), void *state) { -- cgit From d2cf97aeba14a4d336fb57b01f19bd5a08dcb003 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 29 Nov 2007 13:24:54 -0800 Subject: Remove the explicit TALLOC_CTX * from cli_struct. Make us very explicit about how long a talloc ctx should last. Jeremy. (This used to be commit ba9e2be2b5a59684e854609f9d82ea1633448c62) --- source3/utils/smbtree.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 0e0c993f4e..bcacddc414 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -71,13 +71,17 @@ static bool get_workgroups(struct user_auth_info *user_info) { struct cli_state *cli; struct sockaddr_storage server_ss; - pstring master_workgroup; + TALLOC_CTX *ctx = talloc_tos(); + char *master_workgroup = NULL; /* Try to connect to a #1d name of our current workgroup. If that doesn't work broadcast for a master browser and then jump off that workgroup. */ - pstrcpy(master_workgroup, lp_workgroup()); + master_workgroup = talloc_strdup(ctx, lp_workgroup()); + if (!master_workgroup) { + return false; + } if (!use_bcast && !find_master_ip(lp_workgroup(), &server_ss)) { DEBUG(4, ("Unable to find master browser for workgroup %s, falling back to broadcast\n", @@ -90,7 +94,9 @@ static bool get_workgroups(struct user_auth_info *user_info) return False; } - if (!(cli = get_ipc_connect_master_ip_bcast(master_workgroup, user_info))) { + if (!(cli = get_ipc_connect_master_ip_bcast(talloc_tos(), + user_info, + &master_workgroup))) { DEBUG(4, ("Unable to find master browser by " "broadcast\n")); return False; -- cgit From adf6d848de8ae32a83c7271d8ccd24d2cf8b47f7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 3 Dec 2007 18:48:41 -0800 Subject: Getting to the home stretch for elimination of pstrings... Jeremy. (This used to be commit 041163551194102ca67fef52c57d87020a1d09bc) --- source3/utils/smbtree.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index bcacddc414..23090013a3 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -32,7 +32,7 @@ static enum tree_level level = LEV_SHARE; struct name_list { struct name_list *prev, *next; - pstring name, comment; + char *name, *comment; uint32 server_type; }; @@ -57,10 +57,17 @@ static void add_name(const char *machine_name, uint32 server_type, ZERO_STRUCTP(new_name); - pstrcpy(new_name->name, machine_name); - pstrcpy(new_name->comment, comment); + new_name->name = SMB_STRDUP(machine_name); + new_name->comment = SMB_STRDUP(comment); new_name->server_type = server_type; + if (!new_name->name || !new_name->comment) { + SAFE_FREE(new_name->name); + SAFE_FREE(new_name->comment); + SAFE_FREE(new_name); + return; + } + DLIST_ADD(*name_list, new_name); } @@ -199,7 +206,7 @@ static bool get_shares(char *server_name, struct user_auth_info *user_info) if (get_rpc_shares(cli, add_name, &shares)) return True; - + if (!cli_RNetShareEnum(cli, add_name, &shares)) return False; @@ -268,7 +275,7 @@ static bool print_tree(struct user_auth_info *user_info) POPT_TABLEEND }; poptContext pc; - + /* Initialise samba stuff */ load_case_tables(); @@ -278,7 +285,7 @@ static bool print_tree(struct user_auth_info *user_info) setup_logging(argv[0],True); - pc = poptGetContext("smbtree", argc, (const char **)argv, long_options, + pc = poptGetContext("smbtree", argc, (const char **)argv, long_options, POPT_CONTEXT_KEEP_FIRST); while(poptGetNextOpt(pc) != -1); poptFreeContext(pc); @@ -291,9 +298,11 @@ static bool print_tree(struct user_auth_info *user_info) if (!cmdline_auth_info.got_pass) { char *pass = getpass("Password: "); if (pass) { - pstrcpy(cmdline_auth_info.password, pass); + strlcpy(cmdline_auth_info.password, + pass, + sizeof(cmdline_auth_info.password)); } - cmdline_auth_info.got_pass = True; + cmdline_auth_info.got_pass = true; } /* Now do our stuff */ -- cgit From 9fdf2d05867e5d6abd9099996b9e6c071bdbd0e7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 6 Dec 2007 18:49:39 -0800 Subject: Get closer to building with smbmount. Move parameter line changes into lib/util.c Jeremy. (This used to be commit 6ac5d81655927ba8eabea35adaae5adfcbb821c9) --- source3/utils/smbtree.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 23090013a3..91d3b1542b 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -265,6 +265,7 @@ static bool print_tree(struct user_auth_info *user_info) int main(int argc,char *argv[]) { TALLOC_CTX *frame = talloc_stackframe(); + struct user_auth_info local_user_info; struct poptOption long_options[] = { POPT_AUTOHELP { "broadcast", 'b', POPT_ARG_VAL, &use_bcast, True, "Use broadcast instead of using the master browser" }, @@ -295,19 +296,20 @@ static bool print_tree(struct user_auth_info *user_info) /* Parse command line args */ - if (!cmdline_auth_info.got_pass) { + if (!get_cmdline_auth_info_got_pass()) { char *pass = getpass("Password: "); if (pass) { - strlcpy(cmdline_auth_info.password, - pass, - sizeof(cmdline_auth_info.password)); + set_cmdline_auth_info_password(pass); } - cmdline_auth_info.got_pass = true; } /* Now do our stuff */ - if (!print_tree(&cmdline_auth_info)) { + if (!get_cmdline_auth_info_copy(&local_user_info)) { + return 1; + } + + if (!print_tree(&local_auth_info)) { TALLOC_FREE(frame); return 1; } -- cgit From 79c3aef7ea66b61a9df89ed40943586ca54c82ab Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 6 Dec 2007 18:52:36 -0800 Subject: Fix typos in auth change. Jeremy. (This used to be commit 440e9f5b51e42e5dc5ce3f8d10b9e43ca31e87ef) --- source3/utils/smbtree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 91d3b1542b..cf880498c1 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -265,7 +265,7 @@ static bool print_tree(struct user_auth_info *user_info) int main(int argc,char *argv[]) { TALLOC_CTX *frame = talloc_stackframe(); - struct user_auth_info local_user_info; + struct user_auth_info local_auth_info; struct poptOption long_options[] = { POPT_AUTOHELP { "broadcast", 'b', POPT_ARG_VAL, &use_bcast, True, "Use broadcast instead of using the master browser" }, @@ -305,7 +305,7 @@ static bool print_tree(struct user_auth_info *user_info) /* Now do our stuff */ - if (!get_cmdline_auth_info_copy(&local_user_info)) { + if (!get_cmdline_auth_info_copy(&local_auth_info)) { return 1; } -- cgit From 7faee02d0d351c5c039e8f1be7e82ce3a93cbe96 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 10 Dec 2007 11:30:37 -0800 Subject: Remove the char[1024] strings from dynconfig. Replace them with malloc'ing accessor functions. Should save a lot of static space :-). Jeremy. (This used to be commit 52dc5eaef2106015b3a8b659e818bdb15ad94b05) --- source3/utils/smbtree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index cf880498c1..572f3dca83 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -291,7 +291,7 @@ static bool print_tree(struct user_auth_info *user_info) while(poptGetNextOpt(pc) != -1); poptFreeContext(pc); - lp_load(dyn_CONFIGFILE,True,False,False,True); + lp_load(get_dyn_CONFIGFILE(),True,False,False,True); load_interfaces(); /* Parse command line args */ -- cgit From d09f0d281cf7014f51c7de4864d0366badbc8f0c Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 10 Mar 2008 05:05:37 +0100 Subject: Use rpccli_srvsvc_NetShareEnumAll in smbtree. Guenther (This used to be commit 0cf761f604975930f38213233e4bbf48d7ae7283) --- source3/utils/smbtree.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 572f3dca83..48eae5ac5c 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -150,10 +150,12 @@ static bool get_rpc_shares(struct cli_state *cli, NTSTATUS status; struct rpc_pipe_client *pipe_hnd; TALLOC_CTX *mem_ctx; - ENUM_HND enum_hnd; WERROR werr; - SRV_SHARE_INFO_CTR ctr; + struct srvsvc_NetShareInfoCtr info_ctr; + struct srvsvc_NetShareCtr1 ctr1; int i; + uint32_t resume_handle = 0; + uint32_t total_entries = 0; mem_ctx = talloc_new(NULL); if (mem_ctx == NULL) { @@ -161,8 +163,6 @@ static bool get_rpc_shares(struct cli_state *cli, return False; } - init_enum_hnd(&enum_hnd, 0); - pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, &status); if (pipe_hnd == NULL) { @@ -172,23 +172,29 @@ static bool get_rpc_shares(struct cli_state *cli, return False; } - werr = rpccli_srvsvc_net_share_enum(pipe_hnd, mem_ctx, 1, &ctr, - 0xffffffff, &enum_hnd); + ZERO_STRUCT(info_ctr); + ZERO_STRUCT(ctr1); + + info_ctr.level = 1; + info_ctr.ctr.ctr1 = &ctr1; + + status = rpccli_srvsvc_NetShareEnumAll(pipe_hnd, mem_ctx, + pipe_hnd->cli->desthost, + &info_ctr, + 0xffffffff, + &total_entries, + &resume_handle, + &werr); - if (!W_ERROR_IS_OK(werr)) { + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) { TALLOC_FREE(mem_ctx); cli_rpc_pipe_close(pipe_hnd); return False; } - for (i=0; iinfo_1_str.uni_netname); - comment = rpcstr_pull_unistr2_talloc( - mem_ctx, &info->info_1_str.uni_remark); - fn(name, info->info_1.type, comment, state); + for (i=0; iarray[i]; + fn(info.name, info.type, info.comment, state); } TALLOC_FREE(mem_ctx); -- cgit From 2a2188591b5ed922d09dc723adcf10f8b8f5e5a0 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 19 Apr 2008 21:56:43 +0200 Subject: Add "desthost" to rpc_pipe_client This reduces the dependency on cli_state (This used to be commit 783afab9c891dd7bcb78895b2a639b6f3a0edf5b) --- source3/utils/smbtree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 48eae5ac5c..d2dd1b49d3 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -179,7 +179,7 @@ static bool get_rpc_shares(struct cli_state *cli, info_ctr.ctr.ctr1 = &ctr1; status = rpccli_srvsvc_NetShareEnumAll(pipe_hnd, mem_ctx, - pipe_hnd->cli->desthost, + pipe_hnd->desthost, &info_ctr, 0xffffffff, &total_entries, -- cgit From e73e8297f5484b6c7f525917679414c09a145cf0 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 20 Apr 2008 13:51:46 +0200 Subject: Replace cli_rpc_pipe_close by a talloc destructor on rpc_pipe_struct (This used to be commit 99fc3283c4ecc791f5a242bd1983b4352ce3e6cf) --- source3/utils/smbtree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index d2dd1b49d3..c2b364d1e9 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -188,7 +188,7 @@ static bool get_rpc_shares(struct cli_state *cli, if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) { TALLOC_FREE(mem_ctx); - cli_rpc_pipe_close(pipe_hnd); + TALLOC_FREE(pipe_hnd); return False; } @@ -198,7 +198,7 @@ static bool get_rpc_shares(struct cli_state *cli, } TALLOC_FREE(mem_ctx); - cli_rpc_pipe_close(pipe_hnd); + TALLOC_FREE(pipe_hnd); return True; } -- cgit From 4d8836ab96889bcdc35e86bedffa6117f9c35095 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 5 May 2008 16:58:24 +0200 Subject: Fix client authentication with -P switch in client tools (Bug 5435). Guenther (This used to be commit d077ef64cd1d9bbaeb936566c2c70da508de829f) --- source3/utils/smbtree.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index c2b364d1e9..e975a1c8a2 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -302,6 +302,12 @@ static bool print_tree(struct user_auth_info *user_info) /* Parse command line args */ + if (get_cmdline_auth_info_use_machine_account() && + !set_cmdline_auth_info_machine_account_creds()) { + TALLOC_FREE(frame); + return 1; + } + if (!get_cmdline_auth_info_got_pass()) { char *pass = getpass("Password: "); if (pass) { -- cgit From 1335da2a7cc639310e5d389e8e8dbe67c4e7ca25 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 20 Jul 2008 11:04:31 +0200 Subject: Refactoring: Change calling conventions for cli_rpc_pipe_open_noauth Pass in ndr_syntax_id instead of pipe_idx, return NTSTATUS (This used to be commit 9abc9dc4dc13bd3e42f98eff64eacf24b51f5779) --- source3/utils/smbtree.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/utils/smbtree.c') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index e975a1c8a2..ce2de4d7fe 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -163,9 +163,10 @@ static bool get_rpc_shares(struct cli_state *cli, return False; } - pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, &status); + status = cli_rpc_pipe_open_noauth(cli, &ndr_table_srvsvc.syntax_id, + &pipe_hnd); - if (pipe_hnd == NULL) { + if (!NT_STATUS_IS_OK(status)) { DEBUG(10, ("Could not connect to srvsvc pipe: %s\n", nt_errstr(status))); TALLOC_FREE(mem_ctx); -- cgit