diff options
author | Jeremy Allison <jra@samba.org> | 2002-02-01 22:15:18 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2002-02-01 22:15:18 +0000 |
commit | 8d63a817bb04da3c7cc43e342a9034f5f23c5041 (patch) | |
tree | de549371c7728978ab045eab1a658b29007cc9ad /source/utils | |
parent | f98c14e8d6d8f1def0edcd02e1dfe66bab8a2ab6 (diff) | |
download | samba-8d63a817bb04da3c7cc43e342a9034f5f23c5041.tar.gz samba-8d63a817bb04da3c7cc43e342a9034f5f23c5041.tar.xz samba-8d63a817bb04da3c7cc43e342a9034f5f23c5041.zip |
Move over to RELEASE branch.
Jeremy.
Diffstat (limited to 'source/utils')
-rw-r--r-- | source/utils/locktest.c | 2 | ||||
-rw-r--r-- | source/utils/locktest2.c | 2 | ||||
-rw-r--r-- | source/utils/make_printerdef.c | 2 | ||||
-rw-r--r-- | source/utils/make_smbcodepage.c | 6 | ||||
-rw-r--r-- | source/utils/make_unicodemap.c | 8 | ||||
-rw-r--r-- | source/utils/masktest.c | 1 | ||||
-rw-r--r-- | source/utils/nmblookup.c | 21 | ||||
-rw-r--r-- | source/utils/pdbedit.c | 149 | ||||
-rw-r--r-- | source/utils/rpccheck.c | 2 | ||||
-rw-r--r-- | source/utils/rpctorture.c | 8 | ||||
-rw-r--r-- | source/utils/smbcacls.c | 40 | ||||
-rw-r--r-- | source/utils/smbcontrol.c | 19 | ||||
-rw-r--r-- | source/utils/smbfilter.c | 6 | ||||
-rw-r--r-- | source/utils/smbpasswd.c | 183 | ||||
-rw-r--r-- | source/utils/smbw_sample.c | 31 | ||||
-rw-r--r-- | source/utils/status.c | 5 | ||||
-rw-r--r-- | source/utils/testparm.c | 4 | ||||
-rw-r--r-- | source/utils/testprns.c | 1 | ||||
-rw-r--r-- | source/utils/torture.c | 11 |
19 files changed, 301 insertions, 200 deletions
diff --git a/source/utils/locktest.c b/source/utils/locktest.c index 80dbba1e37e..4697067e881 100644 --- a/source/utils/locktest.c +++ b/source/utils/locktest.c @@ -217,7 +217,7 @@ static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], int fnum[NS } cli_ulogoff(cli[server][conn]); cli_shutdown(cli[server][conn]); - free(cli[server][conn]); + SAFE_FREE(cli[server][conn]); cli[server][conn] = NULL; } cli[server][conn] = connect_one(share[server]); diff --git a/source/utils/locktest2.c b/source/utils/locktest2.c index 0391aa29426..91083bc3ec4 100644 --- a/source/utils/locktest2.c +++ b/source/utils/locktest2.c @@ -268,7 +268,7 @@ static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], } cli_ulogoff(cli[server][conn]); cli_shutdown(cli[server][conn]); - free(cli[server][conn]); + SAFE_FREE(cli[server][conn]); cli[server][conn] = NULL; } cli[server][conn] = connect_one(share[server]); diff --git a/source/utils/make_printerdef.c b/source/utils/make_printerdef.c index a449a24fcdd..f5d40ea3f00 100644 --- a/source/utils/make_printerdef.c +++ b/source/utils/make_printerdef.c @@ -307,7 +307,7 @@ static char *find_desc(FILE *fichier,char *text) if (!strcmp(text,long_desc)) found=1; } - free(chaine); + SAFE_FREE(chaine); if (!found || !crap) return(NULL); while(*crap==' ') crap++; pstrcpy(short_desc,crap); diff --git a/source/utils/make_smbcodepage.c b/source/utils/make_smbcodepage.c index 1bd3edc2631..256dde7c0d1 100644 --- a/source/utils/make_smbcodepage.c +++ b/source/utils/make_smbcodepage.c @@ -99,7 +99,7 @@ static int clean_data( char **buf, size_t *size) newbuf_p += (strlen(newbuf_p) + 1); } - free(*buf); + SAFE_FREE(*buf); *buf = newbuf; return num_lines; } @@ -209,7 +209,7 @@ The maximum size I will believe is 100k.\n", prog_name, size); { fprintf(stderr, "%s: read failed for file %s. Error was %s.\n", prog_name, input_file, strerror(errno)); - free((char *)buf); + SAFE_FREE(buf); fclose(fp); exit(1); } @@ -303,7 +303,7 @@ definition file. File %s has %d.\n", prog_name, MAXCODEPAGELINES, input_file, nu fclose(fp); - free(orig_buf); + SAFE_FREE(orig_buf); return 0; } diff --git a/source/utils/make_unicodemap.c b/source/utils/make_unicodemap.c index 3584facbf62..79c63ff003c 100644 --- a/source/utils/make_unicodemap.c +++ b/source/utils/make_unicodemap.c @@ -96,7 +96,7 @@ static size_t clean_data( char **buf, size_t *size) newbuf_p += (strlen(newbuf_p) + 1); } - free(*buf); + SAFE_FREE(*buf); *buf = newbuf; return num_lines; } @@ -172,7 +172,7 @@ static int do_compile(const char *codepage, const char *input_file, const char * if(fread( buf, 1, size, fp) != size) { fprintf(stderr, "%s: read failed for file %s. Error was %s.\n", prog_name, input_file, strerror(errno)); - free((char *)buf); + SAFE_FREE(buf); fclose(fp); exit(1); } @@ -289,8 +289,8 @@ static int do_compile(const char *codepage, const char *input_file, const char * fclose(fp); - free(orig_buf); - free(output_buf); + SAFE_FREE(orig_buf); + SAFE_FREE(output_buf); return 0; } diff --git a/source/utils/masktest.c b/source/utils/masktest.c index a654b5bfd11..ba719bae248 100644 --- a/source/utils/masktest.c +++ b/source/utils/masktest.c @@ -23,7 +23,6 @@ #include "includes.h" -extern int DEBUGLEVEL; static fstring password; static fstring username; static int got_pass; diff --git a/source/utils/nmblookup.c b/source/utils/nmblookup.c index 0f978a6cf3f..27bd419c781 100644 --- a/source/utils/nmblookup.c +++ b/source/utils/nmblookup.c @@ -24,9 +24,8 @@ #include "includes.h" -extern int DEBUGLEVEL; - extern struct in_addr ipzero; +extern BOOL AllowDebugChange; static BOOL use_bcast = True; static BOOL got_bcast = False; @@ -113,7 +112,7 @@ static void do_node_status(int fd, char *name, int type, struct in_addr ip) printf("Looking up status of %s\n",inet_ntoa(ip)); make_nmb_name(&nname, name, type); - status = name_status_query(fd,&nname,ip, &count); + status = node_status_query(fd,&nname,ip, &count); if (status) { for (i=0;i<count;i++) { fstrcpy(cleanname, status[i].name); @@ -124,7 +123,7 @@ static void do_node_status(int fd, char *name, int type, struct in_addr ip) cleanname,status[i].type, node_status_flags(status[i].flags)); } - free(status); + SAFE_FREE(status); } printf("\n"); } @@ -197,9 +196,11 @@ int main(int argc,char *argv[]) int i; static pstring servicesf = CONFIGFILE; BOOL lookup_by_ip = False; - int commandline_debuglevel = -2; DEBUGLEVEL = 1; + /* Prevent smb.conf setting from overridding */ + AllowDebugChange = False; + *lookup = 0; TimeInit(); @@ -241,7 +242,7 @@ int main(int argc,char *argv[]) recursion_desired = True; break; case 'd': - commandline_debuglevel = DEBUGLEVEL = atoi(optarg); + DEBUGLEVEL = atoi(optarg); break; case 's': pstrcpy(servicesf, optarg); @@ -270,14 +271,6 @@ int main(int argc,char *argv[]) fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); } - /* - * Ensure we reset DEBUGLEVEL if someone specified it - * on the command line. - */ - - if(commandline_debuglevel != -2) - DEBUGLEVEL = commandline_debuglevel; - load_interfaces(); if (!open_sockets()) return(1); diff --git a/source/utils/pdbedit.c b/source/utils/pdbedit.c index 7006eeee4e5..a96793e18e2 100644 --- a/source/utils/pdbedit.c +++ b/source/utils/pdbedit.c @@ -32,7 +32,7 @@ #include "includes.h" extern pstring global_myname; -extern int DEBUGLEVEL; +extern BOOL AllowDebugChange; /* * Next two lines needed for SunOS and don't @@ -43,11 +43,11 @@ extern int optind; /********************************************************* Print command usage on stderr and die. -**********************************************************/ + **********************************************************/ static void usage(void) { if (getuid() == 0) { - printf("tdbedit options\n"); + printf("pdbedit options\n"); } else { printf("You need to be root to use this tool!\n"); } @@ -188,13 +188,13 @@ static int set_user_info (char *username, char *fullname, char *homedir, char *d if (fullname) pdb_set_fullname(sam_pwent, fullname); if (homedir) - pdb_set_homedir(sam_pwent, homedir); + pdb_set_homedir(sam_pwent, homedir, True); if (drive) - pdb_set_dir_drive(sam_pwent,drive); + pdb_set_dir_drive(sam_pwent, drive, True); if (script) - pdb_set_logon_script(sam_pwent, script); + pdb_set_logon_script(sam_pwent, script, True); if (profile) - pdb_set_profile_path (sam_pwent, profile); + pdb_set_profile_path (sam_pwent, profile, True); if (pdb_update_sam_account (sam_pwent, True)) print_user_info (username, True, False); @@ -208,13 +208,98 @@ static int set_user_info (char *username, char *fullname, char *homedir, char *d } /********************************************************* + A strdup with exit +**********************************************************/ + +static char *strdup_x(const char *s) +{ + char *new_s = strdup(s); + if (!new_s) { + fprintf(stderr,"out of memory\n"); + exit(1); + } + return new_s; +} + +/************************************************************* + Utility function to prompt for passwords from stdin. Each + password entered must end with a newline. +*************************************************************/ +static char *stdin_new_passwd(void) +{ + static fstring new_passwd; + size_t len; + + ZERO_ARRAY(new_passwd); + + /* + * if no error is reported from fgets() and string at least contains + * the newline that ends the password, then replace the newline with + * a null terminator. + */ + if ( fgets(new_passwd, sizeof(new_passwd), stdin) != NULL) { + if ((len = strlen(new_passwd)) > 0) { + if(new_passwd[len-1] == '\n') + new_passwd[len - 1] = 0; + } + } + return(new_passwd); +} + +/************************************************************* + Utility function to get passwords via tty or stdin + Used if the '-s' option is set to silently get passwords + to enable scripting. + _copied_ from smbpasswd +*************************************************************/ +static char *get_pass( char *prompt, BOOL stdin_get) +{ + char *p; + if (stdin_get) { + p = stdin_new_passwd(); + } else { + p = getpass(prompt); + } + return strdup_x(p); +} + +/************************************************************* + Utility function to prompt for new password. + _copied_ from smbpasswd +*************************************************************/ +static char *prompt_for_new_password(BOOL stdin_get) +{ + char *p; + fstring new_passwd; + + ZERO_ARRAY(new_passwd); + + p = get_pass("New SMB password:", stdin_get); + + fstrcpy(new_passwd, p); + safe_free(p); + + p = get_pass("Retype new SMB password:", stdin_get); + + if (strcmp(p, new_passwd)) { + fprintf(stderr, "Mismatch - password unchanged.\n"); + ZERO_ARRAY(new_passwd); + safe_free(p); + return NULL; + } + + return p; +} + + +/********************************************************* Add New User **********************************************************/ static int new_user (char *username, char *fullname, char *homedir, char *drive, char *script, char *profile) { SAM_ACCOUNT *sam_pwent=NULL; struct passwd *pwd = NULL; - char *password1, *password2; + char *password; ZERO_STRUCT(sam_pwent); @@ -225,28 +310,27 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive, pdb_free_sam (sam_pwent); return -1; } - - password1 = getpass("new password:"); - password2 = getpass("retype new password:"); - if (strcmp (password1, password2)) { - fprintf (stderr, "Passwords does not match!\n"); + + password = prompt_for_new_password(0); + if (!password) { + fprintf (stderr, "Passwords do not match!\n"); pdb_free_sam (sam_pwent); return -1; } - pdb_set_plaintext_passwd(sam_pwent, password1); + pdb_set_plaintext_passwd(sam_pwent, password); pdb_set_username(sam_pwent, username); if (fullname) pdb_set_fullname(sam_pwent, fullname); if (homedir) - pdb_set_homedir (sam_pwent, homedir); + pdb_set_homedir (sam_pwent, homedir, True); if (drive) - pdb_set_dir_drive (sam_pwent, drive); + pdb_set_dir_drive (sam_pwent, drive, True); if (script) - pdb_set_logon_script(sam_pwent, script); + pdb_set_logon_script(sam_pwent, script, True); if (profile) - pdb_set_profile_path (sam_pwent, profile); + pdb_set_profile_path (sam_pwent, profile, True); /* TODO: Check uid not being in MACHINE UID range!! */ pdb_set_uid (sam_pwent, pwd->pw_uid); @@ -557,7 +641,7 @@ static int import_users (char *filename) good++; pdb_reset_sam (sam_pwent); } - printf ("%d lines read.\n%d entryes imported\n", line, good); + printf ("%d lines read.\n%d entries imported\n", line, good); pdb_free_sam(sam_pwent); return 0; } @@ -588,25 +672,35 @@ int main (int argc, char **argv) TimeInit(); - setup_logging("tdbedit", True); + setup_logging("pdbedit", True); + + charset_initialise(); if (argc < 2) { usage(); return 0; } - if(!initialize_password_db(True)) { - fprintf(stderr, "Can't setup password database vectors.\n"); - exit(1); - } - + DEBUGLEVEL = 0; + AllowDebugChange = False; + if (!lp_load(servicesf,True,False,False)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); exit(1); } + + secrets_init(); + + if(!initialize_password_db(True)) { + fprintf(stderr, "Can't setup password database vectors.\n"); + exit(1); + } - while ((ch = getopt(argc, argv, "ad:f:h:i:lmp:s:u:vwx")) != EOF) { + + codepage_initialise(lp_client_code_page()); + + while ((ch = getopt(argc, argv, "ad:f:h:i:lmp:s:u:vwxD:")) != EOF) { switch(ch) { case 'a': add_user = True; @@ -653,6 +747,9 @@ int main (int argc, char **argv) import = True; smbpasswd = optarg; break; + case 'D': + DEBUGLEVEL = atoi(optarg); + break; default: usage(); } diff --git a/source/utils/rpccheck.c b/source/utils/rpccheck.c index 1db7de34234..e8e61e9f718 100644 --- a/source/utils/rpccheck.c +++ b/source/utils/rpccheck.c @@ -21,8 +21,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - main() { char filter[]="0123456789ABCDEF"; diff --git a/source/utils/rpctorture.c b/source/utils/rpctorture.c index c80cfe4adea..3bf70b9719e 100644 --- a/source/utils/rpctorture.c +++ b/source/utils/rpctorture.c @@ -34,10 +34,6 @@ extern pstring global_myname; extern pstring user_socket_options; -extern pstring debugf; -extern int DEBUGLEVEL; - - extern file_info def_finfo; #define CNV_LANG(s) dos2unix_format(s,False) @@ -240,6 +236,7 @@ enum client_action enum client_action cli_action = CLIENT_NONE; int nprocs = 1; int numops = 100; + pstring logfile; struct client_info cli_info; @@ -458,8 +455,9 @@ enum client_action case 'l': { - slprintf(debugf, sizeof(debugf)-1, + slprintf(logfile, sizeof(logfile)-1, "%s.client",optarg); + lp_set_logfile(logfile); break; } diff --git a/source/utils/smbcacls.c b/source/utils/smbcacls.c index 59385decaa4..f65f65fd330 100644 --- a/source/utils/smbcacls.c +++ b/source/utils/smbcacls.c @@ -92,9 +92,8 @@ static BOOL cacls_open_policy_hnd(void) /* Some systems don't support SEC_RIGHTS_MAXIMUM_ALLOWED, but NT sends 0x2000000 so we might as well do it too. */ - if (cli_lsa_open_policy(&lsa_cli, lsa_cli.mem_ctx, True, - GENERIC_EXECUTE_ACCESS, &pol) - != NT_STATUS_OK) { + if (!NT_STATUS_IS_OK(cli_lsa_open_policy(&lsa_cli, lsa_cli.mem_ctx, True, + GENERIC_EXECUTE_ACCESS, &pol))) { return False; } @@ -118,8 +117,8 @@ static void SidToString(fstring str, DOM_SID *sid) /* Ask LSA to convert the sid to a name */ if (!cacls_open_policy_hnd() || - cli_lsa_lookup_sids(&lsa_cli, lsa_cli.mem_ctx, &pol, 1, sid, &names, &types, - &num_names) != NT_STATUS_OK || + !NT_STATUS_IS_OK(cli_lsa_lookup_sids(&lsa_cli, lsa_cli.mem_ctx, &pol, 1, sid, &names, &types, + &num_names)) || !names || !names[0]) { return; } @@ -142,8 +141,8 @@ static BOOL StringToSid(DOM_SID *sid, char *str) } if (!cacls_open_policy_hnd() || - cli_lsa_lookup_names(&lsa_cli, lsa_cli.mem_ctx, &pol, 1, &str, &sids, &types, - &num_sids) != NT_STATUS_OK) { + !NT_STATUS_IS_OK(cli_lsa_lookup_names(&lsa_cli, lsa_cli.mem_ctx, &pol, 1, &str, &sids, &types, + &num_sids))) { result = False; goto done; } @@ -164,7 +163,7 @@ static void print_ace(FILE *f, SEC_ACE *ace) int do_print = 0; uint32 got_mask; - SidToString(sidstr, &ace->sid); + SidToString(sidstr, &ace->trustee); fprintf(f, "%s:", sidstr); @@ -329,7 +328,7 @@ static BOOL add_ace(SEC_ACL **the_acl, SEC_ACE *ace) memcpy(aces, (*the_acl)->ace, (*the_acl)->num_aces * sizeof(SEC_ACE)); memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE)); new = make_sec_acl(ctx,(*the_acl)->revision,1+(*the_acl)->num_aces, aces); - free(aces); + SAFE_FREE(aces); (*the_acl) = new; return True; } @@ -392,8 +391,8 @@ static SEC_DESC *sec_desc_parse(char *str) ret = make_sec_desc(ctx,revision, owner_sid, grp_sid, NULL, dacl, &sd_size); - if (grp_sid) free(grp_sid); - if (owner_sid) free(owner_sid); + SAFE_FREE(grp_sid); + SAFE_FREE(owner_sid); return ret; } @@ -528,7 +527,7 @@ static int ace_compare(SEC_ACE *ace1, SEC_ACE *ace2) { if (sec_ace_equal(ace1, ace2)) return 0; if (ace1->type != ace2->type) return ace2->type - ace1->type; - if (sid_compare(&ace1->sid, &ace2->sid)) return sid_compare(&ace1->sid, &ace2->sid); + if (sid_compare(&ace1->trustee, &ace2->trustee)) return sid_compare(&ace1->trustee, &ace2->trustee); if (ace1->flags != ace2->flags) return ace1->flags - ace2->flags; if (ace1->info.mask != ace2->info.mask) return ace1->info.mask - ace2->info.mask; if (ace1->size != ace2->size) return ace1->size - ace2->size; @@ -606,10 +605,8 @@ static int cacl_set(struct cli_state *cli, char *filename, } old->dacl->num_aces--; if (old->dacl->num_aces == 0) { - free(old->dacl->ace); - old->dacl->ace=NULL; - free(old->dacl); - old->dacl = NULL; + SAFE_FREE(old->dacl->ace); + SAFE_FREE(old->dacl); old->off_dacl = 0; } found = True; @@ -630,8 +627,8 @@ static int cacl_set(struct cli_state *cli, char *filename, BOOL found = False; for (j=0;old->dacl && j<old->dacl->num_aces;j++) { - if (sid_equal(&sd->dacl->ace[i].sid, - &old->dacl->ace[j].sid)) { + if (sid_equal(&sd->dacl->ace[i].trustee, + &old->dacl->ace[j].trustee)) { old->dacl->ace[j] = sd->dacl->ace[i]; found = True; } @@ -640,7 +637,7 @@ static int cacl_set(struct cli_state *cli, char *filename, if (!found) { fstring str; - SidToString(str, &sd->dacl->ace[i].sid); + SidToString(str, &sd->dacl->ace[i].trustee); printf("ACL for SID %s not found\n", str); } } @@ -718,14 +715,12 @@ struct cli_state *connect_one(char *share) !cli_connect(c, server_n, &ip)) { DEBUG(0,("Connection to %s failed\n", server_n)); cli_shutdown(c); - safe_free(c); return NULL; } if (!cli_session_request(c, &calling, &called)) { DEBUG(0,("session request to %s failed\n", called.name)); cli_shutdown(c); - safe_free(c); if (strcmp(called.name, "*SMBSERVER")) { make_nmb_name(&called , "*SMBSERVER", 0x20); goto again; @@ -738,7 +733,6 @@ struct cli_state *connect_one(char *share) if (!cli_negprot(c)) { DEBUG(0,("protocol negotiation failed\n")); cli_shutdown(c); - safe_free(c); return NULL; } @@ -755,7 +749,6 @@ struct cli_state *connect_one(char *share) lp_workgroup())) { DEBUG(0,("session setup failed: %s\n", cli_errstr(c))); cli_shutdown(c); - safe_free(c); return NULL; } @@ -765,7 +758,6 @@ struct cli_state *connect_one(char *share) password, strlen(password)+1)) { DEBUG(0,("tree connect failed: %s\n", cli_errstr(c))); cli_shutdown(c); - safe_free(c); return NULL; } diff --git a/source/utils/smbcontrol.c b/source/utils/smbcontrol.c index bba7b15dd28..3b4781bb742 100644 --- a/source/utils/smbcontrol.c +++ b/source/utils/smbcontrol.c @@ -21,6 +21,8 @@ #include "includes.h" +extern BOOL AllowDebugChange; + static struct { char *name; int value; @@ -175,7 +177,7 @@ static int parse_type(char *mtype) /**************************************************************************** do command ****************************************************************************/ -static BOOL do_command(char *dest, char *msg_name, char **params) +static BOOL do_command(char *dest, char *msg_name, int iparams, char **params) { int i, n, v; int mtype; @@ -308,7 +310,10 @@ static BOOL do_command(char *dest, char *msg_name, char **params) n = atoi(params[0]); pong_count = 0; for (i=0;i<n;i++) { - retval = send_message(dest, MSG_PING, NULL, 0, True); + if (iparams > 1) + retval = send_message(dest, MSG_PING, params[1], strlen(params[1]) + 1, True); + else + retval = send_message(dest, MSG_PING, NULL, 0, True); if (retval == False) break; } if (retval) { @@ -339,6 +344,8 @@ static BOOL do_command(char *dest, char *msg_name, char **params) TimeInit(); setup_logging(argv[0],True); + AllowDebugChange = False; + DEBUGLEVEL = 0; charset_initialise(); if (argc < 2) usage(True); @@ -366,17 +373,17 @@ static BOOL do_command(char *dest, char *msg_name, char **params) if (!interactive) { if (argc < 2) usage(True); - return (do_command(argv[0],argv[1],argc > 2 ? &argv[2] : 0)); + return (do_command(argv[0],argv[1], argc-2, argc > 2 ? &argv[2] : 0)); } while (True) { - char *myargv[3]; + char *myargv[4]; int myargc; printf("smbcontrol> "); if (!fgets(temp, sizeof(temp)-1, stdin)) break; myargc = 0; - while ((myargc < 3) && + while ((myargc < 4) && (myargv[myargc] = strtok(myargc?NULL:temp," \t\n"))) { myargc++; } @@ -384,7 +391,7 @@ static BOOL do_command(char *dest, char *msg_name, char **params) if (strequal(myargv[0],"q")) break; if (myargc < 2) usage(False); - else if (!do_command(myargv[0],myargv[1],myargc > 2 ? &myargv[2] : 0)) + else if (!do_command(myargv[0],myargv[1],myargc-2,myargc > 2 ? &myargv[2] : 0)) usage(False); } return(0); diff --git a/source/utils/smbfilter.c b/source/utils/smbfilter.c index db83873e694..6be0860c928 100644 --- a/source/utils/smbfilter.c +++ b/source/utils/smbfilter.c @@ -36,8 +36,6 @@ static char *netbiosname; static char packet[BUFFER_SIZE]; -extern int DEBUGLEVEL; - static void filter_reply(char *buf) { int msg_type = CVAL(buf,0); @@ -120,7 +118,7 @@ static void filter_child(int c, struct in_addr dest_ip) if (s != -1) FD_SET(s, &fds); if (c != -1) FD_SET(c, &fds); - num = sys_select_intr(MAX(s+1, c+1),&fds,NULL); + num = sys_select_intr(MAX(s+1, c+1),&fds,NULL,NULL,NULL); if (num <= 0) continue; if (c != -1 && FD_ISSET(c, &fds)) { @@ -184,7 +182,7 @@ static void start_filter(char *desthost) FD_ZERO(&fds); FD_SET(s, &fds); - num = sys_select_intr(s+1,&fds,NULL); + num = sys_select_intr(s+1,&fds,NULL,NULL,NULL); if (num > 0) { c = accept(s, &addr, &in_addrlen); if (c != -1) { diff --git a/source/utils/smbpasswd.c b/source/utils/smbpasswd.c index b29b5d9a97e..24185114f13 100644 --- a/source/utils/smbpasswd.c +++ b/source/utils/smbpasswd.c @@ -22,7 +22,7 @@ #include "includes.h" extern pstring global_myname; -extern int DEBUGLEVEL; +extern BOOL AllowDebugChange; /* * Next two lines needed for SunOS and don't @@ -35,16 +35,17 @@ extern int optind; static BOOL local_mode; /********************************************************* -a strdup with exit + A strdup with exit **********************************************************/ -static char *xstrdup(char *s) + +static char *strdup_x(const char *s) { - s = strdup(s); - if (!s) { + char *new_s = strdup(s); + if (!new_s) { fprintf(stderr,"out of memory\n"); exit(1); } - return s; + return new_s; } @@ -81,66 +82,6 @@ static void usage(void) exit(1); } -/********************************************************* -Join a domain. -**********************************************************/ -static int join_domain(char *domain, char *remote) -{ - pstring remote_machine; - fstring trust_passwd; - unsigned char orig_trust_passwd_hash[16]; - BOOL ret; - - pstrcpy(remote_machine, remote ? remote : ""); - fstrcpy(trust_passwd, global_myname); - strlower(trust_passwd); - E_md4hash( (uchar *)trust_passwd, orig_trust_passwd_hash); - - /* Ensure that we are not trying to join a - domain if we are locally set up as a domain - controller. */ - - if(strequal(remote, global_myname)) { - fprintf(stderr, "Cannot join domain %s as the domain controller name is our own. We cannot be a domain controller for a domain and also be a domain member.\n", domain); - return 1; - } - - /* - * Write the old machine account password. - */ - - if(!secrets_store_trust_account_password(domain, orig_trust_passwd_hash)) { - fprintf(stderr, "Unable to write the machine account password for \ -machine %s in domain %s.\n", global_myname, domain); - return 1; - } - - /* - * If we are given a remote machine assume this is the PDC. - */ - - if(remote == NULL) { - pstrcpy(remote_machine, lp_passwordserver()); - } - - if(!*remote_machine) { - fprintf(stderr, "No password server list given in smb.conf - \ -unable to join domain.\n"); - return 1; - } - - ret = change_trust_account_password( domain, remote_machine); - - if(!ret) { - trust_password_delete(domain); - fprintf(stderr,"Unable to join domain %s.\n",domain); - } else { - printf("Joined domain %s.\n",domain); - } - - return (int)ret; -} - /* Initialise client credentials for authenticated pipe access */ void init_rpcclient_creds(struct ntuser_creds *creds, char* username, @@ -165,13 +106,13 @@ Join a domain using the administrator username and password /* Macro for checking RPC error codes to make things more readable */ #define CHECK_RPC_ERR(rpc, msg) \ - if ((result = rpc) != NT_STATUS_OK) { \ + if (!NT_STATUS_IS_OK(result = rpc)) { \ DEBUG(0, (msg ": %s\n", get_nt_error_msg(result))); \ goto done; \ } #define CHECK_RPC_ERR_DEBUG(rpc, debug_args) \ - if ((result = rpc) != NT_STATUS_OK) { \ + if (!NT_STATUS_IS_OK(result = rpc)) { \ DEBUG(0, debug_args); \ goto done; \ } @@ -205,7 +146,7 @@ static int join_domain_byuser(char *domain, char *remote_machine, /* Misc */ - uint32 result; + NTSTATUS result; int retval = 1; /* Connect to remote machine */ @@ -293,14 +234,18 @@ static int join_domain_byuser(char *domain, char *remote_machine, acct_name, ACB_WSTRUST, unknown, &user_pol, &user_rid); + } - /* We *must* do this.... don't ask... */ + if (NT_STATUS_IS_OK(result)) { + + /* We *must* do this.... don't ask... */ + CHECK_RPC_ERR_DEBUG(cli_samr_close(&cli, mem_ctx, &user_pol), ("error closing user policy")); result = NT_STATUS_USER_EXISTS; - } + } - if (result == NT_STATUS_USER_EXISTS) { + if (NT_STATUS_V(result) == NT_STATUS_V(NT_STATUS_USER_EXISTS)) { uint32 num_rids, *name_types, *user_rids; uint32 flags = 0x3e8; char *names; @@ -333,7 +278,7 @@ static int join_domain_byuser(char *domain, char *remote_machine, ("could not re-open existing user %s: %s\n", acct_name, get_nt_error_msg(result))); - } else if (result != NT_STATUS_OK) { + } else if (!NT_STATUS_IS_OK(result)) { DEBUG(0, ("error creating domain user: %s\n", get_nt_error_msg(result))); goto done; @@ -430,6 +375,75 @@ static int join_domain_byuser(char *domain, char *remote_machine, return retval; } +/********************************************************* +Join a domain. Old server manager method. +**********************************************************/ + +static int join_domain(char *domain, char *remote) +{ + pstring remote_machine; + fstring trust_passwd; + unsigned char orig_trust_passwd_hash[16]; + DOM_SID domain_sid; + BOOL ret; + + pstrcpy(remote_machine, remote ? remote : ""); + fstrcpy(trust_passwd, global_myname); + strlower(trust_passwd); + E_md4hash( (uchar *)trust_passwd, orig_trust_passwd_hash); + + /* Ensure that we are not trying to join a + domain if we are locally set up as a domain + controller. */ + + if(strequal(remote, global_myname)) { + fprintf(stderr, "Cannot join domain %s as the domain controller name is our own. We cannot be a domain controller for a domain and also be a domain member.\n", domain); + return 1; + } + + /* + * Write the old machine account password. + */ + + if(!secrets_store_trust_account_password(domain, orig_trust_passwd_hash)) { + fprintf(stderr, "Unable to write the machine account password for \ +machine %s in domain %s.\n", global_myname, domain); + return 1; + } + + /* + * If we are given a remote machine assume this is the PDC. + */ + + if(remote == NULL) { + pstrcpy(remote_machine, lp_passwordserver()); + } + + if(!*remote_machine) { + fprintf(stderr, "No password server list given in smb.conf - \ +unable to join domain.\n"); + return 1; + } + + if (!fetch_domain_sid( domain, remote_machine, &domain_sid) || + !secrets_store_domain_sid(domain, &domain_sid)) { + fprintf(stderr,"Failed to get domain SID. Unable to join domain %s.\n",domain); + return 1; + } + + ret = change_trust_account_password( domain, remote_machine); + + if(!ret) { + trust_password_delete(domain); + fprintf(stderr,"Unable to join domain %s.\n",domain); + return 1; + } else { + printf("Joined domain %s.\n",domain); + } + + return 0; +} + static void set_line_buffering(FILE *f) { setvbuf(f, NULL, _IOLBF, 0); @@ -474,7 +488,7 @@ static char *get_pass( char *prompt, BOOL stdin_get) } else { p = getpass(prompt); } - return xstrdup(p); + return strdup_x(p); } /************************************************************* @@ -546,11 +560,6 @@ static BOOL password_change(const char *remote_machine, char *user_name, ******************************************************************/ static BOOL store_ldap_admin_pw (char* pw) { - TDB_DATA kbuf, dbuf; - pstring fname; - pstring key; - char *p; - if (!pw) return False; @@ -593,11 +602,11 @@ static int process_root(int argc, char *argv[]) break; case 'x': local_flags |= LOCAL_DELETE_USER; - new_passwd = xstrdup("XXXXXX"); + new_passwd = strdup_x("XXXXXX"); break; case 'd': local_flags |= LOCAL_DISABLE_USER; - new_passwd = xstrdup("XXXXXX"); + new_passwd = strdup_x("XXXXXX"); break; case 'e': local_flags |= LOCAL_ENABLE_USER; @@ -607,7 +616,7 @@ static int process_root(int argc, char *argv[]) break; case 'n': local_flags |= LOCAL_SET_NO_PASSWORD; - new_passwd = xstrdup("NO PASSWORD"); + new_passwd = strdup_x("NO PASSWORD"); break; case 'j': new_domain = optarg; @@ -740,7 +749,7 @@ static int process_root(int argc, char *argv[]) if (got_username || got_pass) usage(); fstrcpy(user_name, argv[0]); - new_passwd = xstrdup(argv[1]); + new_passwd = strdup_x(argv[1]); break; default: usage(); @@ -770,7 +779,7 @@ static int process_root(int argc, char *argv[]) if (local_flags & LOCAL_ADD_USER) { safe_free(new_passwd); - new_passwd = xstrdup(user_name); + new_passwd = strdup_x(user_name); strlower(new_passwd); } @@ -810,7 +819,7 @@ static int process_root(int argc, char *argv[]) goto done; } if((sampass != NULL) && (pdb_get_lanman_passwd(sampass) != NULL)) { - new_passwd = xstrdup("XXXX"); /* Don't care. */ + new_passwd = strdup_x("XXXX"); /* Don't care. */ } pdb_free_sam(sampass); @@ -910,7 +919,7 @@ static int process_nonroot(int argc, char *argv[]) if (!user_name) { pwd = sys_getpwuid(getuid()); if (pwd) { - user_name = xstrdup(pwd->pw_name); + user_name = strdup_x(pwd->pw_name); } else { fprintf(stderr,"you don't exist - go away\n"); exit(1); @@ -966,6 +975,8 @@ int main(int argc, char **argv) { static pstring servicesf = CONFIGFILE; + AllowDebugChange = False; + #if defined(HAVE_SET_AUTH_PARAMETERS) set_auth_parameters(argc, argv); #endif /* HAVE_SET_AUTH_PARAMETERS */ diff --git a/source/utils/smbw_sample.c b/source/utils/smbw_sample.c index db92af95108..cf94743411d 100644 --- a/source/utils/smbw_sample.c +++ b/source/utils/smbw_sample.c @@ -4,22 +4,25 @@ #include <dirent.h> #include <sys/stat.h> +extern DIR *smbw_opendir(const char *fname); +extern struct dirent *smbw_readdir(DIR *dirp); + static void usage(void) { - printf(" -smbw_sample - a sample program that uses smbw - -smbw_sample <options> path - - options: - -W workgroup - -l logfile - -P prefix - -d debuglevel - -U username%%password - -R resolve order - -note that path must start with /smb/ + printf("\n \ +smbw_sample - a sample program that uses smbw\n \ +\n \ +smbw_sample <options> path\n \ +\n \ + options:\n \ + -W workgroup\n \ + -l logfile\n \ + -P prefix\n \ + -d debuglevel\n \ + -U username%%password\n \ + -R resolve order\n \ +\n \ +note that path must start with /smb/\n \ "); } diff --git a/source/utils/status.c b/source/utils/status.c index 28726d40f0f..01d80ad53dd 100644 --- a/source/utils/status.c +++ b/source/utils/status.c @@ -44,8 +44,8 @@ struct session_record{ struct session_record *next; } *srecs; -extern int DEBUGLEVEL; extern FILE *dbf; +extern BOOL AllowDebugChange; static pstring Ucrit_username = ""; /* added by OH */ static pid_t Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */ @@ -535,6 +535,8 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st } if (ptr==NULL) { ptr=(struct session_record *) malloc(sizeof(struct session_record)); + if (!ptr) + return 0; ptr->uid=crec.uid; ptr->pid=crec.pid; ptr->start=crec.start; @@ -579,6 +581,7 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st charset_initialise(); + AllowDebugChange = False; DEBUGLEVEL = 0; dbf = stderr; diff --git a/source/utils/testparm.c b/source/utils/testparm.c index 10292b3033a..9502ec9669d 100644 --- a/source/utils/testparm.c +++ b/source/utils/testparm.c @@ -35,9 +35,10 @@ #include "includes.h" #include "smb.h" +extern BOOL AllowDebugChange; + /* these live in util.c */ extern FILE *dbf; -extern int DEBUGLEVEL; /*********************************************** Here we do a set of 'hard coded' checks for bad @@ -219,6 +220,7 @@ int main(int argc, char *argv[]) dbf = stdout; DEBUGLEVEL = 2; + AllowDebugChange = False; printf("Load smb config files from %s\n",configfile); diff --git a/source/utils/testprns.c b/source/utils/testprns.c index c03fa0436a6..0ba5403c30a 100644 --- a/source/utils/testprns.c +++ b/source/utils/testprns.c @@ -36,7 +36,6 @@ /* these live in util.c */ extern FILE *dbf; -extern int DEBUGLEVEL; int main(int argc, char *argv[]) { diff --git a/source/utils/torture.c b/source/utils/torture.c index 1277cd2ee32..185cd93d164 100644 --- a/source/utils/torture.c +++ b/source/utils/torture.c @@ -215,7 +215,8 @@ static BOOL check_error(struct cli_state *c, { uint8 class; uint32 num; - (void)cli_error(c, &class, &num, NULL); + + (void)cli_dos_error(c, &class, &num); if ((eclass != class || ecode != num) && num != (nterr&0xFFFFFF)) { printf("unexpected error code class=%d code=%d\n", @@ -3645,8 +3646,8 @@ int cli_setfileinfo_test(struct cli_state *cli, int fnum, int level, char *data, return False; } - if (rdata) free(rdata); - if (rparam) free(rparam); + SAFE_FREE(rdata); + SAFE_FREE(rparam); return True; } @@ -4305,7 +4306,7 @@ static BOOL run_opentest(int dummy) /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */ fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL); - cli_error( &cli1, &eclass, &errnum, NULL); + cli_dos_error( &cli1, &eclass, &errnum); if (eclass != ERRDOS || errnum != ERRnoaccess) { printf("wrong error code (%x,%x) = %s\n", (unsigned int)eclass, @@ -4333,7 +4334,7 @@ static BOOL run_opentest(int dummy) /* This will fail - but the error should be ERRshare. */ fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL); - cli_error( &cli1, &eclass, &errnum, NULL); + cli_dos_error( &cli1, &eclass, &errnum); if (eclass != ERRDOS || errnum != ERRbadshare) { printf("wrong error code (%x,%x) = %s\n", (unsigned int)eclass, |