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"
30 /* The following messages were for error checking that is not properly
31 reported at the moment. Which should be reinstated? */
32 #define ERRMSG_TARGET_WG_NOT_VALID "\nTarget workgroup option not valid "\
33 "except on net rap server command, ignored"
34 #define ERRMSG_INVALID_HELP_OPTION "\nInvalid help option\n"
36 #define ERRMSG_BOTH_SERVER_IPADDRESS "\nTarget server and IP address both "\
37 "specified. Do not set both at the same time. The target IP address was used\n"
39 static int errmsg_not_implemented(void)
41 d_printf(_("\nNot implemented\n"));
45 int net_rap_file_usage(struct net_context
*c
, int argc
, const char **argv
)
47 return net_file_usage(c
, argc
, argv
);
50 /***************************************************************************
51 list info on an open file
52 ***************************************************************************/
53 static void file_fn(const char * pPath
, const char * pUser
, uint16 perms
,
54 uint16 locks
, uint32 id
)
56 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
57 id
, pUser
, perms
, locks
, pPath
);
60 static void one_file_fn(const char *pPath
, const char *pUser
, uint16 perms
,
61 uint16 locks
, uint32 id
)
63 d_printf(_("File ID %d\n"
67 "Permissions 0x%x\n"),
68 id
, pUser
, locks
, pPath
, perms
);
72 static int rap_file_close(struct net_context
*c
, int argc
, const char **argv
)
74 struct cli_state
*cli
;
76 if (argc
== 0 || c
->display_usage
) {
77 return net_rap_file_usage(c
, argc
, argv
);
80 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
83 ret
= cli_NetFileClose(cli
, atoi(argv
[0]));
88 static int rap_file_info(struct net_context
*c
, int argc
, const char **argv
)
90 struct cli_state
*cli
;
92 if (argc
== 0 || c
->display_usage
)
93 return net_rap_file_usage(c
, argc
, argv
);
95 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
98 ret
= cli_NetFileGetInfo(cli
, atoi(argv
[0]), one_file_fn
);
103 static int rap_file_user(struct net_context
*c
, int argc
, const char **argv
)
105 struct cli_state
*cli
;
108 if (argc
== 0 || c
->display_usage
)
109 return net_rap_file_usage(c
, argc
, argv
);
111 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
114 /* list open files */
116 d_printf(_("\nEnumerating open files on remote server:\n\n"
117 "\nFileId Opened by Perms Locks Path \n"
118 "------ --------- ----- ----- ---- \n"));
119 ret
= cli_NetFileEnum(cli
, argv
[0], NULL
, file_fn
);
122 d_printf(_("\nOperation not supported by server!\n\n"));
128 int net_rap_file(struct net_context
*c
, int argc
, const char **argv
)
130 struct functable func
[] = {
135 N_("Close specified file on server"),
136 N_("net rap file close\n"
137 " Close specified file on server")
143 N_("List all files opened by username"),
144 N_("net rap file user\n"
145 " List all files opened by username")
151 N_("Display info about an opened file"),
152 N_("net rap file info\n"
153 " Display info about an opened file")
155 {NULL
, NULL
, 0, NULL
, NULL
}
159 struct cli_state
*cli
;
162 if (c
->display_usage
) {
163 d_printf(_("Usage:\n"));
164 d_printf(_("net rap file\n"
165 " List all open files on rempte "
167 net_display_usage_from_functable(func
);
171 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
174 /* list open files */
176 d_printf(_("\nEnumerating open files on remote server:\n\n"
177 "\nFileId Opened by Perms Locks Path\n"
178 "------ --------- ----- ----- ----\n"));
179 ret
= cli_NetFileEnum(cli
, NULL
, NULL
, file_fn
);
182 d_printf(_("\nOperation not supported by server!\n\n"));
188 return net_run_function(c
, argc
, argv
, "net rap file", func
);
191 int net_rap_share_usage(struct net_context
*c
, int argc
, const char **argv
)
193 return net_share_usage(c
, argc
, argv
);
196 static void long_share_fn(const char *share_name
, uint32 type
,
197 const char *comment
, void *state
)
199 d_printf("%-12s %-8.8s %-50s\n",
200 share_name
, net_share_type_str(type
), comment
);
203 static void share_fn(const char *share_name
, uint32 type
,
204 const char *comment
, void *state
)
206 d_printf("%s\n", share_name
);
209 static int rap_share_delete(struct net_context
*c
, int argc
, const char **argv
)
211 struct cli_state
*cli
;
214 if (argc
== 0 || c
->display_usage
) {
215 return net_rap_share_usage(c
, argc
, argv
);
218 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
221 ret
= cli_NetShareDelete(cli
, argv
[0]);
226 static int rap_share_add(struct net_context
*c
, int argc
, const char **argv
)
228 struct cli_state
*cli
;
231 struct rap_share_info_2 sinfo
;
235 if (argc
== 0 || c
->display_usage
) {
236 return net_rap_share_usage(c
, argc
, argv
);
239 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
242 sharename
= SMB_STRDUP(argv
[0]);
243 p
= strchr(sharename
, '=');
245 d_printf(_("Server path not specified\n"));
246 SAFE_FREE(sharename
);
247 return net_rap_share_usage(c
, argc
, argv
);
250 strlcpy((char *)sinfo
.share_name
, sharename
, sizeof(sinfo
.share_name
));
251 sinfo
.reserved1
= '\0';
252 sinfo
.share_type
= 0;
253 sinfo
.comment
= c
->opt_comment
? smb_xstrdup(c
->opt_comment
) : "";
255 sinfo
.maximum_users
= c
->opt_maxusers
;
256 sinfo
.active_users
= 0;
258 memset(sinfo
.password
, '\0', sizeof(sinfo
.password
));
259 sinfo
.reserved2
= '\0';
261 ret
= cli_NetShareAdd(cli
, &sinfo
);
263 SAFE_FREE(sharename
);
268 int net_rap_share(struct net_context
*c
, int argc
, const char **argv
)
270 struct functable func
[] = {
275 N_("Delete a share from server"),
276 N_("net rap share delete\n"
277 " Delete a share from server")
283 N_("Delete a share from server"),
284 N_("net rap share close\n"
285 " Delete a share from server\n"
286 " Alias for net rap share delete")
292 N_("Add a share to server"),
293 N_("net rap share add\n"
294 " Add a share to server")
296 {NULL
, NULL
, 0, NULL
, NULL
}
300 struct cli_state
*cli
;
303 if (c
->display_usage
) {
304 d_printf(_("Usage:\n"));
305 d_printf(_("net rap share\n"
306 " List all shares on remote server\n"));
307 net_display_usage_from_functable(func
);
311 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
314 if (c
->opt_long_list_entries
) {
316 "\nEnumerating shared resources (exports) on remote server:\n\n"
317 "\nShare name Type Description\n"
318 "---------- ---- -----------\n"));
319 ret
= cli_RNetShareEnum(cli
, long_share_fn
, NULL
);
321 ret
= cli_RNetShareEnum(cli
, share_fn
, NULL
);
327 return net_run_function(c
, argc
, argv
, "net rap share", func
);
330 int net_rap_session_usage(struct net_context
*c
, int argc
, const char **argv
)
333 "\nnet rap session [misc. options] [targets]"
334 "\n\tenumerates all active SMB/CIFS sessions on target server\n"));
336 "\nnet rap session DELETE <client_name> [misc. options] [targets] \n"
338 "\nnet rap session CLOSE <client_name> [misc. options] [targets]"
339 "\n\tDeletes (closes) a session from specified client to server\n"));
341 "\nnet rap session INFO <client_name>"
342 "\n\tEnumerates all open files in specified session\n"));
344 net_common_flags_usage(c
, argc
, argv
);
348 static void list_sessions_func(char *wsname
, char *username
, uint16 conns
,
349 uint16 opens
, uint16 users
, uint32 sess_time
,
350 uint32 idle_time
, uint32 user_flags
, char *clitype
)
352 int hrs
= idle_time
/ 3600;
353 int min
= (idle_time
/ 60) % 60;
354 int sec
= idle_time
% 60;
356 d_printf("\\\\%-18.18s %-20.20s %-18.18s %5d %2.2d:%2.2d:%2.2d\n",
357 wsname
, username
, clitype
, opens
, hrs
, min
, sec
);
360 static void display_session_func(const char *wsname
, const char *username
,
361 uint16 conns
, uint16 opens
, uint16 users
,
362 uint32 sess_time
, uint32 idle_time
,
363 uint32 user_flags
, const char *clitype
)
365 int ihrs
= idle_time
/ 3600;
366 int imin
= (idle_time
/ 60) % 60;
367 int isec
= idle_time
% 60;
368 int shrs
= sess_time
/ 3600;
369 int smin
= (sess_time
/ 60) % 60;
370 int ssec
= sess_time
% 60;
371 d_printf(_("User name %-20.20s\n"
372 "Computer %-20.20s\n"
373 "Guest logon %-20.20s\n"
374 "Client Type %-40.40s\n"
375 "Sess time %2.2d:%2.2d:%2.2d\n"
376 "Idle time %2.2d:%2.2d:%2.2d\n"),
378 (user_flags
&0x0)?_("yes"):_("no"), clitype
,
379 shrs
, smin
, ssec
, ihrs
, imin
, isec
);
382 static void display_conns_func(uint16 conn_id
, uint16 conn_type
, uint16 opens
,
383 uint16 users
, uint32 conn_time
,
384 const char *username
, const char *netname
)
386 d_printf("%-14.14s %-8.8s %5d\n",
387 netname
, net_share_type_str(conn_type
), opens
);
390 static int rap_session_info(struct net_context
*c
, int argc
, const char **argv
)
392 const char *sessname
;
393 struct cli_state
*cli
;
396 if (argc
== 0 || c
->display_usage
)
397 return net_rap_session_usage(c
, argc
, argv
);
399 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
404 ret
= cli_NetSessionGetInfo(cli
, sessname
, display_session_func
);
410 d_printf(_("Share name Type # Opens\n-------------------------"
411 "-----------------------------------------------------\n"));
412 ret
= cli_NetConnectionEnum(cli
, sessname
, display_conns_func
);
417 static int rap_session_delete(struct net_context
*c
, int argc
, const char **argv
)
419 struct cli_state
*cli
;
422 if (argc
== 0 || c
->display_usage
)
423 return net_rap_session_usage(c
, argc
, argv
);
425 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
428 ret
= cli_NetSessionDel(cli
, argv
[0]);
433 int net_rap_session(struct net_context
*c
, int argc
, const char **argv
)
435 struct functable func
[] = {
440 N_("Display information about session"),
441 N_("net rap session info\n"
442 " Display information about session")
448 N_("Close specified session"),
449 N_("net rap session delete\n"
450 " Close specified session\n"
451 " Alias for net rap session close")
457 N_("Close specified session"),
458 N_("net rap session close\n"
459 " Close specified session")
461 {NULL
, NULL
, 0, NULL
, NULL
}
465 struct cli_state
*cli
;
468 if (c
->display_usage
) {
469 d_printf(_("Usage:\n"));
470 d_printf(_("net rap session\n"
471 " List all open sessions on remote "
473 net_display_usage_from_functable(func
);
477 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
480 d_printf(_("Computer User name "
481 "Client Type Opens Idle time\n"
482 "------------------------------------------"
483 "------------------------------------\n"));
484 ret
= cli_NetSessionEnum(cli
, list_sessions_func
);
490 return net_run_function(c
, argc
, argv
, "net rap session", func
);
493 /****************************************************************************
495 ****************************************************************************/
496 static void display_server_func(const char *name
, uint32 m
,
497 const char *comment
, void * reserved
)
499 d_printf("\t%-16.16s %s\n", name
, comment
);
502 static int net_rap_server_name(struct net_context
*c
, int argc
, const char *argv
[])
504 struct cli_state
*cli
;
507 if (c
->display_usage
) {
510 _("net rap server name\n"
511 " Get the name of the server\n"));
515 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
518 if (!cli_get_server_name(NULL
, cli
, &name
)) {
519 d_fprintf(stderr
, _("cli_get_server_name failed\n"));
524 d_printf(_("Server name = %s\n"), name
);
531 static int net_rap_server_domain(struct net_context
*c
, int argc
,
534 struct cli_state
*cli
;
537 if (c
->display_usage
) {
540 _("net rap server domain\n"
541 " Enumerate servers in this domain/workgroup\n"));
545 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
548 d_printf(_("\nEnumerating servers in this domain or workgroup: \n\n"
549 "\tServer name Server description\n"
550 "\t------------- ----------------------------\n"));
552 ret
= cli_NetServerEnum(cli
, cli
->server_domain
, SV_TYPE_ALL
,
553 display_server_func
,NULL
);
558 int net_rap_server(struct net_context
*c
, int argc
, const char **argv
)
560 struct functable func
[] = {
565 N_("Get the name of the server"),
566 N_("net rap server name\n"
567 " Get the name of the server")
571 net_rap_server_domain
,
573 N_("Get the servers in this domain/workgroup"),
574 N_("net rap server domain\n"
575 " Get the servers in this domain/workgroup")
577 {NULL
, NULL
, 0, NULL
, NULL
}
580 /* smb4k uses 'net [rap|rpc] server domain' to query servers in a domain */
581 /* Fall through for 'domain', any other forms will cause to show usage message */
582 return net_run_function(c
, argc
, argv
, "net rap server", func
);
586 int net_rap_domain_usage(struct net_context
*c
, int argc
, const char **argv
)
588 d_printf(_("net rap domain [misc. options] [target]\n\tlists the"
589 " domains or workgroups visible on the current network\n"));
591 net_common_flags_usage(c
, argc
, argv
);
595 int net_rap_domain(struct net_context
*c
, int argc
, const char **argv
)
597 struct cli_state
*cli
;
600 if (c
->display_usage
)
601 return net_rap_domain_usage(c
, argc
, argv
);
603 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
606 d_printf(_("\nEnumerating domains:\n\n"
607 "\tDomain name Server name of Browse Master\n"
608 "\t------------- ----------------------------\n"));
610 ret
= cli_NetServerEnum(cli
, cli
->server_domain
, SV_TYPE_DOMAIN_ENUM
,
611 display_server_func
,NULL
);
616 int net_rap_printq_usage(struct net_context
*c
, int argc
, const char **argv
)
619 "net rap printq [misc. options] [targets]\n"
621 "net rap printq info [<queue_name>] [misc. options] [targets]\n"
622 "\tlists the specified queue and jobs on the target server.\n"
623 "\tIf the queue name is not specified, all queues are listed.\n\n"));
625 "net rap printq delete [<queue name>] [misc. options] [targets]\n"
626 "\tdeletes the specified job number on the target server, or the\n"
627 "\tprinter queue if no job number is specified\n"));
629 net_common_flags_usage(c
, argc
, argv
);
634 static void enum_queue(const char *queuename
, uint16 pri
, uint16 start
,
635 uint16 until
, const char *sep
, const char *pproc
,
636 const char *dest
, const char *qparms
,
637 const char *qcomment
, uint16 status
, uint16 jobcount
)
639 d_printf(_("%-17.17s Queue %5d jobs "),
640 queuename
, jobcount
);
644 d_printf(_("*Printer Active*\n"));
647 d_printf(_("*Printer Paused*\n"));
650 d_printf(_("*Printer error*\n"));
653 d_printf(_("*Delete Pending*\n"));
656 d_printf(_("**UNKNOWN STATUS**\n"));
660 static void enum_jobs(uint16 jobid
, const char *ownername
,
661 const char *notifyname
, const char *datatype
,
662 const char *jparms
, uint16 pos
, uint16 status
,
663 const char *jstatus
, unsigned int submitted
, unsigned int jobsize
,
666 d_printf(" %-23.23s %5d %9d ",
667 ownername
, jobid
, jobsize
);
670 d_printf(_("Waiting\n"));
673 d_printf(_("Held in queue\n"));
676 d_printf(_("Spooling\n"));
679 d_printf(_("Printing\n"));
682 d_printf(_("**UNKNOWN STATUS**\n"));
686 #define PRINTQ_ENUM_DISPLAY \
687 _("Print queues at \\\\%s\n\n"\
688 "Name Job # Size Status\n\n"\
689 "------------------------------------------------------------------"\
692 static int rap_printq_info(struct net_context
*c
, int argc
, const char **argv
)
694 struct cli_state
*cli
;
697 if (argc
== 0 || c
->display_usage
)
698 return net_rap_printq_usage(c
, argc
, argv
);
700 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
703 d_printf(PRINTQ_ENUM_DISPLAY
, cli
->desthost
); /* list header */
704 ret
= cli_NetPrintQGetInfo(cli
, argv
[0], enum_queue
, enum_jobs
);
709 static int rap_printq_delete(struct net_context
*c
, int argc
, const char **argv
)
711 struct cli_state
*cli
;
714 if (argc
== 0 || c
->display_usage
)
715 return net_rap_printq_usage(c
, argc
, argv
);
717 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
720 ret
= cli_printjob_del(cli
, atoi(argv
[0]));
725 int net_rap_printq(struct net_context
*c
, int argc
, const char **argv
)
727 struct cli_state
*cli
;
730 struct functable func
[] = {
735 N_("Display info about print queues and jobs"),
736 N_("net rap printq info [queue]\n"
737 " Display info about print jobs in queue.\n"
738 " If queue is not specified, all queues are "
745 N_("Delete print job(s)"),
746 N_("net rap printq delete\n"
747 " Delete print job(s)")
749 {NULL
, NULL
, 0, NULL
, NULL
}
753 if (c
->display_usage
) {
754 d_printf(_("Usage:\n"));
755 d_printf(_("net rap printq\n"
756 " List the print queue\n"));
757 net_display_usage_from_functable(func
);
761 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
764 d_printf(PRINTQ_ENUM_DISPLAY
, cli
->desthost
); /* list header */
765 ret
= cli_NetPrintQEnum(cli
, enum_queue
, enum_jobs
);
770 return net_run_function(c
, argc
, argv
, "net rap printq", func
);
773 static int net_rap_user_usage(struct net_context
*c
, int argc
, const char **argv
)
775 return net_user_usage(c
, argc
, argv
);
778 static void user_fn(const char *user_name
, void *state
)
780 d_printf("%-21.21s\n", user_name
);
783 static void long_user_fn(const char *user_name
, const char *comment
,
784 const char * home_dir
, const char * logon_script
,
787 d_printf("%-21.21s %s\n",
791 static void group_member_fn(const char *user_name
, void *state
)
793 d_printf("%-21.21s\n", user_name
);
796 static int rap_user_delete(struct net_context
*c
, int argc
, const char **argv
)
798 struct cli_state
*cli
;
801 if (argc
== 0 || c
->display_usage
) {
802 return net_rap_user_usage(c
, argc
, argv
);
805 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
808 ret
= cli_NetUserDelete(cli
, argv
[0]);
813 static int rap_user_add(struct net_context
*c
, int argc
, const char **argv
)
815 struct cli_state
*cli
;
817 struct rap_user_info_1 userinfo
;
819 if (argc
== 0 || c
->display_usage
) {
820 return net_rap_user_usage(c
, argc
, argv
);
823 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
826 safe_strcpy((char *)userinfo
.user_name
, argv
[0], sizeof(userinfo
.user_name
)-1);
827 if (c
->opt_flags
== -1)
830 userinfo
.userflags
= c
->opt_flags
;
831 userinfo
.reserved1
= '\0';
832 userinfo
.comment
= smb_xstrdup(c
->opt_comment
? c
->opt_comment
: "");
834 userinfo
.home_dir
= NULL
;
835 userinfo
.logon_script
= NULL
;
836 userinfo
.passwrd
[0] = '\0';
838 ret
= cli_NetUserAdd(cli
, &userinfo
);
844 static int rap_user_info(struct net_context
*c
, int argc
, const char **argv
)
846 struct cli_state
*cli
;
848 if (argc
== 0 || c
->display_usage
) {
849 return net_rap_user_usage(c
, argc
, argv
);
852 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
855 ret
= cli_NetUserGetGroups(cli
, argv
[0], group_member_fn
, NULL
);
860 int net_rap_user(struct net_context
*c
, int argc
, const char **argv
)
863 struct functable func
[] = {
868 N_("Add specified user"),
869 N_("net rap user add\n"
870 " Add specified user")
876 N_("List domain groups of specified user"),
877 N_("net rap user info\n"
878 " List domain groups of specified user")
885 N_("Remove specified user"),
886 N_("net rap user delete\n"
887 " Remove specified user")
889 {NULL
, NULL
, 0, NULL
, NULL
}
893 struct cli_state
*cli
;
894 if (c
->display_usage
) {
895 d_printf(_("Usage:\n"));
896 d_printf(_("net rap user\n"
897 " List all users\n"));
898 net_display_usage_from_functable(func
);
902 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
904 if (c
->opt_long_list_entries
) {
905 d_printf(_("\nUser name Comment"
906 "\n-----------------------------\n"));
907 ret
= cli_RNetUserEnum(cli
, long_user_fn
, NULL
);
911 ret
= cli_RNetUserEnum0(cli
, user_fn
, NULL
);
916 ret
= net_run_function(c
, argc
, argv
, "net rap user", func
);
919 DEBUG(1, (_("Net user returned: %d\n"), ret
));
925 int net_rap_group_usage(struct net_context
*c
, int argc
, const char **argv
)
927 return net_group_usage(c
, argc
, argv
);
930 static void long_group_fn(const char *group_name
, const char *comment
,
933 d_printf("%-21.21s %s\n", group_name
, comment
);
936 static void group_fn(const char *group_name
, void *state
)
938 d_printf("%-21.21s\n", group_name
);
941 static int rap_group_delete(struct net_context
*c
, int argc
, const char **argv
)
943 struct cli_state
*cli
;
945 if (argc
== 0 || c
->display_usage
) {
946 return net_rap_group_usage(c
, argc
, argv
);
949 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
952 ret
= cli_NetGroupDelete(cli
, argv
[0]);
957 static int rap_group_add(struct net_context
*c
, int argc
, const char **argv
)
959 struct cli_state
*cli
;
961 struct rap_group_info_1 grinfo
;
963 if (argc
== 0 || c
->display_usage
) {
964 return net_rap_group_usage(c
, argc
, argv
);
967 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
970 /* BB check for length 21 or smaller explicitly ? BB */
971 safe_strcpy((char *)grinfo
.group_name
, argv
[0], sizeof(grinfo
.group_name
)-1);
972 grinfo
.reserved1
= '\0';
973 grinfo
.comment
= smb_xstrdup(c
->opt_comment
? c
->opt_comment
: "");
975 ret
= cli_NetGroupAdd(cli
, &grinfo
);
980 int net_rap_group(struct net_context
*c
, int argc
, const char **argv
)
982 struct functable func
[] = {
987 N_("Add specified group"),
988 N_("net rap group add\n"
989 " Add specified group")
995 N_("Delete specified group"),
996 N_("net rap group delete\n"
997 " Delete specified group")
999 {NULL
, NULL
, 0, NULL
, NULL
}
1003 struct cli_state
*cli
;
1005 if (c
->display_usage
) {
1006 d_printf(_("Usage:\n"));
1007 d_printf(_("net rap group\n"
1008 " List all groups\n"));
1009 net_display_usage_from_functable(func
);
1013 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1015 if (c
->opt_long_list_entries
) {
1016 d_printf(_("Group name Comment\n"
1017 "-----------------------------\n"));
1018 ret
= cli_RNetGroupEnum(cli
, long_group_fn
, NULL
);
1022 ret
= cli_RNetGroupEnum0(cli
, group_fn
, NULL
);
1027 return net_run_function(c
, argc
, argv
, "net rap group", func
);
1030 int net_rap_groupmember_usage(struct net_context
*c
, int argc
, const char **argv
)
1033 "net rap groupmember LIST <group> [misc. options] [targets]"
1034 "\n\t Enumerate users in a group\n"
1035 "\nnet rap groupmember DELETE <group> <user> [misc. options] "
1036 "[targets]\n\t Delete specified user from specified group\n"
1037 "\nnet rap groupmember ADD <group> <user> [misc. options] [targets]"
1038 "\n\t Add specified user to specified group\n"));
1040 net_common_flags_usage(c
, argc
, argv
);
1045 static int rap_groupmember_add(struct net_context
*c
, int argc
, const char **argv
)
1047 struct cli_state
*cli
;
1049 if (argc
!= 2 || c
->display_usage
) {
1050 return net_rap_groupmember_usage(c
, argc
, argv
);
1053 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1056 ret
= cli_NetGroupAddUser(cli
, argv
[0], argv
[1]);
1061 static int rap_groupmember_delete(struct net_context
*c
, int argc
, const char **argv
)
1063 struct cli_state
*cli
;
1065 if (argc
!= 2 || c
->display_usage
) {
1066 return net_rap_groupmember_usage(c
, argc
, argv
);
1069 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1072 ret
= cli_NetGroupDelUser(cli
, argv
[0], argv
[1]);
1077 static int rap_groupmember_list(struct net_context
*c
, int argc
, const char **argv
)
1079 struct cli_state
*cli
;
1081 if (argc
== 0 || c
->display_usage
) {
1082 return net_rap_groupmember_usage(c
, argc
, argv
);
1085 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1088 ret
= cli_NetGroupGetUsers(cli
, argv
[0], group_member_fn
, NULL
);
1093 int net_rap_groupmember(struct net_context
*c
, int argc
, const char **argv
)
1095 struct functable func
[] = {
1098 rap_groupmember_add
,
1100 N_("Add specified user to group"),
1101 N_("net rap groupmember add\n"
1102 " Add specified user to group")
1106 rap_groupmember_list
,
1108 N_("List users in group"),
1109 N_("net rap groupmember list\n"
1110 " List users in group")
1114 rap_groupmember_delete
,
1116 N_("Remove user from group"),
1117 N_("net rap groupmember delete\n"
1118 " Remove user from group")
1120 {NULL
, NULL
, 0, NULL
, NULL
}
1123 return net_run_function(c
, argc
, argv
, "net rap groupmember", func
);
1126 int net_rap_validate_usage(struct net_context
*c
, int argc
, const char **argv
)
1128 d_printf(_("net rap validate <username> [password]\n"
1129 "\tValidate user and password to check whether they"
1130 " can access target server or domain\n"));
1132 net_common_flags_usage(c
, argc
, argv
);
1136 int net_rap_validate(struct net_context
*c
, int argc
, const char **argv
)
1138 return errmsg_not_implemented();
1141 int net_rap_service_usage(struct net_context
*c
, int argc
, const char **argv
)
1143 d_printf(_("net rap service [misc. options] [targets] \n"
1144 "\tlists all running service daemons on target server\n"));
1145 d_printf(_("\nnet rap service START <name> [service startup arguments]"
1146 " [misc. options] [targets]"
1147 "\n\tStart named service on remote server\n"));
1148 d_printf(_("\nnet rap service STOP <name> [misc. options] [targets]\n"
1149 "\n\tStop named service on remote server\n"));
1151 net_common_flags_usage(c
, argc
, argv
);
1155 static int rap_service_start(struct net_context
*c
, int argc
, const char **argv
)
1157 return errmsg_not_implemented();
1160 static int rap_service_stop(struct net_context
*c
, int argc
, const char **argv
)
1162 return errmsg_not_implemented();
1165 static void service_fn(const char *service_name
, const char *dummy
,
1168 d_printf("%-21.21s\n", service_name
);
1171 int net_rap_service(struct net_context
*c
, int argc
, const char **argv
)
1173 struct functable func
[] = {
1178 N_("Start service on remote server"),
1179 N_("net rap service start\n"
1180 " Start service on remote server")
1186 N_("Stop named serve on remote server"),
1187 N_("net rap service stop\n"
1188 " Stop named serve on remote server")
1190 {NULL
, NULL
, 0, NULL
, NULL
}
1194 struct cli_state
*cli
;
1196 if (c
->display_usage
) {
1197 d_printf(_("Usage:\n"));
1198 d_printf(_("net rap service\n"
1199 " List services on remote server\n"));
1200 net_display_usage_from_functable(func
);
1204 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1207 if (c
->opt_long_list_entries
) {
1208 d_printf(_("Service name Comment\n"
1209 "-----------------------------\n"));
1210 ret
= cli_RNetServiceEnum(cli
, long_group_fn
, NULL
);
1212 ret
= cli_RNetServiceEnum(cli
, service_fn
, NULL
);
1217 return net_run_function(c
, argc
, argv
, "net rap service", func
);
1220 int net_rap_password_usage(struct net_context
*c
, int argc
, const char **argv
)
1223 "net rap password <user> <oldpwo> <newpw> [misc. options] [target]\n"
1224 "\tchanges the password for the specified user at target\n"));
1230 int net_rap_password(struct net_context
*c
, int argc
, const char **argv
)
1232 struct cli_state
*cli
;
1235 if (argc
< 3 || c
->display_usage
)
1236 return net_rap_password_usage(c
, argc
, argv
);
1238 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1241 /* BB Add check for password lengths? */
1242 ret
= cli_oem_change_password(cli
, argv
[0], argv
[2], argv
[1]);
1247 int net_rap_admin_usage(struct net_context
*c
, int argc
, const char **argv
)
1250 "net rap admin <remote command> [cmd args [env]] [misc. options] [targets]"
1251 "\n\texecutes a remote command on an os/2 target server\n"));
1257 int net_rap_admin(struct net_context
*c
, int argc
, const char **argv
)
1259 return errmsg_not_implemented();
1262 /* Entry-point for all the RAP functions. */
1264 int net_rap(struct net_context
*c
, int argc
, const char **argv
)
1266 struct functable func
[] = {
1271 N_("List open files"),
1279 N_("List shares exported by server"),
1280 N_("net rap share\n"
1281 " List shares exported by server")
1287 N_("List open sessions"),
1288 N_("net rap session\n"
1289 " List open sessions")
1295 N_("List servers in workgroup"),
1296 N_("net rap server\n"
1297 " List servers in domain/workgroup")
1303 N_("List domains in network"),
1304 N_("net rap domain\n"
1305 " List domains in network")
1311 N_("List printer queues on server"),
1312 N_("net rap printq\n"
1313 " List printer queues on server")
1327 N_("List user groups"),
1328 N_("net rap group\n"
1329 " List user groups")
1335 N_("Check username/password"),
1336 N_("net rap validate\n"
1337 " Check username/password")
1341 net_rap_groupmember
,
1343 N_("List/modify group memberships"),
1344 N_("net rap groupmember\n"
1345 " List/modify group memberships")
1351 N_("Execute commands on remote OS/2"),
1352 N_("net rap admin\n"
1353 " Execute commands on remote OS/2")
1359 N_("Start/stop remote service"),
1360 N_("net rap service\n"
1361 " Start/stop remote service")
1367 N_("Change user password"),
1368 N_("net rap password\n"
1369 " Change user password")
1371 {NULL
, NULL
, 0, NULL
, NULL
}
1374 return net_run_function(c
, argc
, argv
, "net rap", func
);