#include "includes.h" /* ** */ char usage [] ="Usage:\n\ $netpwd :==$netpwd\n\ $netpwd DC username oldpassword [newpassword]\n\ \n\ Example of password checking:\n\ $netpwd starlet ZyzMan 123456\n\ \n\ Example of password changing:\n\ $netpwd starlet ZyzMan 123456 my$new_pwd\n"; int main (int argc, char **argv) { char *rem_host,*user,*pass,*new_pass; char loc_host [] = "DTV3"; struct cli_state cli; struct in_addr ip; struct hostent * hp; if ( argc < 4 ) { puts(usage); return 1; } rem_host = argv[1]; user = argv[2]; pass = argv[3]; new_pass = argv[4]; if ( !(hp = gethostbyname(rem_host)) ) { perror("gethostbyname"); return 2; } memset(&cli,0, sizeof(struct cli_state)); memcpy(&ip,hp->h_addr,sizeof(ip)); if ( !cli_initialise(&cli) || !cli_connect(&cli, rem_host, &ip) ) { printf("unable to connect to SMB server on machine %s. Error was : %s.\n", rem_host, cli_errstr(&cli) ); return 2; } if ( !cli_session_request(&cli, rem_host, 0x20, loc_host) ) { printf("machine %s rejected the session setup. Error was : %s.\n", rem_host, cli_errstr(&cli) ); cli_shutdown(&cli); return 2; } cli.protocol = PROTOCOL_NT1; if ( !cli_negprot(&cli) ) { printf("machine %s rejected the negotiate protocol. Error was : %s.\n", rem_host,cli_errstr(&cli) ); cli_shutdown(&cli); return 2; } if ( !cli_session_setup(&cli, user, pass, sizeof(pass)-1,"", 0, "") ) { printf("machine %s rejected the session setup. Error was : %s.\n", rem_host,cli_errstr(&cli) ); cli_shutdown(&cli); return 2; } if ( new_pass ) { if ( !cli_send_tconX(&cli, "IPC$", "IPC", "", 1) ) { printf("machine %s rejected the tconX on the IPC$ share. Error was : %s.\n", rem_host,cli_errstr(&cli) ); cli_shutdown(&cli); return 2; } if ( !cli_oem_change_password(&cli, user, new_pass, pass) ) { printf("machine %s rejected the password change: Error was : %s.\n", rem_host, cli_errstr(&cli)); cli_shutdown(&cli); return 2; } } cli_shutdown(&cli); printf("Password was checked/changed\n"); return TRUE; }