r17915: Saturn fixes
[Samba/gbeck.git] / source / utils / net_rap.c
blobef5df435357770cf0ecce5503067ba83796519db
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 int net_rap_server(int argc, const char **argv)
413 struct cli_state *cli;
414 int ret;
416 if (!(cli = net_make_ipc_connection(0)))
417 return -1;
419 d_printf("\nEnumerating servers in this domain or workgroup: \n\n"\
420 "\tServer name Server description\n"\
421 "\t------------- ----------------------------\n");
423 ret = cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_ALL,
424 display_server_func,NULL);
425 cli_shutdown(cli);
426 return ret;
429 int net_rap_domain_usage(int argc, const char **argv)
431 d_printf("net rap domain [misc. options] [target]\n\tlists the"\
432 " domains or workgroups visible on the current network\n");
434 net_common_flags_usage(argc, argv);
435 return -1;
439 int net_rap_domain(int argc, const char **argv)
441 struct cli_state *cli;
442 int ret;
444 if (!(cli = net_make_ipc_connection(0)))
445 return -1;
447 d_printf("\nEnumerating domains:\n\n"\
448 "\tDomain name Server name of Browse Master\n"\
449 "\t------------- ----------------------------\n");
451 ret = cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_DOMAIN_ENUM,
452 display_server_func,NULL);
453 cli_shutdown(cli);
454 return ret;
457 int net_rap_printq_usage(int argc, const char **argv)
459 d_printf(
460 "net rap printq [misc. options] [targets]\n"\
461 "\tor\n"\
462 "net rap printq list [<queue_name>] [misc. options] [targets]\n"\
463 "\tlists the specified queue and jobs on the target server.\n"\
464 "\tIf the queue name is not specified, all queues are listed.\n\n");
465 d_printf(
466 "net rap printq delete [<queue name>] [misc. options] [targets]\n"\
467 "\tdeletes the specified job number on the target server, or the\n"\
468 "\tprinter queue if no job number is specified\n");
470 net_common_flags_usage(argc, argv);
472 return -1;
475 static void enum_queue(const char *queuename, uint16 pri, uint16 start,
476 uint16 until, const char *sep, const char *pproc,
477 const char *dest, const char *qparms,
478 const char *qcomment, uint16 status, uint16 jobcount)
480 d_printf("%-17.17s Queue %5d jobs ",
481 queuename, jobcount);
483 switch (status) {
484 case 0:
485 d_printf("*Printer Active*\n");
486 break;
487 case 1:
488 d_printf("*Printer Paused*\n");
489 break;
490 case 2:
491 d_printf("*Printer error*\n");
492 break;
493 case 3:
494 d_printf("*Delete Pending*\n");
495 break;
496 default:
497 d_printf("**UNKNOWN STATUS**\n");
501 static void enum_jobs(uint16 jobid, const char *ownername,
502 const char *notifyname, const char *datatype,
503 const char *jparms, uint16 pos, uint16 status,
504 const char *jstatus, unsigned int submitted, unsigned int jobsize,
505 const char *comment)
507 d_printf(" %-23.23s %5d %9d ",
508 ownername, jobid, jobsize);
509 switch (status) {
510 case 0:
511 d_printf("Waiting\n");
512 break;
513 case 1:
514 d_printf("Held in queue\n");
515 break;
516 case 2:
517 d_printf("Spooling\n");
518 break;
519 case 3:
520 d_printf("Printing\n");
521 break;
522 default:
523 d_printf("**UNKNOWN STATUS**\n");
527 #define PRINTQ_ENUM_DISPLAY \
528 "Print queues at \\\\%s\n\n"\
529 "Name Job # Size Status\n\n"\
530 "------------------------------------------------------------------"\
531 "-------------\n"
533 static int rap_printq_info(int argc, const char **argv)
535 struct cli_state *cli;
536 int ret;
538 if (argc == 0)
539 return net_rap_printq_usage(argc, argv);
541 if (!(cli = net_make_ipc_connection(0)))
542 return -1;
544 d_printf(PRINTQ_ENUM_DISPLAY, cli->desthost); /* list header */
545 ret = cli_NetPrintQGetInfo(cli, argv[0], enum_queue, enum_jobs);
546 cli_shutdown(cli);
547 return ret;
550 static int rap_printq_delete(int argc, const char **argv)
552 struct cli_state *cli;
553 int ret;
555 if (argc == 0)
556 return net_rap_printq_usage(argc, argv);
558 if (!(cli = net_make_ipc_connection(0)))
559 return -1;
561 ret = cli_printjob_del(cli, atoi(argv[0]));
562 cli_shutdown(cli);
563 return ret;
566 int net_rap_printq(int argc, const char **argv)
568 struct cli_state *cli;
569 int ret;
571 struct functable func[] = {
572 {"INFO", rap_printq_info},
573 {"DELETE", rap_printq_delete},
574 {NULL, NULL}
577 if (argc == 0) {
578 if (!(cli = net_make_ipc_connection(0)))
579 return -1;
581 d_printf(PRINTQ_ENUM_DISPLAY, cli->desthost); /* list header */
582 ret = cli_NetPrintQEnum(cli, enum_queue, enum_jobs);
583 cli_shutdown(cli);
584 return ret;
587 return net_run_function(argc, argv, func, net_rap_printq_usage);
591 static int net_rap_user_usage(int argc, const char **argv)
593 return net_help_user(argc, argv);
596 static void user_fn(const char *user_name, void *state)
598 d_printf("%-21.21s\n", user_name);
601 static void long_user_fn(const char *user_name, const char *comment,
602 const char * home_dir, const char * logon_script,
603 void *state)
605 d_printf("%-21.21s %s\n",
606 user_name, comment);
609 static void group_member_fn(const char *user_name, void *state)
611 d_printf("%-21.21s\n", user_name);
614 static int rap_user_delete(int argc, const char **argv)
616 struct cli_state *cli;
617 int ret;
619 if (argc == 0) {
620 d_printf("\n\nUser name not specified\n");
621 return net_rap_user_usage(argc, argv);
624 if (!(cli = net_make_ipc_connection(0)))
625 return -1;
627 ret = cli_NetUserDelete(cli, argv[0]);
628 cli_shutdown(cli);
629 return ret;
632 static int rap_user_add(int argc, const char **argv)
634 struct cli_state *cli;
635 int ret;
636 RAP_USER_INFO_1 userinfo;
638 if (argc == 0) {
639 d_printf("\n\nUser name not specified\n");
640 return net_rap_user_usage(argc, argv);
643 if (!(cli = net_make_ipc_connection(0)))
644 return -1;
646 safe_strcpy(userinfo.user_name, argv[0], sizeof(userinfo.user_name)-1);
647 if (opt_flags == -1)
648 opt_flags = 0x21;
650 userinfo.userflags = opt_flags;
651 userinfo.reserved1 = '\0';
652 userinfo.comment = smb_xstrdup(opt_comment);
653 userinfo.priv = 1;
654 userinfo.home_dir = NULL;
655 userinfo.logon_script = NULL;
657 ret = cli_NetUserAdd(cli, &userinfo);
659 cli_shutdown(cli);
660 return ret;
663 static int rap_user_info(int argc, const char **argv)
665 struct cli_state *cli;
666 int ret;
667 if (argc == 0) {
668 d_printf("\n\nUser name not specified\n");
669 return net_rap_user_usage(argc, argv);
672 if (!(cli = net_make_ipc_connection(0)))
673 return -1;
675 ret = cli_NetUserGetGroups(cli, argv[0], group_member_fn, NULL);
676 cli_shutdown(cli);
677 return ret;
680 int net_rap_user(int argc, const char **argv)
682 int ret = -1;
683 struct functable func[] = {
684 {"ADD", rap_user_add},
685 {"INFO", rap_user_info},
686 {"DELETE", rap_user_delete},
687 {NULL, NULL}
690 if (argc == 0) {
691 struct cli_state *cli;
692 if (!(cli = net_make_ipc_connection(0)))
693 goto done;
694 if (opt_long_list_entries) {
695 d_printf("\nUser name Comment"\
696 "\n-----------------------------\n");
697 ret = cli_RNetUserEnum(cli, long_user_fn, NULL);
698 cli_shutdown(cli);
699 goto done;
701 ret = cli_RNetUserEnum0(cli, user_fn, NULL);
702 cli_shutdown(cli);
703 goto done;
706 ret = net_run_function(argc, argv, func, net_rap_user_usage);
707 done:
708 if (ret != 0) {
709 DEBUG(1, ("Net user returned: %d\n", ret));
711 return ret;
715 int net_rap_group_usage(int argc, const char **argv)
717 return net_help_group(argc, argv);
720 static void long_group_fn(const char *group_name, const char *comment,
721 void *state)
723 d_printf("%-21.21s %s\n", group_name, comment);
726 static void group_fn(const char *group_name, void *state)
728 d_printf("%-21.21s\n", group_name);
731 static int rap_group_delete(int argc, const char **argv)
733 struct cli_state *cli;
734 int ret;
735 if (argc == 0) {
736 d_printf("\n\nGroup name not specified\n");
737 return net_rap_group_usage(argc, argv);
740 if (!(cli = net_make_ipc_connection(0)))
741 return -1;
743 ret = cli_NetGroupDelete(cli, argv[0]);
744 cli_shutdown(cli);
745 return ret;
748 static int rap_group_add(int argc, const char **argv)
750 struct cli_state *cli;
751 int ret;
752 RAP_GROUP_INFO_1 grinfo;
754 if (argc == 0) {
755 d_printf("\n\nGroup name not specified\n");
756 return net_rap_group_usage(argc, argv);
759 if (!(cli = net_make_ipc_connection(0)))
760 return -1;
762 /* BB check for length 21 or smaller explicitly ? BB */
763 safe_strcpy(grinfo.group_name, argv[0], sizeof(grinfo.group_name)-1);
764 grinfo.reserved1 = '\0';
765 grinfo.comment = smb_xstrdup(opt_comment);
767 ret = cli_NetGroupAdd(cli, &grinfo);
768 cli_shutdown(cli);
769 return ret;
772 int net_rap_group(int argc, const char **argv)
774 struct functable func[] = {
775 {"ADD", rap_group_add},
776 {"DELETE", rap_group_delete},
777 {NULL, NULL}
780 if (argc == 0) {
781 struct cli_state *cli;
782 int ret;
783 if (!(cli = net_make_ipc_connection(0)))
784 return -1;
785 if (opt_long_list_entries) {
786 d_printf("Group name Comment\n");
787 d_printf("-----------------------------\n");
788 ret = cli_RNetGroupEnum(cli, long_group_fn, NULL);
789 cli_shutdown(cli);
790 return ret;
792 ret = cli_RNetGroupEnum0(cli, group_fn, NULL);
793 cli_shutdown(cli);
794 return ret;
797 return net_run_function(argc, argv, func, net_rap_group_usage);
800 int net_rap_groupmember_usage(int argc, const char **argv)
802 d_printf(
803 "net rap groupmember LIST <group> [misc. options] [targets]"\
804 "\n\t Enumerate users in a group\n"\
805 "\nnet rap groupmember DELETE <group> <user> [misc. options] "\
806 "[targets]\n\t Delete sepcified user from specified group\n"\
807 "\nnet rap groupmember ADD <group> <user> [misc. options] [targets]"\
808 "\n\t Add specified user to specified group\n");
810 net_common_flags_usage(argc, argv);
811 return -1;
815 static int rap_groupmember_add(int argc, const char **argv)
817 struct cli_state *cli;
818 int ret;
819 if (argc != 2) {
820 d_printf("\n\nGroup or user name not specified\n");
821 return net_rap_groupmember_usage(argc, argv);
824 if (!(cli = net_make_ipc_connection(0)))
825 return -1;
827 ret = cli_NetGroupAddUser(cli, argv[0], argv[1]);
828 cli_shutdown(cli);
829 return ret;
832 static int rap_groupmember_delete(int argc, const char **argv)
834 struct cli_state *cli;
835 int ret;
836 if (argc != 2) {
837 d_printf("\n\nGroup or user name not specified\n");
838 return net_rap_groupmember_usage(argc, argv);
841 if (!(cli = net_make_ipc_connection(0)))
842 return -1;
844 ret = cli_NetGroupDelUser(cli, argv[0], argv[1]);
845 cli_shutdown(cli);
846 return ret;
849 static int rap_groupmember_list(int argc, const char **argv)
851 struct cli_state *cli;
852 int ret;
853 if (argc == 0) {
854 d_printf("\n\nGroup name not specified\n");
855 return net_rap_groupmember_usage(argc, argv);
858 if (!(cli = net_make_ipc_connection(0)))
859 return -1;
861 ret = cli_NetGroupGetUsers(cli, argv[0], group_member_fn, NULL );
862 cli_shutdown(cli);
863 return ret;
866 int net_rap_groupmember(int argc, const char **argv)
868 struct functable func[] = {
869 {"ADD", rap_groupmember_add},
870 {"LIST", rap_groupmember_list},
871 {"DELETE", rap_groupmember_delete},
872 {NULL, NULL}
875 return net_run_function(argc, argv, func, net_rap_groupmember_usage);
878 int net_rap_validate_usage(int argc, const char **argv)
880 d_printf("net rap validate <username> [password]\n"\
881 "\tValidate user and password to check whether they"\
882 " can access target server or domain\n");
884 net_common_flags_usage(argc, argv);
885 return -1;
888 int net_rap_validate(int argc, const char **argv)
890 return errmsg_not_implemented();
893 int net_rap_service_usage(int argc, const char **argv)
895 d_printf("net rap service [misc. options] [targets] \n"\
896 "\tlists all running service daemons on target server\n");
897 d_printf("\nnet rap service START <name> [service startup arguments]"\
898 " [misc. options] [targets]"\
899 "\n\tStart named service on remote server\n");
900 d_printf("\nnet rap service STOP <name> [misc. options] [targets]\n"\
901 "\n\tStop named service on remote server\n");
903 net_common_flags_usage(argc, argv);
904 return -1;
907 static int rap_service_start(int argc, const char **argv)
909 return errmsg_not_implemented();
912 static int rap_service_stop(int argc, const char **argv)
914 return errmsg_not_implemented();
917 static void service_fn(const char *service_name, const char *dummy,
918 void *state)
920 d_printf("%-21.21s\n", service_name);
923 int net_rap_service(int argc, const char **argv)
925 struct functable func[] = {
926 {"START", rap_service_start},
927 {"STOP", rap_service_stop},
928 {NULL, NULL}
931 if (argc == 0) {
932 struct cli_state *cli;
933 int ret;
934 if (!(cli = net_make_ipc_connection(0)))
935 return -1;
937 if (opt_long_list_entries) {
938 d_printf("Service name Comment\n");
939 d_printf("-----------------------------\n");
940 ret = cli_RNetServiceEnum(cli, long_group_fn, NULL);
942 ret = cli_RNetServiceEnum(cli, service_fn, NULL);
943 cli_shutdown(cli);
944 return ret;
947 return net_run_function(argc, argv, func, net_rap_service_usage);
950 int net_rap_password_usage(int argc, const char **argv)
952 d_printf(
953 "net rap password <user> <oldpwo> <newpw> [misc. options] [target]\n"\
954 "\tchanges the password for the specified user at target\n");
956 return -1;
960 int net_rap_password(int argc, const char **argv)
962 struct cli_state *cli;
963 int ret;
965 if (argc < 3)
966 return net_rap_password_usage(argc, argv);
968 if (!(cli = net_make_ipc_connection(0)))
969 return -1;
971 /* BB Add check for password lengths? */
972 ret = cli_oem_change_password(cli, argv[0], argv[2], argv[1]);
973 cli_shutdown(cli);
974 return ret;
977 int net_rap_admin_usage(int argc, const char **argv)
979 d_printf(
980 "net rap admin <remote command> [cmd args [env]] [misc. options] [targets]"\
981 "\n\texecutes a remote command on an os/2 target server\n");
983 return -1;
987 int net_rap_admin(int argc, const char **argv)
989 return errmsg_not_implemented();
992 /* The help subsystem for the RAP subcommand */
994 int net_rap_usage(int argc, const char **argv)
996 d_printf(" net rap domain \tto list domains \n"\
997 " net rap file \t\tto list open files on a server \n"\
998 " net rap group \tto list user groups \n"\
999 " net rap groupmember \tto list users in a group \n"\
1000 " net rap password \tto change the password of a user\n"\
1001 " net rap printq \tto list the print queues on a server\n"\
1002 " net rap server \tto list servers in a domain\n"\
1003 " net rap session \tto list clients with open sessions to a server\n"\
1004 " net rap share \tto list shares exported by a server\n"\
1005 " net rap user \t\tto list users\n"\
1006 " net rap validate \tto check whether a user and the corresponding password are valid\n"\
1007 " net rap help\n"\
1008 "\nType \"net help <option>\" to get more information on that option\n\n");
1010 net_common_flags_usage(argc, argv);
1011 return -1;
1015 handle "net rap help *" subcommands
1017 int net_rap_help(int argc, const char **argv)
1019 struct functable func[] = {
1020 {"FILE", net_rap_file_usage},
1021 {"SHARE", net_rap_share_usage},
1022 {"SESSION", net_rap_session_usage},
1023 {"SERVER", net_rap_server_usage},
1024 {"DOMAIN", net_rap_domain_usage},
1025 {"PRINTQ", net_rap_printq_usage},
1026 {"USER", net_rap_user_usage},
1027 {"GROUP", net_rap_group_usage},
1028 {"VALIDATE", net_rap_validate_usage},
1029 {"GROUPMEMBER", net_rap_groupmember_usage},
1030 {"ADMIN", net_rap_admin_usage},
1031 {"SERVICE", net_rap_service_usage},
1032 {"PASSWORD", net_rap_password_usage},
1033 {NULL, NULL}};
1035 return net_run_function(argc, argv, func, net_rap_usage);
1038 /* Entry-point for all the RAP functions. */
1040 int net_rap(int argc, const char **argv)
1042 struct functable func[] = {
1043 {"FILE", net_rap_file},
1044 {"SHARE", net_rap_share},
1045 {"SESSION", net_rap_session},
1046 {"SERVER", net_rap_server},
1047 {"DOMAIN", net_rap_domain},
1048 {"PRINTQ", net_rap_printq},
1049 {"USER", net_rap_user},
1050 {"GROUP", net_rap_group},
1051 {"VALIDATE", net_rap_validate},
1052 {"GROUPMEMBER", net_rap_groupmember},
1053 {"ADMIN", net_rap_admin},
1054 {"SERVICE", net_rap_service},
1055 {"PASSWORD", net_rap_password},
1056 {"HELP", net_rap_help},
1057 {NULL, NULL}
1060 return net_run_function(argc, argv, func, net_rap_usage);