diff options
author | Jeremy Allison <jra@samba.org> | 1998-03-26 19:11:31 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 1998-03-26 19:11:31 +0000 |
commit | 6cd35ce945a0ff3e9c787ec12ef81161a6aecbe4 (patch) | |
tree | 88f4692aceacfc3019c097c05a22bed8ec2c97f4 /source3/utils | |
parent | 039761b05c2a1708ce6b247a058cc3d55f652a37 (diff) | |
download | samba-6cd35ce945a0ff3e9c787ec12ef81161a6aecbe4.tar.gz samba-6cd35ce945a0ff3e9c787ec12ef81161a6aecbe4.tar.bz2 samba-6cd35ce945a0ff3e9c787ec12ef81161a6aecbe4.zip |
client.c: Fixed problem where debug level on command line was overridden by smb.conf.
smbpasswd.c: Removed bugs I put in yesterday (thanks Luke :-) and added error
message reporting for remote password changing.
Jeremy.
(This used to be commit 6a3394a285a250d1029cdd545dd0bf832284555a)
Diffstat (limited to 'source3/utils')
-rw-r--r-- | source3/utils/smbpasswd.c | 92 |
1 files changed, 58 insertions, 34 deletions
diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index f733f99be2..b03385769c 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -38,6 +38,39 @@ struct }; /****************************************************** + Return an error message for a remote password change. +*******************************************************/ + +char *get_error_message(struct cli_state *cli) +{ + static fstring error_message; + int errclass; + int errnum; + int i; + + /* + * Errors are of two kinds - smb errors, + * dealt with by cli_errstr, and rap + * errors, whose error code is in cli.error. + */ + + cli_error(cli, &errclass, &errnum); + if(errclass != 0) + return cli_errstr(cli); + + sprintf(error_message, "code %d", cli->error); + + for(i = 0; pw_change_errmap[i].message != NULL; i++) { + if (pw_change_errmap[i].err == cli->error) { + fstrcpy( error_message, pw_change_errmap[i].message); + break; + } + } + + return error_message; +} + +/****************************************************** Convert a hex password. *******************************************************/ @@ -387,10 +420,10 @@ int get_new_machine_uid(void) static void usage(char *name, BOOL is_root) { if(is_root) - fprintf(stderr, "Usage is : %s [-a] [-d] [-m] [-w] [-n] [username] [password]\n\ -%s: [-R <name resolve order>] [-r machine] [username] [password]\n%s: [-h]\n", name, name, name); + fprintf(stderr, "Usage is : %s [-D DEBUGLEVEL] [-a] [-d] [-m] [-n] [username] [password]\n\ +%s: [-R <name resolve order>] [-D DEBUGLEVEL] [-r machine] [username] [password]\n%s: [-h]\n", name, name, name); else - fprintf(stderr, "Usage is : %s [-h] [-r machine] [password]\n", name); + fprintf(stderr, "Usage is : %s [-h] [-D DEBUGLEVEL] [-r machine] [password]\n", name); exit(1); } @@ -402,6 +435,7 @@ int main(int argc, char **argv) { extern char *optarg; extern int optind; + extern int DEBUGLEVEL; char *prog_name; int real_uid; struct passwd *pwd; @@ -431,7 +465,6 @@ int main(int argc, char **argv) BOOL add_user = False; BOOL got_new_pass = False; BOOL machine_account = False; - BOOL server_machine_account = False; BOOL disable_user = False; BOOL set_no_password = False; pstring servicesf = CONFIGFILE; @@ -467,7 +500,7 @@ int main(int argc, char **argv) is_root = (real_uid == 0); - while ((ch = getopt(argc, argv, "adhmnr:R:w")) != EOF) { + while ((ch = getopt(argc, argv, "adhmnr:R:D:")) != EOF) { switch(ch) { case 'a': if(is_root) @@ -483,6 +516,9 @@ int main(int argc, char **argv) } else usage(prog_name, is_root); break; + case 'D': + DEBUGLEVEL = atoi(optarg); + break; case 'n': if(is_root) { set_no_password = True; @@ -500,10 +536,8 @@ int main(int argc, char **argv) } else usage(prog_name, is_root); case 'm': - case 'w': if(is_root) { machine_account = True; - server_machine_account = (ch == 'm'); } else usage(prog_name, is_root); break; @@ -651,16 +685,18 @@ int main(int argc, char **argv) prog_name, remote_machine ); exit(1); } - + + cli.error = 0; + if (!cli_initialise(&cli) || !cli_connect(&cli, remote_machine, &ip)) { - fprintf(stderr, "%s: unable to connect to SMB server on machine %s.\n", - prog_name, remote_machine ); + fprintf(stderr, "%s: unable to connect to SMB server on machine %s. Error was : %s.\n", + prog_name, remote_machine, get_error_message(&cli) ); exit(1); } if (!cli_session_request(&cli, remote_machine, 0x20, myname)) { - fprintf(stderr, "%s: machine %s rejected the session setup.\n", - prog_name, remote_machine ); + fprintf(stderr, "%s: machine %s rejected the session setup. Error was : %s.\n", + prog_name, remote_machine, get_error_message(&cli) ); cli_shutdown(&cli); exit(1); } @@ -668,40 +704,30 @@ int main(int argc, char **argv) cli.protocol = PROTOCOL_NT1; if (!cli_negprot(&cli)) { - fprintf(stderr, "%s: machine %s rejected the negotiate protocol.\n", - prog_name, remote_machine ); + fprintf(stderr, "%s: machine %s rejected the negotiate protocol. Error was : %s.\n", + prog_name, remote_machine, get_error_message(&cli) ); cli_shutdown(&cli); exit(1); } if (!cli_session_setup(&cli, user_name, old_passwd, strlen(old_passwd), "", 0, "")) { - fprintf(stderr, "%s: machine %s rejected the session setup.\n", - prog_name, remote_machine ); + fprintf(stderr, "%s: machine %s rejected the session setup. Error was : %s.\n", + prog_name, remote_machine, get_error_message(&cli) ); cli_shutdown(&cli); exit(1); } if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) { - fprintf(stderr, "%s: machine %s rejected the tconX on the IPC$ share.\n", - prog_name, remote_machine ); + fprintf(stderr, "%s: machine %s rejected the tconX on the IPC$ share. Error was : %s.\n", + prog_name, remote_machine, get_error_message(&cli) ); cli_shutdown(&cli); exit(1); } if(!cli_oem_change_password(&cli, user_name, new_passwd, old_passwd)) { - fstring error_message; - - sprintf(error_message, " with code %d", cli.error); - - for(i = 0; pw_change_errmap[i].message != NULL; i++) { - if (pw_change_errmap[i].err == cli.error) { - fstrcpy( error_message, pw_change_errmap[i].message); - break; - } - } - fprintf(stderr, "%s: machine %s rejected the password change: %s.\n", - prog_name, remote_machine, error_message ); + fprintf(stderr, "%s: machine %s rejected the password change: Error was : %s.\n", + prog_name, remote_machine, get_error_message(&cli) ); cli_shutdown(&cli); exit(1); } @@ -735,8 +761,7 @@ int main(int argc, char **argv) pwd = &machine_account_pwd; pwd->pw_name = user_name; - sprintf(machine_dir_name, "%s machine account for %s", - server_machine_account ? "Server" : "Workstation", user_name); + sprintf(machine_dir_name, "Workstation machine account for %s", user_name); pwd->pw_gecos = ""; pwd->pw_dir = machine_dir_name; pwd->pw_shell = ""; @@ -817,8 +842,7 @@ int main(int argc, char **argv) int new_entry_length; char *new_entry; long offpos; - uint16 acct_ctrl = (machine_account ? - ( server_machine_account ? ACB_SVRTRUST : ACB_WSTRUST) : ACB_NORMAL); + uint16 acct_ctrl = (machine_account ? ACB_WSTRUST : ACB_NORMAL); /* The add user write needs to be atomic - so get the fd from the fp and do a raw write() call. |