r22973: Apparently, 3.0.25 broke smb4k badly ;-)
[Samba/vl.git] / source3 / utils / net_rap.c
blob54e59673b80f10b2c8ec5120deb551f02a3f0a1d
1 /*
2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
4 Copyright (C) 2001 Steve French (sfrench@us.ibm.com)
5 Copyright (C) 2001 Jim McDonough (jmcd@us.ibm.com)
6 Copyright (C) 2001 Andrew Tridgell (tridge@samba.org)
7 Copyright (C) 2001 Andrew Bartlett (abartlet@samba.org)
9 Originally written by Steve and Jim. Largely rewritten by tridge in
10 November 2001.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #include "includes.h"
27 #include "utils/net.h"
29 /* The following messages were for error checking that is not properly
30 reported at the moment. Which should be reinstated? */
31 #define ERRMSG_TARGET_WG_NOT_VALID "\nTarget workgroup option not valid "\
32 "except on net rap server command, ignored"
33 #define ERRMSG_INVALID_HELP_OPTION "\nInvalid help option\n"
35 #define ERRMSG_BOTH_SERVER_IPADDRESS "\nTarget server and IP address both "\
36 "specified. Do not set both at the same time. The target IP address was used\n"
38 const char *share_type[] = {
39 "Disk",
40 "Print",
41 "Dev",
42 "IPC"
45 static int errmsg_not_implemented(void)
47 d_printf("\nNot implemented\n");
48 return 0;
51 int net_rap_file_usage(int argc, const char **argv)
53 return net_help_file(argc, argv);
56 /***************************************************************************
57 list info on an open file
58 ***************************************************************************/
59 static void file_fn(const char * pPath, const char * pUser, uint16 perms,
60 uint16 locks, uint32 id)
62 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
63 id, pUser, perms, locks, pPath);
66 static void one_file_fn(const char *pPath, const char *pUser, uint16 perms,
67 uint16 locks, uint32 id)
69 d_printf("File ID %d\n"\
70 "User name %s\n"\
71 "Locks 0x%-4.2x\n"\
72 "Path %s\n"\
73 "Permissions 0x%x\n",
74 id, pUser, locks, pPath, perms);
78 static int rap_file_close(int argc, const char **argv)
80 struct cli_state *cli;
81 int ret;
82 if (argc == 0) {
83 d_printf("\nMissing fileid of file to close\n\n");
84 return net_rap_file_usage(argc, argv);
87 if (!(cli = net_make_ipc_connection(0)))
88 return -1;
90 ret = cli_NetFileClose(cli, atoi(argv[0]));
91 cli_shutdown(cli);
92 return ret;
95 static int rap_file_info(int argc, const char **argv)
97 struct cli_state *cli;
98 int ret;
99 if (argc == 0)
100 return net_rap_file_usage(argc, argv);
102 if (!(cli = net_make_ipc_connection(0)))
103 return -1;
105 ret = cli_NetFileGetInfo(cli, atoi(argv[0]), one_file_fn);
106 cli_shutdown(cli);
107 return ret;
110 static int rap_file_user(int argc, const char **argv)
112 if (argc == 0)
113 return net_rap_file_usage(argc, argv);
115 d_fprintf(stderr, "net rap file user not implemented yet\n");
116 return -1;
119 int net_rap_file(int argc, const char **argv)
121 struct functable func[] = {
122 {"CLOSE", rap_file_close},
123 {"USER", rap_file_user},
124 {"INFO", rap_file_info},
125 {NULL, NULL}
128 if (argc == 0) {
129 struct cli_state *cli;
130 int ret;
132 if (!(cli = net_make_ipc_connection(0)))
133 return -1;
135 /* list open files */
136 d_printf(
137 "\nEnumerating open files on remote server:\n\n"\
138 "\nFileId Opened by Perms Locks Path \n"\
139 "------ --------- ----- ----- ---- \n");
140 ret = cli_NetFileEnum(cli, NULL, NULL, file_fn);
141 cli_shutdown(cli);
142 return ret;
145 return net_run_function(argc, argv, func, net_rap_file_usage);
148 int net_rap_share_usage(int argc, const char **argv)
150 return net_help_share(argc, argv);
153 static void long_share_fn(const char *share_name, uint32 type,
154 const char *comment, void *state)
156 d_printf("%-12s %-8.8s %-50s\n",
157 share_name, share_type[type], comment);
160 static void share_fn(const char *share_name, uint32 type,
161 const char *comment, void *state)
163 d_printf("%s\n", share_name);
166 static int rap_share_delete(int argc, const char **argv)
168 struct cli_state *cli;
169 int ret;
171 if (argc == 0) {
172 d_printf("\n\nShare name not specified\n");
173 return net_rap_share_usage(argc, argv);
176 if (!(cli = net_make_ipc_connection(0)))
177 return -1;
179 ret = cli_NetShareDelete(cli, argv[0]);
180 cli_shutdown(cli);
181 return ret;
184 static int rap_share_add(int argc, const char **argv)
186 struct cli_state *cli;
187 int ret;
189 RAP_SHARE_INFO_2 sinfo;
190 char *p;
191 char *sharename;
193 if (argc == 0) {
194 d_printf("\n\nShare name not specified\n");
195 return net_rap_share_usage(argc, argv);
198 if (!(cli = net_make_ipc_connection(0)))
199 return -1;
201 sharename = SMB_STRDUP(argv[0]);
202 p = strchr(sharename, '=');
203 if (p == NULL) {
204 d_printf("Server path not specified\n");
205 return net_rap_share_usage(argc, argv);
207 *p = 0;
208 strlcpy(sinfo.share_name, sharename, sizeof(sinfo.share_name));
209 sinfo.reserved1 = '\0';
210 sinfo.share_type = 0;
211 sinfo.comment = smb_xstrdup(opt_comment);
212 sinfo.perms = 0;
213 sinfo.maximum_users = opt_maxusers;
214 sinfo.active_users = 0;
215 sinfo.path = p+1;
216 memset(sinfo.password, '\0', sizeof(sinfo.password));
217 sinfo.reserved2 = '\0';
219 ret = cli_NetShareAdd(cli, &sinfo);
220 cli_shutdown(cli);
221 return ret;
225 int net_rap_share(int argc, const char **argv)
227 struct functable func[] = {
228 {"DELETE", rap_share_delete},
229 {"CLOSE", rap_share_delete},
230 {"ADD", rap_share_add},
231 {NULL, NULL}
234 if (argc == 0) {
235 struct cli_state *cli;
236 int ret;
238 if (!(cli = net_make_ipc_connection(0)))
239 return -1;
241 if (opt_long_list_entries) {
242 d_printf(
243 "\nEnumerating shared resources (exports) on remote server:\n\n"\
244 "\nShare name Type Description\n"\
245 "---------- ---- -----------\n");
246 ret = cli_RNetShareEnum(cli, long_share_fn, NULL);
247 } else {
248 ret = cli_RNetShareEnum(cli, share_fn, NULL);
250 cli_shutdown(cli);
251 return ret;
254 return net_run_function(argc, argv, func, net_rap_share_usage);
258 int net_rap_session_usage(int argc, const char **argv)
260 d_printf(
261 "\nnet rap session [misc. options] [targets]"\
262 "\n\tenumerates all active SMB/CIFS sessions on target server\n");
263 d_printf(
264 "\nnet rap session DELETE <client_name> [misc. options] [targets] \n"\
265 "\tor"\
266 "\nnet rap session CLOSE <client_name> [misc. options] [targets]"\
267 "\n\tDeletes (closes) a session from specified client to server\n");
268 d_printf(
269 "\nnet rap session INFO <client_name>"\
270 "\n\tEnumerates all open files in specified session\n");
272 net_common_flags_usage(argc, argv);
273 return -1;
276 static void list_sessions_func(char *wsname, char *username, uint16 conns,
277 uint16 opens, uint16 users, uint32 sess_time,
278 uint32 idle_time, uint32 user_flags, char *clitype)
280 int hrs = idle_time / 3600;
281 int min = (idle_time / 60) % 60;
282 int sec = idle_time % 60;
284 d_printf("\\\\%-18.18s %-20.20s %-18.18s %5d %2.2d:%2.2d:%2.2d\n",
285 wsname, username, clitype, opens, hrs, min, sec);
288 static void display_session_func(const char *wsname, const char *username,
289 uint16 conns, uint16 opens, uint16 users,
290 uint32 sess_time, uint32 idle_time,
291 uint32 user_flags, const char *clitype)
293 int ihrs = idle_time / 3600;
294 int imin = (idle_time / 60) % 60;
295 int isec = idle_time % 60;
296 int shrs = sess_time / 3600;
297 int smin = (sess_time / 60) % 60;
298 int ssec = sess_time % 60;
299 d_printf("User name %-20.20s\n"\
300 "Computer %-20.20s\n"\
301 "Guest logon %-20.20s\n"\
302 "Client Type %-40.40s\n"\
303 "Sess time %2.2d:%2.2d:%2.2d\n"\
304 "Idle time %2.2d:%2.2d:%2.2d\n",
305 username, wsname,
306 (user_flags&0x0)?"yes":"no", clitype,
307 shrs, smin, ssec, ihrs, imin, isec);
310 static void display_conns_func(uint16 conn_id, uint16 conn_type, uint16 opens,
311 uint16 users, uint32 conn_time,
312 const char *username, const char *netname)
314 d_printf("%-14.14s %-8.8s %5d\n",
315 netname, share_type[conn_type], opens);
318 static int rap_session_info(int argc, const char **argv)
320 const char *sessname;
321 struct cli_state *cli;
322 int ret;
324 if (!(cli = net_make_ipc_connection(0)))
325 return -1;
327 if (argc == 0)
328 return net_rap_session_usage(argc, argv);
330 sessname = argv[0];
332 ret = cli_NetSessionGetInfo(cli, sessname, display_session_func);
333 if (ret < 0) {
334 cli_shutdown(cli);
335 return ret;
338 d_printf("Share name Type # Opens\n-------------------------"\
339 "-----------------------------------------------------\n");
340 ret = cli_NetConnectionEnum(cli, sessname, display_conns_func);
341 cli_shutdown(cli);
342 return ret;
345 static int rap_session_delete(int argc, const char **argv)
347 struct cli_state *cli;
348 int ret;
350 if (!(cli = net_make_ipc_connection(0)))
351 return -1;
353 if (argc == 0)
354 return net_rap_session_usage(argc, argv);
356 ret = cli_NetSessionDel(cli, argv[0]);
357 cli_shutdown(cli);
358 return ret;
361 int net_rap_session(int argc, const char **argv)
363 struct functable func[] = {
364 {"INFO", rap_session_info},
365 {"DELETE", rap_session_delete},
366 {"CLOSE", rap_session_delete},
367 {NULL, NULL}
370 if (argc == 0) {
371 struct cli_state *cli;
372 int ret;
374 if (!(cli = net_make_ipc_connection(0)))
375 return -1;
377 d_printf("Computer User name "\
378 "Client Type Opens Idle time\n"\
379 "------------------------------------------"\
380 "------------------------------------\n");
381 ret = cli_NetSessionEnum(cli, list_sessions_func);
383 cli_shutdown(cli);
384 return ret;
387 return net_run_function(argc, argv, func, net_rap_session_usage);
390 /****************************************************************************
391 list a server name
392 ****************************************************************************/
393 static void display_server_func(const char *name, uint32 m,
394 const char *comment, void * reserved)
396 d_printf("\t%-16.16s %s\n", name, comment);
400 int net_rap_server_usage(int argc, const char **argv)
402 d_printf("net rap server [misc. options] [target]\n\t"\
403 "lists the servers in the specified domain or workgroup.\n");
404 d_printf("\n\tIf domain is not specified, it uses the current"\
405 " domain or workgroup as\n\tthe default.\n");
407 net_common_flags_usage(argc, argv);
408 return -1;
411 static int net_rap_server_name(int argc, const char *argv[])
413 struct cli_state *cli;
414 char *name;
416 if (!(cli = net_make_ipc_connection(0)))
417 return -1;
419 if (!cli_get_server_name(NULL, cli, &name)) {
420 d_fprintf(stderr, "cli_get_server_name failed\n");
421 cli_shutdown(cli);
422 return -1;
425 d_printf("Server name = %s\n", name);
427 TALLOC_FREE(name);
428 cli_shutdown(cli);
429 return 0;
432 int net_rap_server(int argc, const char **argv)
434 struct cli_state *cli;
435 int ret;
437 if (argc > 0) {
438 if (strequal(argv[0], "name")) {
439 return net_rap_server_name(argc, argv);
441 /* smb4k uses 'net [rap|rpc] server domain' to query servers in a domain */
442 /* Fall through for 'domain', any other forms will cause to show usage message */
443 if (!strequal(argv[0], "domain")) {
444 return net_rap_server_usage(argc-1, argv+1);
448 if (!(cli = net_make_ipc_connection(0)))
449 return -1;
451 d_printf("\nEnumerating servers in this domain or workgroup: \n\n"\
452 "\tServer name Server description\n"\
453 "\t------------- ----------------------------\n");
455 ret = cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_ALL,
456 display_server_func,NULL);
457 cli_shutdown(cli);
458 return ret;
461 int net_rap_domain_usage(int argc, const char **argv)
463 d_printf("net rap domain [misc. options] [target]\n\tlists the"\
464 " domains or workgroups visible on the current network\n");
466 net_common_flags_usage(argc, argv);
467 return -1;
471 int net_rap_domain(int argc, const char **argv)
473 struct cli_state *cli;
474 int ret;
476 if (!(cli = net_make_ipc_connection(0)))
477 return -1;
479 d_printf("\nEnumerating domains:\n\n"\
480 "\tDomain name Server name of Browse Master\n"\
481 "\t------------- ----------------------------\n");
483 ret = cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_DOMAIN_ENUM,
484 display_server_func,NULL);
485 cli_shutdown(cli);
486 return ret;
489 int net_rap_printq_usage(int argc, const char **argv)
491 d_printf(
492 "net rap printq [misc. options] [targets]\n"\
493 "\tor\n"\
494 "net rap printq list [<queue_name>] [misc. options] [targets]\n"\
495 "\tlists the specified queue and jobs on the target server.\n"\
496 "\tIf the queue name is not specified, all queues are listed.\n\n");
497 d_printf(
498 "net rap printq delete [<queue name>] [misc. options] [targets]\n"\
499 "\tdeletes the specified job number on the target server, or the\n"\
500 "\tprinter queue if no job number is specified\n");
502 net_common_flags_usage(argc, argv);
504 return -1;
507 static void enum_queue(const char *queuename, uint16 pri, uint16 start,
508 uint16 until, const char *sep, const char *pproc,
509 const char *dest, const char *qparms,
510 const char *qcomment, uint16 status, uint16 jobcount)
512 d_printf("%-17.17s Queue %5d jobs ",
513 queuename, jobcount);
515 switch (status) {
516 case 0:
517 d_printf("*Printer Active*\n");
518 break;
519 case 1:
520 d_printf("*Printer Paused*\n");
521 break;
522 case 2:
523 d_printf("*Printer error*\n");
524 break;
525 case 3:
526 d_printf("*Delete Pending*\n");
527 break;
528 default:
529 d_printf("**UNKNOWN STATUS**\n");
533 static void enum_jobs(uint16 jobid, const char *ownername,
534 const char *notifyname, const char *datatype,
535 const char *jparms, uint16 pos, uint16 status,
536 const char *jstatus, unsigned int submitted, unsigned int jobsize,
537 const char *comment)
539 d_printf(" %-23.23s %5d %9d ",
540 ownername, jobid, jobsize);
541 switch (status) {
542 case 0:
543 d_printf("Waiting\n");
544 break;
545 case 1:
546 d_printf("Held in queue\n");
547 break;
548 case 2:
549 d_printf("Spooling\n");
550 break;
551 case 3:
552 d_printf("Printing\n");
553 break;
554 default:
555 d_printf("**UNKNOWN STATUS**\n");
559 #define PRINTQ_ENUM_DISPLAY \
560 "Print queues at \\\\%s\n\n"\
561 "Name Job # Size Status\n\n"\
562 "------------------------------------------------------------------"\
563 "-------------\n"
565 static int rap_printq_info(int argc, const char **argv)
567 struct cli_state *cli;
568 int ret;
570 if (argc == 0)
571 return net_rap_printq_usage(argc, argv);
573 if (!(cli = net_make_ipc_connection(0)))
574 return -1;
576 d_printf(PRINTQ_ENUM_DISPLAY, cli->desthost); /* list header */
577 ret = cli_NetPrintQGetInfo(cli, argv[0], enum_queue, enum_jobs);
578 cli_shutdown(cli);
579 return ret;
582 static int rap_printq_delete(int argc, const char **argv)
584 struct cli_state *cli;
585 int ret;
587 if (argc == 0)
588 return net_rap_printq_usage(argc, argv);
590 if (!(cli = net_make_ipc_connection(0)))
591 return -1;
593 ret = cli_printjob_del(cli, atoi(argv[0]));
594 cli_shutdown(cli);
595 return ret;
598 int net_rap_printq(int argc, const char **argv)
600 struct cli_state *cli;
601 int ret;
603 struct functable func[] = {
604 {"INFO", rap_printq_info},
605 {"DELETE", rap_printq_delete},
606 {NULL, NULL}
609 if (argc == 0) {
610 if (!(cli = net_make_ipc_connection(0)))
611 return -1;
613 d_printf(PRINTQ_ENUM_DISPLAY, cli->desthost); /* list header */
614 ret = cli_NetPrintQEnum(cli, enum_queue, enum_jobs);
615 cli_shutdown(cli);
616 return ret;
619 return net_run_function(argc, argv, func, net_rap_printq_usage);
623 static int net_rap_user_usage(int argc, const char **argv)
625 return net_help_user(argc, argv);
628 static void user_fn(const char *user_name, void *state)
630 d_printf("%-21.21s\n", user_name);
633 static void long_user_fn(const char *user_name, const char *comment,
634 const char * home_dir, const char * logon_script,
635 void *state)
637 d_printf("%-21.21s %s\n",
638 user_name, comment);
641 static void group_member_fn(const char *user_name, void *state)
643 d_printf("%-21.21s\n", user_name);
646 static int rap_user_delete(int argc, const char **argv)
648 struct cli_state *cli;
649 int ret;
651 if (argc == 0) {
652 d_printf("\n\nUser name not specified\n");
653 return net_rap_user_usage(argc, argv);
656 if (!(cli = net_make_ipc_connection(0)))
657 return -1;
659 ret = cli_NetUserDelete(cli, argv[0]);
660 cli_shutdown(cli);
661 return ret;
664 static int rap_user_add(int argc, const char **argv)
666 struct cli_state *cli;
667 int ret;
668 RAP_USER_INFO_1 userinfo;
670 if (argc == 0) {
671 d_printf("\n\nUser name not specified\n");
672 return net_rap_user_usage(argc, argv);
675 if (!(cli = net_make_ipc_connection(0)))
676 return -1;
678 safe_strcpy(userinfo.user_name, argv[0], sizeof(userinfo.user_name)-1);
679 if (opt_flags == -1)
680 opt_flags = 0x21;
682 userinfo.userflags = opt_flags;
683 userinfo.reserved1 = '\0';
684 userinfo.comment = smb_xstrdup(opt_comment);
685 userinfo.priv = 1;
686 userinfo.home_dir = NULL;
687 userinfo.logon_script = NULL;
689 ret = cli_NetUserAdd(cli, &userinfo);
691 cli_shutdown(cli);
692 return ret;
695 static int rap_user_info(int argc, const char **argv)
697 struct cli_state *cli;
698 int ret;
699 if (argc == 0) {
700 d_printf("\n\nUser name not specified\n");
701 return net_rap_user_usage(argc, argv);
704 if (!(cli = net_make_ipc_connection(0)))
705 return -1;
707 ret = cli_NetUserGetGroups(cli, argv[0], group_member_fn, NULL);
708 cli_shutdown(cli);
709 return ret;
712 int net_rap_user(int argc, const char **argv)
714 int ret = -1;
715 struct functable func[] = {
716 {"ADD", rap_user_add},
717 {"INFO", rap_user_info},
718 {"DELETE", rap_user_delete},
719 {NULL, NULL}
722 if (argc == 0) {
723 struct cli_state *cli;
724 if (!(cli = net_make_ipc_connection(0)))
725 goto done;
726 if (opt_long_list_entries) {
727 d_printf("\nUser name Comment"\
728 "\n-----------------------------\n");
729 ret = cli_RNetUserEnum(cli, long_user_fn, NULL);
730 cli_shutdown(cli);
731 goto done;
733 ret = cli_RNetUserEnum0(cli, user_fn, NULL);
734 cli_shutdown(cli);
735 goto done;
738 ret = net_run_function(argc, argv, func, net_rap_user_usage);
739 done:
740 if (ret != 0) {
741 DEBUG(1, ("Net user returned: %d\n", ret));
743 return ret;
747 int net_rap_group_usage(int argc, const char **argv)
749 return net_help_group(argc, argv);
752 static void long_group_fn(const char *group_name, const char *comment,
753 void *state)
755 d_printf("%-21.21s %s\n", group_name, comment);
758 static void group_fn(const char *group_name, void *state)
760 d_printf("%-21.21s\n", group_name);
763 static int rap_group_delete(int argc, const char **argv)
765 struct cli_state *cli;
766 int ret;
767 if (argc == 0) {
768 d_printf("\n\nGroup name not specified\n");
769 return net_rap_group_usage(argc, argv);
772 if (!(cli = net_make_ipc_connection(0)))
773 return -1;
775 ret = cli_NetGroupDelete(cli, argv[0]);
776 cli_shutdown(cli);
777 return ret;
780 static int rap_group_add(int argc, const char **argv)
782 struct cli_state *cli;
783 int ret;
784 RAP_GROUP_INFO_1 grinfo;
786 if (argc == 0) {
787 d_printf("\n\nGroup name not specified\n");
788 return net_rap_group_usage(argc, argv);
791 if (!(cli = net_make_ipc_connection(0)))
792 return -1;
794 /* BB check for length 21 or smaller explicitly ? BB */
795 safe_strcpy(grinfo.group_name, argv[0], sizeof(grinfo.group_name)-1);
796 grinfo.reserved1 = '\0';
797 grinfo.comment = smb_xstrdup(opt_comment);
799 ret = cli_NetGroupAdd(cli, &grinfo);
800 cli_shutdown(cli);
801 return ret;
804 int net_rap_group(int argc, const char **argv)
806 struct functable func[] = {
807 {"ADD", rap_group_add},
808 {"DELETE", rap_group_delete},
809 {NULL, NULL}
812 if (argc == 0) {
813 struct cli_state *cli;
814 int ret;
815 if (!(cli = net_make_ipc_connection(0)))
816 return -1;
817 if (opt_long_list_entries) {
818 d_printf("Group name Comment\n");
819 d_printf("-----------------------------\n");
820 ret = cli_RNetGroupEnum(cli, long_group_fn, NULL);
821 cli_shutdown(cli);
822 return ret;
824 ret = cli_RNetGroupEnum0(cli, group_fn, NULL);
825 cli_shutdown(cli);
826 return ret;
829 return net_run_function(argc, argv, func, net_rap_group_usage);
832 int net_rap_groupmember_usage(int argc, const char **argv)
834 d_printf(
835 "net rap groupmember LIST <group> [misc. options] [targets]"\
836 "\n\t Enumerate users in a group\n"\
837 "\nnet rap groupmember DELETE <group> <user> [misc. options] "\
838 "[targets]\n\t Delete sepcified user from specified group\n"\
839 "\nnet rap groupmember ADD <group> <user> [misc. options] [targets]"\
840 "\n\t Add specified user to specified group\n");
842 net_common_flags_usage(argc, argv);
843 return -1;
847 static int rap_groupmember_add(int argc, const char **argv)
849 struct cli_state *cli;
850 int ret;
851 if (argc != 2) {
852 d_printf("\n\nGroup or user name not specified\n");
853 return net_rap_groupmember_usage(argc, argv);
856 if (!(cli = net_make_ipc_connection(0)))
857 return -1;
859 ret = cli_NetGroupAddUser(cli, argv[0], argv[1]);
860 cli_shutdown(cli);
861 return ret;
864 static int rap_groupmember_delete(int argc, const char **argv)
866 struct cli_state *cli;
867 int ret;
868 if (argc != 2) {
869 d_printf("\n\nGroup or user name not specified\n");
870 return net_rap_groupmember_usage(argc, argv);
873 if (!(cli = net_make_ipc_connection(0)))
874 return -1;
876 ret = cli_NetGroupDelUser(cli, argv[0], argv[1]);
877 cli_shutdown(cli);
878 return ret;
881 static int rap_groupmember_list(int argc, const char **argv)
883 struct cli_state *cli;
884 int ret;
885 if (argc == 0) {
886 d_printf("\n\nGroup name not specified\n");
887 return net_rap_groupmember_usage(argc, argv);
890 if (!(cli = net_make_ipc_connection(0)))
891 return -1;
893 ret = cli_NetGroupGetUsers(cli, argv[0], group_member_fn, NULL );
894 cli_shutdown(cli);
895 return ret;
898 int net_rap_groupmember(int argc, const char **argv)
900 struct functable func[] = {
901 {"ADD", rap_groupmember_add},
902 {"LIST", rap_groupmember_list},
903 {"DELETE", rap_groupmember_delete},
904 {NULL, NULL}
907 return net_run_function(argc, argv, func, net_rap_groupmember_usage);
910 int net_rap_validate_usage(int argc, const char **argv)
912 d_printf("net rap validate <username> [password]\n"\
913 "\tValidate user and password to check whether they"\
914 " can access target server or domain\n");
916 net_common_flags_usage(argc, argv);
917 return -1;
920 int net_rap_validate(int argc, const char **argv)
922 return errmsg_not_implemented();
925 int net_rap_service_usage(int argc, const char **argv)
927 d_printf("net rap service [misc. options] [targets] \n"\
928 "\tlists all running service daemons on target server\n");
929 d_printf("\nnet rap service START <name> [service startup arguments]"\
930 " [misc. options] [targets]"\
931 "\n\tStart named service on remote server\n");
932 d_printf("\nnet rap service STOP <name> [misc. options] [targets]\n"\
933 "\n\tStop named service on remote server\n");
935 net_common_flags_usage(argc, argv);
936 return -1;
939 static int rap_service_start(int argc, const char **argv)
941 return errmsg_not_implemented();
944 static int rap_service_stop(int argc, const char **argv)
946 return errmsg_not_implemented();
949 static void service_fn(const char *service_name, const char *dummy,
950 void *state)
952 d_printf("%-21.21s\n", service_name);
955 int net_rap_service(int argc, const char **argv)
957 struct functable func[] = {
958 {"START", rap_service_start},
959 {"STOP", rap_service_stop},
960 {NULL, NULL}
963 if (argc == 0) {
964 struct cli_state *cli;
965 int ret;
966 if (!(cli = net_make_ipc_connection(0)))
967 return -1;
969 if (opt_long_list_entries) {
970 d_printf("Service name Comment\n");
971 d_printf("-----------------------------\n");
972 ret = cli_RNetServiceEnum(cli, long_group_fn, NULL);
974 ret = cli_RNetServiceEnum(cli, service_fn, NULL);
975 cli_shutdown(cli);
976 return ret;
979 return net_run_function(argc, argv, func, net_rap_service_usage);
982 int net_rap_password_usage(int argc, const char **argv)
984 d_printf(
985 "net rap password <user> <oldpwo> <newpw> [misc. options] [target]\n"\
986 "\tchanges the password for the specified user at target\n");
988 return -1;
992 int net_rap_password(int argc, const char **argv)
994 struct cli_state *cli;
995 int ret;
997 if (argc < 3)
998 return net_rap_password_usage(argc, argv);
1000 if (!(cli = net_make_ipc_connection(0)))
1001 return -1;
1003 /* BB Add check for password lengths? */
1004 ret = cli_oem_change_password(cli, argv[0], argv[2], argv[1]);
1005 cli_shutdown(cli);
1006 return ret;
1009 int net_rap_admin_usage(int argc, const char **argv)
1011 d_printf(
1012 "net rap admin <remote command> [cmd args [env]] [misc. options] [targets]"\
1013 "\n\texecutes a remote command on an os/2 target server\n");
1015 return -1;
1019 int net_rap_admin(int argc, const char **argv)
1021 return errmsg_not_implemented();
1024 /* The help subsystem for the RAP subcommand */
1026 int net_rap_usage(int argc, const char **argv)
1028 d_printf(" net rap domain \tto list domains \n"\
1029 " net rap file \t\tto list open files on a server \n"\
1030 " net rap group \tto list user groups \n"\
1031 " net rap groupmember \tto list users in a group \n"\
1032 " net rap password \tto change the password of a user\n"\
1033 " net rap printq \tto list the print queues on a server\n"\
1034 " net rap server \tto list servers in a domain\n"\
1035 " net rap session \tto list clients with open sessions to a server\n"\
1036 " net rap share \tto list shares exported by a server\n"\
1037 " net rap user \t\tto list users\n"\
1038 " net rap validate \tto check whether a user and the corresponding password are valid\n"\
1039 " net rap help\n"\
1040 "\nType \"net help <option>\" to get more information on that option\n\n");
1042 net_common_flags_usage(argc, argv);
1043 return -1;
1047 handle "net rap help *" subcommands
1049 int net_rap_help(int argc, const char **argv)
1051 struct functable func[] = {
1052 {"FILE", net_rap_file_usage},
1053 {"SHARE", net_rap_share_usage},
1054 {"SESSION", net_rap_session_usage},
1055 {"SERVER", net_rap_server_usage},
1056 {"DOMAIN", net_rap_domain_usage},
1057 {"PRINTQ", net_rap_printq_usage},
1058 {"USER", net_rap_user_usage},
1059 {"GROUP", net_rap_group_usage},
1060 {"VALIDATE", net_rap_validate_usage},
1061 {"GROUPMEMBER", net_rap_groupmember_usage},
1062 {"ADMIN", net_rap_admin_usage},
1063 {"SERVICE", net_rap_service_usage},
1064 {"PASSWORD", net_rap_password_usage},
1065 {NULL, NULL}};
1067 return net_run_function(argc, argv, func, net_rap_usage);
1070 /* Entry-point for all the RAP functions. */
1072 int net_rap(int argc, const char **argv)
1074 struct functable func[] = {
1075 {"FILE", net_rap_file},
1076 {"SHARE", net_rap_share},
1077 {"SESSION", net_rap_session},
1078 {"SERVER", net_rap_server},
1079 {"DOMAIN", net_rap_domain},
1080 {"PRINTQ", net_rap_printq},
1081 {"USER", net_rap_user},
1082 {"GROUP", net_rap_group},
1083 {"VALIDATE", net_rap_validate},
1084 {"GROUPMEMBER", net_rap_groupmember},
1085 {"ADMIN", net_rap_admin},
1086 {"SERVICE", net_rap_service},
1087 {"PASSWORD", net_rap_password},
1088 {"HELP", net_rap_help},
1089 {NULL, NULL}
1092 return net_run_function(argc, argv, func, net_rap_usage);