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
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 3 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, see <http://www.gnu.org/licenses/>. */
26 #include "../librpc/gen_ndr/rap.h"
27 #include "../librpc/gen_ndr/svcctl.h"
28 #include "utils/net.h"
29 #include "libsmb/libsmb.h"
30 #include "libsmb/clirap.h"
32 /* The following messages were for error checking that is not properly
33 reported at the moment. Which should be reinstated? */
34 #define ERRMSG_TARGET_WG_NOT_VALID "\nTarget workgroup option not valid "\
35 "except on net rap server command, ignored"
36 #define ERRMSG_INVALID_HELP_OPTION "\nInvalid help option\n"
38 #define ERRMSG_BOTH_SERVER_IPADDRESS "\nTarget server and IP address both "\
39 "specified. Do not set both at the same time. The target IP address was used\n"
41 static int errmsg_not_implemented(void)
43 d_printf(_("\nNot implemented\n"));
47 int net_rap_file_usage(struct net_context *c, int argc, const char **argv)
49 return net_file_usage(c, argc, argv);
52 /***************************************************************************
53 list info on an open file
54 ***************************************************************************/
55 static void file_fn(const char * pPath, const char * pUser, uint16 perms,
56 uint16 locks, uint32 id)
58 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
59 id, pUser, perms, locks, pPath);
62 static void one_file_fn(const char *pPath, const char *pUser, uint16 perms,
63 uint16 locks, uint32 id)
65 d_printf(_("File ID %d\n"
69 "Permissions 0x%x\n"),
70 id, pUser, locks, pPath, perms);
74 static int rap_file_close(struct net_context *c, int argc, const char **argv)
76 struct cli_state *cli;
78 if (argc == 0 || c->display_usage) {
79 return net_rap_file_usage(c, argc, argv);
82 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
85 ret = cli_NetFileClose(cli, atoi(argv[0]));
90 static int rap_file_info(struct net_context *c, int argc, const char **argv)
92 struct cli_state *cli;
94 if (argc == 0 || c->display_usage)
95 return net_rap_file_usage(c, argc, argv);
97 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
100 ret = cli_NetFileGetInfo(cli, atoi(argv[0]), one_file_fn);
105 static int rap_file_user(struct net_context *c, int argc, const char **argv)
107 struct cli_state *cli;
110 if (argc == 0 || c->display_usage)
111 return net_rap_file_usage(c, argc, argv);
113 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
116 /* list open files */
118 d_printf(_("\nEnumerating open files on remote server:\n\n"
119 "\nFileId Opened by Perms Locks Path \n"
120 "------ --------- ----- ----- ---- \n"));
121 ret = cli_NetFileEnum(cli, argv[0], NULL, file_fn);
124 d_printf(_("\nOperation not supported by server!\n\n"));
130 int net_rap_file(struct net_context *c, int argc, const char **argv)
132 struct functable func[] = {
137 N_("Close specified file on server"),
138 N_("net rap file close\n"
139 " Close specified file on server")
145 N_("List all files opened by username"),
146 N_("net rap file user\n"
147 " List all files opened by username")
153 N_("Display info about an opened file"),
154 N_("net rap file info\n"
155 " Display info about an opened file")
157 {NULL, NULL, 0, NULL, NULL}
161 struct cli_state *cli;
164 if (c->display_usage) {
165 d_printf(_("Usage:\n"));
166 d_printf(_("net rap file\n"
167 " List all open files on rempte "
169 net_display_usage_from_functable(func);
173 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
176 /* list open files */
178 d_printf(_("\nEnumerating open files on remote server:\n\n"
179 "\nFileId Opened by Perms Locks Path\n"
180 "------ --------- ----- ----- ----\n"));
181 ret = cli_NetFileEnum(cli, NULL, NULL, file_fn);
184 d_printf(_("\nOperation not supported by server!\n\n"));
190 return net_run_function(c, argc, argv, "net rap file", func);
193 int net_rap_share_usage(struct net_context *c, int argc, const char **argv)
195 return net_share_usage(c, argc, argv);
198 static void long_share_fn(const char *share_name, uint32 type,
199 const char *comment, void *state)
201 d_printf("%-12s %-8.8s %-50s\n",
202 share_name, net_share_type_str(type), comment);
205 static void share_fn(const char *share_name, uint32 type,
206 const char *comment, void *state)
208 d_printf("%s\n", share_name);
211 static int rap_share_delete(struct net_context *c, int argc, const char **argv)
213 struct cli_state *cli;
216 if (argc == 0 || c->display_usage) {
217 return net_rap_share_usage(c, argc, argv);
220 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
223 ret = cli_NetShareDelete(cli, argv[0]);
228 static int rap_share_add(struct net_context *c, int argc, const char **argv)
230 struct cli_state *cli;
233 struct rap_share_info_2 sinfo;
237 if (argc == 0 || c->display_usage) {
238 return net_rap_share_usage(c, argc, argv);
241 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
244 sharename = SMB_STRDUP(argv[0]);
245 p = strchr(sharename, '=');
247 d_printf(_("Server path not specified\n"));
248 SAFE_FREE(sharename);
249 return net_rap_share_usage(c, argc, argv);
252 strlcpy((char *)sinfo.share_name, sharename, sizeof(sinfo.share_name));
253 sinfo.reserved1 = '\0';
254 sinfo.share_type = 0;
255 sinfo.comment = c->opt_comment ? smb_xstrdup(c->opt_comment) : "";
257 sinfo.maximum_users = c->opt_maxusers;
258 sinfo.active_users = 0;
260 memset(sinfo.password, '\0', sizeof(sinfo.password));
261 sinfo.reserved2 = '\0';
263 ret = cli_NetShareAdd(cli, &sinfo);
265 SAFE_FREE(sharename);
270 int net_rap_share(struct net_context *c, int argc, const char **argv)
272 struct functable func[] = {
277 N_("Delete a share from server"),
278 N_("net rap share delete\n"
279 " Delete a share from server")
285 N_("Delete a share from server"),
286 N_("net rap share close\n"
287 " Delete a share from server\n"
288 " Alias for net rap share delete")
294 N_("Add a share to server"),
295 N_("net rap share add\n"
296 " Add a share to server")
298 {NULL, NULL, 0, NULL, NULL}
302 struct cli_state *cli;
305 if (c->display_usage) {
306 d_printf(_("Usage:\n"));
307 d_printf(_("net rap share\n"
308 " List all shares on remote server\n"));
309 net_display_usage_from_functable(func);
313 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
316 if (c->opt_long_list_entries) {
318 "\nEnumerating shared resources (exports) on remote server:\n\n"
319 "\nShare name Type Description\n"
320 "---------- ---- -----------\n"));
321 ret = cli_RNetShareEnum(cli, long_share_fn, NULL);
323 ret = cli_RNetShareEnum(cli, share_fn, NULL);
329 return net_run_function(c, argc, argv, "net rap share", func);
332 int net_rap_session_usage(struct net_context *c, int argc, const char **argv)
335 "\nnet rap session [misc. options] [targets]"
336 "\n\tenumerates all active SMB/CIFS sessions on target server\n"));
338 "\nnet rap session DELETE <client_name> [misc. options] [targets] \n"
340 "\nnet rap session CLOSE <client_name> [misc. options] [targets]"
341 "\n\tDeletes (closes) a session from specified client to server\n"));
343 "\nnet rap session INFO <client_name>"
344 "\n\tEnumerates all open files in specified session\n"));
346 net_common_flags_usage(c, argc, argv);
350 static void list_sessions_func(char *wsname, char *username, uint16 conns,
351 uint16 opens, uint16 users, uint32 sess_time,
352 uint32 idle_time, uint32 user_flags, char *clitype)
354 int hrs = idle_time / 3600;
355 int min = (idle_time / 60) % 60;
356 int sec = idle_time % 60;
358 d_printf("\\\\%-18.18s %-20.20s %-18.18s %5d %2.2d:%2.2d:%2.2d\n",
359 wsname, username, clitype, opens, hrs, min, sec);
362 static void display_session_func(const char *wsname, const char *username,
363 uint16 conns, uint16 opens, uint16 users,
364 uint32 sess_time, uint32 idle_time,
365 uint32 user_flags, const char *clitype)
367 int ihrs = idle_time / 3600;
368 int imin = (idle_time / 60) % 60;
369 int isec = idle_time % 60;
370 int shrs = sess_time / 3600;
371 int smin = (sess_time / 60) % 60;
372 int ssec = sess_time % 60;
373 d_printf(_("User name %-20.20s\n"
374 "Computer %-20.20s\n"
375 "Guest logon %-20.20s\n"
376 "Client Type %-40.40s\n"
377 "Sess time %2.2d:%2.2d:%2.2d\n"
378 "Idle time %2.2d:%2.2d:%2.2d\n"),
380 (user_flags&0x0)?_("yes"):_("no"), clitype,
381 shrs, smin, ssec, ihrs, imin, isec);
384 static void display_conns_func(uint16 conn_id, uint16 conn_type, uint16 opens,
385 uint16 users, uint32 conn_time,
386 const char *username, const char *netname)
388 d_printf("%-14.14s %-8.8s %5d\n",
389 netname, net_share_type_str(conn_type), opens);
392 static int rap_session_info(struct net_context *c, int argc, const char **argv)
394 const char *sessname;
395 struct cli_state *cli;
398 if (argc == 0 || c->display_usage)
399 return net_rap_session_usage(c, argc, argv);
401 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
406 ret = cli_NetSessionGetInfo(cli, sessname, display_session_func);
412 d_printf(_("Share name Type # Opens\n-------------------------"
413 "-----------------------------------------------------\n"));
414 ret = cli_NetConnectionEnum(cli, sessname, display_conns_func);
419 static int rap_session_delete(struct net_context *c, int argc, const char **argv)
421 struct cli_state *cli;
424 if (argc == 0 || c->display_usage)
425 return net_rap_session_usage(c, argc, argv);
427 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
430 ret = cli_NetSessionDel(cli, argv[0]);
435 int net_rap_session(struct net_context *c, int argc, const char **argv)
437 struct functable func[] = {
442 N_("Display information about session"),
443 N_("net rap session info\n"
444 " Display information about session")
450 N_("Close specified session"),
451 N_("net rap session delete\n"
452 " Close specified session\n"
453 " Alias for net rap session close")
459 N_("Close specified session"),
460 N_("net rap session close\n"
461 " Close specified session")
463 {NULL, NULL, 0, NULL, NULL}
467 struct cli_state *cli;
470 if (c->display_usage) {
471 d_printf(_("Usage:\n"));
472 d_printf(_("net rap session\n"
473 " List all open sessions on remote "
475 net_display_usage_from_functable(func);
479 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
482 d_printf(_("Computer User name "
483 "Client Type Opens Idle time\n"
484 "------------------------------------------"
485 "------------------------------------\n"));
486 ret = cli_NetSessionEnum(cli, list_sessions_func);
492 return net_run_function(c, argc, argv, "net rap session", func);
495 /****************************************************************************
497 ****************************************************************************/
498 static void display_server_func(const char *name, uint32 m,
499 const char *comment, void * reserved)
501 d_printf("\t%-16.16s %s\n", name, comment);
504 static int net_rap_server_name(struct net_context *c, int argc, const char *argv[])
506 struct cli_state *cli;
509 if (c->display_usage) {
512 _("net rap server name\n"
513 " Get the name of the server\n"));
517 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
520 if (!cli_get_server_name(NULL, cli, &name)) {
521 d_fprintf(stderr, _("cli_get_server_name failed\n"));
526 d_printf(_("Server name = %s\n"), name);
533 static int net_rap_server_domain(struct net_context *c, int argc,
536 struct cli_state *cli;
539 if (c->display_usage) {
542 _("net rap server domain\n"
543 " Enumerate servers in this domain/workgroup\n"));
547 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
550 d_printf(_("\nEnumerating servers in this domain or workgroup: \n\n"
551 "\tServer name Server description\n"
552 "\t------------- ----------------------------\n"));
554 ret = cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_ALL,
555 display_server_func,NULL);
560 int net_rap_server(struct net_context *c, int argc, const char **argv)
562 struct functable func[] = {
567 N_("Get the name of the server"),
568 N_("net rap server name\n"
569 " Get the name of the server")
573 net_rap_server_domain,
575 N_("Get the servers in this domain/workgroup"),
576 N_("net rap server domain\n"
577 " Get the servers in this domain/workgroup")
579 {NULL, NULL, 0, NULL, NULL}
582 /* smb4k uses 'net [rap|rpc] server domain' to query servers in a domain */
583 /* Fall through for 'domain', any other forms will cause to show usage message */
584 return net_run_function(c, argc, argv, "net rap server", func);
588 int net_rap_domain_usage(struct net_context *c, int argc, const char **argv)
590 d_printf(_("net rap domain [misc. options] [target]\n\tlists the"
591 " domains or workgroups visible on the current network\n"));
593 net_common_flags_usage(c, argc, argv);
597 int net_rap_domain(struct net_context *c, int argc, const char **argv)
599 struct cli_state *cli;
602 if (c->display_usage)
603 return net_rap_domain_usage(c, argc, argv);
605 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
608 d_printf(_("\nEnumerating domains:\n\n"
609 "\tDomain name Server name of Browse Master\n"
610 "\t------------- ----------------------------\n"));
612 ret = cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_DOMAIN_ENUM,
613 display_server_func,NULL);
618 int net_rap_printq_usage(struct net_context *c, int argc, const char **argv)
621 "net rap printq [misc. options] [targets]\n"
623 "net rap printq info [<queue_name>] [misc. options] [targets]\n"
624 "\tlists the specified queue and jobs on the target server.\n"
625 "\tIf the queue name is not specified, all queues are listed.\n\n"));
627 "net rap printq delete [<queue name>] [misc. options] [targets]\n"
628 "\tdeletes the specified job number on the target server, or the\n"
629 "\tprinter queue if no job number is specified\n"));
631 net_common_flags_usage(c, argc, argv);
636 static void enum_queue(const char *queuename, uint16 pri, uint16 start,
637 uint16 until, const char *sep, const char *pproc,
638 const char *dest, const char *qparms,
639 const char *qcomment, uint16 status, uint16 jobcount)
641 d_printf(_("%-17.17s Queue %5d jobs "),
642 queuename, jobcount);
646 d_printf(_("*Printer Active*\n"));
649 d_printf(_("*Printer Paused*\n"));
652 d_printf(_("*Printer error*\n"));
655 d_printf(_("*Delete Pending*\n"));
658 d_printf(_("**UNKNOWN STATUS**\n"));
662 static void enum_jobs(uint16 jobid, const char *ownername,
663 const char *notifyname, const char *datatype,
664 const char *jparms, uint16 pos, uint16 status,
665 const char *jstatus, unsigned int submitted, unsigned int jobsize,
668 d_printf(" %-23.23s %5d %9d ",
669 ownername, jobid, jobsize);
672 d_printf(_("Waiting\n"));
675 d_printf(_("Held in queue\n"));
678 d_printf(_("Spooling\n"));
681 d_printf(_("Printing\n"));
684 d_printf(_("**UNKNOWN STATUS**\n"));
688 #define PRINTQ_ENUM_DISPLAY \
689 _("Print queues at \\\\%s\n\n"\
690 "Name Job # Size Status\n\n"\
691 "------------------------------------------------------------------"\
694 static int rap_printq_info(struct net_context *c, int argc, const char **argv)
696 struct cli_state *cli;
699 if (argc == 0 || c->display_usage)
700 return net_rap_printq_usage(c, argc, argv);
702 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
705 d_printf(PRINTQ_ENUM_DISPLAY, cli->desthost); /* list header */
706 ret = cli_NetPrintQGetInfo(cli, argv[0], enum_queue, enum_jobs);
711 static int rap_printq_delete(struct net_context *c, int argc, const char **argv)
713 struct cli_state *cli;
716 if (argc == 0 || c->display_usage)
717 return net_rap_printq_usage(c, argc, argv);
719 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
722 ret = cli_printjob_del(cli, atoi(argv[0]));
727 int net_rap_printq(struct net_context *c, int argc, const char **argv)
729 struct cli_state *cli;
732 struct functable func[] = {
737 N_("Display info about print queues and jobs"),
738 N_("net rap printq info [queue]\n"
739 " Display info about print jobs in queue.\n"
740 " If queue is not specified, all queues are "
747 N_("Delete print job(s)"),
748 N_("net rap printq delete\n"
749 " Delete print job(s)")
751 {NULL, NULL, 0, NULL, NULL}
755 if (c->display_usage) {
756 d_printf(_("Usage:\n"));
757 d_printf(_("net rap printq\n"
758 " List the print queue\n"));
759 net_display_usage_from_functable(func);
763 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
766 d_printf(PRINTQ_ENUM_DISPLAY, cli->desthost); /* list header */
767 ret = cli_NetPrintQEnum(cli, enum_queue, enum_jobs);
772 return net_run_function(c, argc, argv, "net rap printq", func);
775 static int net_rap_user_usage(struct net_context *c, int argc, const char **argv)
777 return net_user_usage(c, argc, argv);
780 static void user_fn(const char *user_name, void *state)
782 d_printf("%-21.21s\n", user_name);
785 static void long_user_fn(const char *user_name, const char *comment,
786 const char * home_dir, const char * logon_script,
789 d_printf("%-21.21s %s\n",
793 static void group_member_fn(const char *user_name, void *state)
795 d_printf("%-21.21s\n", user_name);
798 static int rap_user_delete(struct net_context *c, int argc, const char **argv)
800 struct cli_state *cli;
803 if (argc == 0 || c->display_usage) {
804 return net_rap_user_usage(c, argc, argv);
807 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
810 ret = cli_NetUserDelete(cli, argv[0]);
815 static int rap_user_add(struct net_context *c, int argc, const char **argv)
817 struct cli_state *cli;
819 struct rap_user_info_1 userinfo;
821 if (argc == 0 || c->display_usage) {
822 return net_rap_user_usage(c, argc, argv);
825 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
828 strlcpy((char *)userinfo.user_name, argv[0], sizeof(userinfo.user_name));
829 if (c->opt_flags == 0)
832 userinfo.userflags = c->opt_flags;
833 userinfo.reserved1 = '\0';
834 userinfo.comment = smb_xstrdup(c->opt_comment ? c->opt_comment : "");
836 userinfo.home_dir = NULL;
837 userinfo.logon_script = NULL;
838 userinfo.passwrd[0] = '\0';
840 ret = cli_NetUserAdd(cli, &userinfo);
846 static int rap_user_info(struct net_context *c, int argc, const char **argv)
848 struct cli_state *cli;
850 if (argc == 0 || c->display_usage) {
851 return net_rap_user_usage(c, argc, argv);
854 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
857 ret = cli_NetUserGetGroups(cli, argv[0], group_member_fn, NULL);
862 int net_rap_user(struct net_context *c, int argc, const char **argv)
865 struct functable func[] = {
870 N_("Add specified user"),
871 N_("net rap user add\n"
872 " Add specified user")
878 N_("List domain groups of specified user"),
879 N_("net rap user info\n"
880 " List domain groups of specified user")
887 N_("Remove specified user"),
888 N_("net rap user delete\n"
889 " Remove specified user")
891 {NULL, NULL, 0, NULL, NULL}
895 struct cli_state *cli;
896 if (c->display_usage) {
897 d_printf(_("Usage:\n"));
898 d_printf(_("net rap user\n"
899 " List all users\n"));
900 net_display_usage_from_functable(func);
904 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
906 if (c->opt_long_list_entries) {
907 d_printf(_("\nUser name Comment"
908 "\n-----------------------------\n"));
909 ret = cli_RNetUserEnum(cli, long_user_fn, NULL);
913 ret = cli_RNetUserEnum0(cli, user_fn, NULL);
918 ret = net_run_function(c, argc, argv, "net rap user", func);
921 DEBUG(1, (_("Net user returned: %d\n"), ret));
927 int net_rap_group_usage(struct net_context *c, int argc, const char **argv)
929 return net_group_usage(c, argc, argv);
932 static void long_group_fn(const char *group_name, const char *comment,
935 d_printf("%-21.21s %s\n", group_name, comment);
938 static void group_fn(const char *group_name, void *state)
940 d_printf("%-21.21s\n", group_name);
943 static int rap_group_delete(struct net_context *c, int argc, const char **argv)
945 struct cli_state *cli;
947 if (argc == 0 || c->display_usage) {
948 return net_rap_group_usage(c, argc, argv);
951 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
954 ret = cli_NetGroupDelete(cli, argv[0]);
959 static int rap_group_add(struct net_context *c, int argc, const char **argv)
961 struct cli_state *cli;
963 struct rap_group_info_1 grinfo;
965 if (argc == 0 || c->display_usage) {
966 return net_rap_group_usage(c, argc, argv);
969 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
972 /* BB check for length 21 or smaller explicitly ? BB */
973 strlcpy((char *)grinfo.group_name, argv[0], sizeof(grinfo.group_name));
974 grinfo.reserved1 = '\0';
975 grinfo.comment = smb_xstrdup(c->opt_comment ? c->opt_comment : "");
977 ret = cli_NetGroupAdd(cli, &grinfo);
982 int net_rap_group(struct net_context *c, int argc, const char **argv)
984 struct functable func[] = {
989 N_("Add specified group"),
990 N_("net rap group add\n"
991 " Add specified group")
997 N_("Delete specified group"),
998 N_("net rap group delete\n"
999 " Delete specified group")
1001 {NULL, NULL, 0, NULL, NULL}
1005 struct cli_state *cli;
1007 if (c->display_usage) {
1008 d_printf(_("Usage:\n"));
1009 d_printf(_("net rap group\n"
1010 " List all groups\n"));
1011 net_display_usage_from_functable(func);
1015 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1017 if (c->opt_long_list_entries) {
1018 d_printf(_("Group name Comment\n"
1019 "-----------------------------\n"));
1020 ret = cli_RNetGroupEnum(cli, long_group_fn, NULL);
1024 ret = cli_RNetGroupEnum0(cli, group_fn, NULL);
1029 return net_run_function(c, argc, argv, "net rap group", func);
1032 int net_rap_groupmember_usage(struct net_context *c, int argc, const char **argv)
1035 "net rap groupmember LIST <group> [misc. options] [targets]"
1036 "\n\t Enumerate users in a group\n"
1037 "\nnet rap groupmember DELETE <group> <user> [misc. options] "
1038 "[targets]\n\t Delete specified user from specified group\n"
1039 "\nnet rap groupmember ADD <group> <user> [misc. options] [targets]"
1040 "\n\t Add specified user to specified group\n"));
1042 net_common_flags_usage(c, argc, argv);
1047 static int rap_groupmember_add(struct net_context *c, int argc, const char **argv)
1049 struct cli_state *cli;
1051 if (argc != 2 || c->display_usage) {
1052 return net_rap_groupmember_usage(c, argc, argv);
1055 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1058 ret = cli_NetGroupAddUser(cli, argv[0], argv[1]);
1063 static int rap_groupmember_delete(struct net_context *c, int argc, const char **argv)
1065 struct cli_state *cli;
1067 if (argc != 2 || c->display_usage) {
1068 return net_rap_groupmember_usage(c, argc, argv);
1071 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1074 ret = cli_NetGroupDelUser(cli, argv[0], argv[1]);
1079 static int rap_groupmember_list(struct net_context *c, int argc, const char **argv)
1081 struct cli_state *cli;
1083 if (argc == 0 || c->display_usage) {
1084 return net_rap_groupmember_usage(c, argc, argv);
1087 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1090 ret = cli_NetGroupGetUsers(cli, argv[0], group_member_fn, NULL );
1095 int net_rap_groupmember(struct net_context *c, int argc, const char **argv)
1097 struct functable func[] = {
1100 rap_groupmember_add,
1102 N_("Add specified user to group"),
1103 N_("net rap groupmember add\n"
1104 " Add specified user to group")
1108 rap_groupmember_list,
1110 N_("List users in group"),
1111 N_("net rap groupmember list\n"
1112 " List users in group")
1116 rap_groupmember_delete,
1118 N_("Remove user from group"),
1119 N_("net rap groupmember delete\n"
1120 " Remove user from group")
1122 {NULL, NULL, 0, NULL, NULL}
1125 return net_run_function(c, argc, argv, "net rap groupmember", func);
1128 int net_rap_validate_usage(struct net_context *c, int argc, const char **argv)
1130 d_printf(_("net rap validate <username> [password]\n"
1131 "\tValidate user and password to check whether they"
1132 " can access target server or domain\n"));
1134 net_common_flags_usage(c, argc, argv);
1138 int net_rap_validate(struct net_context *c, int argc, const char **argv)
1140 return errmsg_not_implemented();
1143 int net_rap_service_usage(struct net_context *c, int argc, const char **argv)
1145 d_printf(_("net rap service [misc. options] [targets] \n"
1146 "\tlists all running service daemons on target server\n"));
1147 d_printf(_("\nnet rap service START <name> [service startup arguments]"
1148 " [misc. options] [targets]"
1149 "\n\tStart named service on remote server\n"));
1150 d_printf(_("\nnet rap service STOP <name> [misc. options] [targets]\n"
1151 "\n\tStop named service on remote server\n"));
1153 net_common_flags_usage(c, argc, argv);
1157 static int rap_service_start(struct net_context *c, int argc, const char **argv)
1159 return errmsg_not_implemented();
1162 static int rap_service_stop(struct net_context *c, int argc, const char **argv)
1164 return errmsg_not_implemented();
1167 static void service_fn(const char *service_name, const char *dummy,
1170 d_printf("%-21.21s\n", service_name);
1173 int net_rap_service(struct net_context *c, int argc, const char **argv)
1175 struct functable func[] = {
1180 N_("Start service on remote server"),
1181 N_("net rap service start\n"
1182 " Start service on remote server")
1188 N_("Stop named serve on remote server"),
1189 N_("net rap service stop\n"
1190 " Stop named serve on remote server")
1192 {NULL, NULL, 0, NULL, NULL}
1196 struct cli_state *cli;
1198 if (c->display_usage) {
1199 d_printf(_("Usage:\n"));
1200 d_printf(_("net rap service\n"
1201 " List services on remote server\n"));
1202 net_display_usage_from_functable(func);
1206 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1209 if (c->opt_long_list_entries) {
1210 d_printf(_("Service name Comment\n"
1211 "-----------------------------\n"));
1212 ret = cli_RNetServiceEnum(cli, long_group_fn, NULL);
1214 ret = cli_RNetServiceEnum(cli, service_fn, NULL);
1219 return net_run_function(c, argc, argv, "net rap service", func);
1222 int net_rap_password_usage(struct net_context *c, int argc, const char **argv)
1225 "net rap password <user> <oldpwo> <newpw> [misc. options] [target]\n"
1226 "\tchanges the password for the specified user at target\n"));
1232 int net_rap_password(struct net_context *c, int argc, const char **argv)
1234 struct cli_state *cli;
1237 if (argc < 3 || c->display_usage)
1238 return net_rap_password_usage(c, argc, argv);
1240 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1243 /* BB Add check for password lengths? */
1244 ret = cli_oem_change_password(cli, argv[0], argv[2], argv[1]);
1249 int net_rap_admin_usage(struct net_context *c, int argc, const char **argv)
1252 "net rap admin <remote command> [cmd args [env]] [misc. options] [targets]"
1253 "\n\texecutes a remote command on an os/2 target server\n"));
1259 int net_rap_admin(struct net_context *c, int argc, const char **argv)
1261 return errmsg_not_implemented();
1264 /* Entry-point for all the RAP functions. */
1266 int net_rap(struct net_context *c, int argc, const char **argv)
1268 struct functable func[] = {
1273 N_("List open files"),
1281 N_("List shares exported by server"),
1282 N_("net rap share\n"
1283 " List shares exported by server")
1289 N_("List open sessions"),
1290 N_("net rap session\n"
1291 " List open sessions")
1297 N_("List servers in workgroup"),
1298 N_("net rap server\n"
1299 " List servers in domain/workgroup")
1305 N_("List domains in network"),
1306 N_("net rap domain\n"
1307 " List domains in network")
1313 N_("List printer queues on server"),
1314 N_("net rap printq\n"
1315 " List printer queues on server")
1329 N_("List user groups"),
1330 N_("net rap group\n"
1331 " List user groups")
1337 N_("Check username/password"),
1338 N_("net rap validate\n"
1339 " Check username/password")
1343 net_rap_groupmember,
1345 N_("List/modify group memberships"),
1346 N_("net rap groupmember\n"
1347 " List/modify group memberships")
1353 N_("Execute commands on remote OS/2"),
1354 N_("net rap admin\n"
1355 " Execute commands on remote OS/2")
1361 N_("Start/stop remote service"),
1362 N_("net rap service\n"
1363 " Start/stop remote service")
1369 N_("Change user password"),
1370 N_("net rap password\n"
1371 " Change user password")
1373 {NULL, NULL, 0, NULL, NULL}
1376 return net_run_function(c, argc, argv, "net rap", func);