From a8346f4e83c2d093370ee608fe6aa4ec03147244 Mon Sep 17 00:00:00 2001 From: Steve French Date: Sat, 3 Nov 2001 21:11:28 +0000 Subject: Adding support for net password, net service, net user info, fixing net helps (This used to be commit a1f3930637a6ccadd4dba90dcd713cf1e4b5a536) --- source3/utils/net.c | 317 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 258 insertions(+), 59 deletions(-) (limited to 'source3') diff --git a/source3/utils/net.c b/source3/utils/net.c index 611f79e7f3..dcbc58017d 100644 --- a/source3/utils/net.c +++ b/source3/utils/net.c @@ -61,7 +61,10 @@ typedef struct _functable { #define GROUPF 8 #define VALIDATEF 9 #define GROUPMEMBERF 10 -#define HELPF 11 +#define ADMINF 11 +#define SERVICEF 12 +#define PASSWORDF 13 +#define HELPF 14 const functable net_func[] = { { FILEF, "FILE"}, @@ -74,6 +77,9 @@ const functable net_func[] = { { GROUPF, "GROUP"}, { VALIDATEF, "VALIDATE"}, { GROUPMEMBERF, "GROUPMEMBER"}, + { ADMINF, "ADMIN"}, + { SERVICEF, "SERVICE"}, + { PASSWORDF, "PASSWORD"}, { HELPF, "HELP"} }; @@ -90,7 +96,8 @@ const functable net_subfunc[] = { { ADD_SF, "ADD" }, { ADD_SF, "CREATE" }, { DELETE_SF, "CLOSE" }, - { DELETE_SF, "DELETE" } + { DELETE_SF, "DELETE" }, + { INFO_SF, "INFO"} }; const char share_type[][6] = { @@ -110,6 +117,7 @@ const char share_type[][6] = { " net file \tto list open files on a server \n"\ " net group \tto list user groups \n"\ " net groupmember to list users in a group \n"\ + " net password to change the password of a user\n"\ " net printq \tto list the print queues on a server\n"\ " net server \tto list servers in a domain\n"\ " net session \tto list clients with open sessions to a server\n"\ @@ -232,7 +240,9 @@ const char share_type[][6] = { "\nnet user [misc. options] [targets]\n\tEnumerate users\n"\ "\nnet user DELETE [misc. options] [targets]"\ "\n\tDelete specified user\n"\ - "\nnet user ADD [-M user flags] [misc. options] [targets]"\ + "\nnet user INFO [misc. options] [targets]"\ + "\n\tList the domain groups of the specified user\n"\ + "\nnet user ADD [-F user flags] [misc. options] [targets]"\ "\n\tAdd specified user\n" #define USER_ENUM_DISPLAY \ @@ -256,6 +266,24 @@ const char share_type[][6] = { "\nnet groupmember ADD [misc. options] [targets]"\ "\n\t Add specified user to specified group\n" + +#define NET_ADMIN_USAGE \ + "\nnet admin [cmd arguments [environment]] [misc_options] [targets]\n"\ + "\texecutes a remote command on an os/2 target server\n" + +#define NET_PASSWORD_USAGE \ + "\nnet password [misc_options] [targets]\n"\ + "\tchanges the password for the specified user on a remote server\n" + +#define NET_SERVICE_USAGE \ + "\nnet service [misc. options] [targets] \n"\ + "\tenumerates all running service daemons on target server\n"\ + "\nnet service ADD [service startup arguments] [misc. options] [targets]"\ + "\n\tStart named service on remote server\n"\ + "\nnet service DELETE [misc. options] [targets]\n"\ + "\n\tStop named service on remote server\n" + + #define NET_VALIDATE_USAGE \ "\nnet validate [password]\n"\ "\tValidate user and password to check whether they can access target server or domain\n" @@ -301,6 +329,7 @@ const char share_type[][6] = { #define COMMENT_STR "Comment " #define USER_STR "User name " #define GROUP_STR "Group name " +#define SERVICE_STR "Service name" #define HOMED_STR "Home directory " #define LOGONS_STR "Logon script " /************************************************************************************/ @@ -958,6 +987,11 @@ void long_user_fn(const char *user_name, const char *comment, const char * home_ printf("%-21.21s %-47.47s %-35.35s %35.35s\n", user_name, comment, home_dir, logon_script); } +void group_member_fn(const char *user_name, void *state) +{ + printf("%-21.21s\n", user_name); +} + int net_user(int subfunct, char * username, char * comment, int flags) { struct in_addr target_ip; @@ -991,7 +1025,7 @@ int net_user(int subfunct, char * username, char * comment, int flags) return cli_RNetUserEnum(cli, long_user_fn, NULL); } else - return cli_RNetUserEnum(cli, user_fn, NULL); + return cli_RNetUserEnum(cli, user_fn, NULL); } else if (subfunct == ADD_SF) { if (username == NULL) { printf(ERRMSG_USERNAME_MISSING); @@ -1011,7 +1045,17 @@ int net_user(int subfunct, char * username, char * comment, int flags) return cli_NetUserAdd(cli, &userinfo); } - } else + } else if (subfunct == INFO_SF) { + if (username == NULL) { + printf(ERRMSG_USERNAME_MISSING); + return -1; + } else { + /* RAP_USER_INFO_1 userinfo; + cli_NetUserInfo (cli, &userinfo); */ /* BB need to add call to get user info level 3 or 4 */ + return cli_NetUserGetGroups(cli, username, group_member_fn, NULL ); + } + } + else printf(ERRMSG_NOT_IMPLEMENTED); return -1; @@ -1120,11 +1164,6 @@ void groupmember_usage(void) printf(CONF_USAGE); } -void group_member_fn(const char *user_name, void *state) -{ - printf("%-21.21s\n", user_name); -} - int net_groupmember(int subfunct, char * groupname, char * username) { @@ -1193,6 +1232,130 @@ int net_validate(char * username) return 0; } +void service_usage(void) +{ + printf(NET_SERVICE_USAGE); /* command syntax */ + + printf(TARGET_USAGE, GLBL_LCL_MASTER); /* target options */ + printf(SERVER_USAGE); + printf(IPADDRESS_USAGE); + + printf(MISC_OPT_USAGE); /* misc options */ + printf(PORT_USAGE); + printf(MYWORKGROUP_USAGE); + printf(DEBUG_USAGE); + printf(MYNAME_USAGE); + printf(USER_USAGE); + printf(CONF_USAGE); +} + + +int net_service(int subfunct, char * servicename, char * srvc_args) +{ +struct in_addr target_ip; + +if((have_ip == 0) && (host[0] == 0)) { + if (!resolve_name("localhost", &target_ip, 0x20)) { + DEBUG(1,("No remote server specified, unable to resolve connection to localhost via name lookup")); + return -1; + } else { + have_ip = True; + dest_ip = target_ip; + } +} +if(host[0] == 0) + strncpy(host, inet_ntoa(dest_ip),16); +cli = connect_to_ipc(host); +if(!cli) { + printf(ERRMSG_NOCONN_TARGET_SRVR); + return -2; +} + +if (subfunct == LIST_SF) { + if(long_list_entries) { + printf("%-15.15s %-50.50s\n", SERVICE_STR, COMMENT_STR); + printf("-----------------------------\n"); + return cli_RNetServiceEnum(cli, long_group_fn, NULL); + } + else + return cli_RNetServiceEnum(cli, group_fn, NULL); +} else + printf(ERRMSG_NOT_IMPLEMENTED); +return -1; + +} + +int net_password(char * username, char * old_password, char * new_password) +{ + struct in_addr target_ip; + + if((have_ip == 0) && (host[0] == 0)) { + if (!resolve_name("localhost", &target_ip, 0x20)) { + DEBUG(1,("No remote server specified, unable to resolve connection to localhost via name lookup")); + return -1; + + } else { + have_ip = True; + dest_ip = target_ip; + } + } + if(host[0] == 0) + strncpy(host, inet_ntoa(dest_ip),16); + cli = connect_to_ipc(host); + if(!cli) { + printf(ERRMSG_NOCONN_TARGET_SRVR); + return -2; + } + + /* BB Add check for password lengths? */ + return cli_oem_change_password(cli, username, new_password, old_password); +} + +void password_usage(void) +{ + printf(NET_PASSWORD_USAGE); /* command syntax */ + + printf(TARGET_USAGE, GLBL_LCL_MASTER); /* target options */ + printf(SERVER_USAGE); + printf(IPADDRESS_USAGE); + printf(WORKGROUP_USAGE); + + printf(MISC_OPT_USAGE); /* misc options */ + printf(PORT_USAGE); + printf(MYWORKGROUP_USAGE); + printf(DEBUG_USAGE); + printf(MYNAME_USAGE); + printf(USER_USAGE); + printf(CONF_USAGE); +} + + +void admin_usage(void) +{ + printf(NET_ADMIN_USAGE); /* command syntax */ + + printf(TARGET_USAGE, GLBL_LCL_MASTER); /* target options */ + printf(SERVER_USAGE); + printf(IPADDRESS_USAGE); + printf(WORKGROUP_USAGE); + + printf(MISC_OPT_USAGE); /* misc options */ + printf(PORT_USAGE); + printf(MYWORKGROUP_USAGE); + printf(DEBUG_USAGE); + printf(MYNAME_USAGE); + printf(USER_USAGE); + printf(CONF_USAGE); +} + + +int net_admin(char * command, char * cmd_args, char * environment) +{ + printf(ERRMSG_NOT_IMPLEMENTED); + return 0; + +} + /**************************************************************************** main program ****************************************************************************/ @@ -1277,17 +1440,18 @@ int main(int argc,char *argv[]) } } - lp_load(servicesf,True,False,False); + lp_load(servicesf,True,False,False); argv_new = (char **)poptGetArgs(pc); + argc_new = argc; for (i=0; i 3) - rc = net_user(subfunc,argv_new[3], comment, flagsarg); + rc = net_user(subfunc,argv_new[3], comment, flagsarg); break; case GROUPF: if (argc_new == 2) - rc = net_group(subfunc, NULL, NULL); + rc = net_group(subfunc, NULL, NULL); else if(argc_new == 3) - rc = net_group(subfunc,NULL, NULL); + rc = net_group(subfunc,NULL, NULL); else if(argc_new > 3) - rc = net_group(subfunc,argv_new[3], comment); + rc = net_group(subfunc,argv_new[3], comment); break; case GROUPMEMBERF: if (argc_new == 4) - rc = net_groupmember(subfunc, argv_new[3], NULL); + rc = net_groupmember(subfunc, argv_new[3], NULL); else if (argc_new == 5) - rc = net_groupmember(subfunc, argv_new[3], argv_new[4]); + rc = net_groupmember(subfunc, argv_new[3], argv_new[4]); else { - groupmember_usage(); - rc = -1; + groupmember_usage(); + rc = -1; } break; case VALIDATEF: rc = net_validate(global_user_name); break; + case SERVICEF: + rc = net_service(subfunc, argv_new[3], argv_new[4]); + break; + case ADMINF: + if(argc_new < 3) + { + admin_usage(); + rc = -1; + } + else if (argc_new == 3) { + rc = net_admin(argv_new[2], NULL, NULL); + } else if (argc_new == 4) { + rc = net_admin(argv_new[2], argv_new[3], NULL); + } else { + rc = net_admin(argv_new[2], argv_new[3], argv_new[4]); + } + break; + case PASSWORDF: + if(argc_new != 5) + { + password_usage(); + rc = -1; + } else { + rc = net_password(argv_new[2], argv_new[3], argv_new[4]); + } + break; case PRINTQF: if (argc_new <= 3) - rc = net_printq(subfunc, NULL, jobid); + rc = net_printq(subfunc, NULL, jobid); else - rc = net_printq(subfunc, argv_new[3], jobid); + rc = net_printq(subfunc, argv_new[3], jobid); break; default: usage(); -- cgit