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/clirap.h"
31 /* The following messages were for error checking that is not properly
32 reported at the moment. Which should be reinstated? */
33 #define ERRMSG_TARGET_WG_NOT_VALID "\nTarget workgroup option not valid "\
34 "except on net rap server command, ignored"
35 #define ERRMSG_INVALID_HELP_OPTION "\nInvalid help option\n"
37 #define ERRMSG_BOTH_SERVER_IPADDRESS "\nTarget server and IP address both "\
38 "specified. Do not set both at the same time. The target IP address was used\n"
40 static int errmsg_not_implemented(void)
42 d_printf(_("\nNot implemented\n"));
46 int net_rap_file_usage(struct net_context
*c
, int argc
, const char **argv
)
48 return net_file_usage(c
, argc
, argv
);
51 /***************************************************************************
52 list info on an open file
53 ***************************************************************************/
54 static void file_fn(const char * pPath
, const char * pUser
, uint16 perms
,
55 uint16 locks
, uint32 id
)
57 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
58 id
, pUser
, perms
, locks
, pPath
);
61 static void one_file_fn(const char *pPath
, const char *pUser
, uint16 perms
,
62 uint16 locks
, uint32 id
)
64 d_printf(_("File ID %d\n"
68 "Permissions 0x%x\n"),
69 id
, pUser
, locks
, pPath
, perms
);
73 static int rap_file_close(struct net_context
*c
, int argc
, const char **argv
)
75 struct cli_state
*cli
;
77 if (argc
== 0 || c
->display_usage
) {
78 return net_rap_file_usage(c
, argc
, argv
);
81 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
84 ret
= cli_NetFileClose(cli
, atoi(argv
[0]));
89 static int rap_file_info(struct net_context
*c
, int argc
, const char **argv
)
91 struct cli_state
*cli
;
93 if (argc
== 0 || c
->display_usage
)
94 return net_rap_file_usage(c
, argc
, argv
);
96 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
99 ret
= cli_NetFileGetInfo(cli
, atoi(argv
[0]), one_file_fn
);
104 static int rap_file_user(struct net_context
*c
, int argc
, const char **argv
)
106 struct cli_state
*cli
;
109 if (argc
== 0 || c
->display_usage
)
110 return net_rap_file_usage(c
, argc
, argv
);
112 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
115 /* list open files */
117 d_printf(_("\nEnumerating open files on remote server:\n\n"
118 "\nFileId Opened by Perms Locks Path \n"
119 "------ --------- ----- ----- ---- \n"));
120 ret
= cli_NetFileEnum(cli
, argv
[0], NULL
, file_fn
);
123 d_printf(_("\nOperation not supported by server!\n\n"));
129 int net_rap_file(struct net_context
*c
, int argc
, const char **argv
)
131 struct functable func
[] = {
136 N_("Close specified file on server"),
137 N_("net rap file close\n"
138 " Close specified file on server")
144 N_("List all files opened by username"),
145 N_("net rap file user\n"
146 " List all files opened by username")
152 N_("Display info about an opened file"),
153 N_("net rap file info\n"
154 " Display info about an opened file")
156 {NULL
, NULL
, 0, NULL
, NULL
}
160 struct cli_state
*cli
;
163 if (c
->display_usage
) {
164 d_printf(_("Usage:\n"));
165 d_printf(_("net rap file\n"
166 " List all open files on rempte "
168 net_display_usage_from_functable(func
);
172 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
175 /* list open files */
177 d_printf(_("\nEnumerating open files on remote server:\n\n"
178 "\nFileId Opened by Perms Locks Path\n"
179 "------ --------- ----- ----- ----\n"));
180 ret
= cli_NetFileEnum(cli
, NULL
, NULL
, file_fn
);
183 d_printf(_("\nOperation not supported by server!\n\n"));
189 return net_run_function(c
, argc
, argv
, "net rap file", func
);
192 int net_rap_share_usage(struct net_context
*c
, int argc
, const char **argv
)
194 return net_share_usage(c
, argc
, argv
);
197 static void long_share_fn(const char *share_name
, uint32 type
,
198 const char *comment
, void *state
)
200 d_printf("%-12s %-8.8s %-50s\n",
201 share_name
, net_share_type_str(type
), comment
);
204 static void share_fn(const char *share_name
, uint32 type
,
205 const char *comment
, void *state
)
207 d_printf("%s\n", share_name
);
210 static int rap_share_delete(struct net_context
*c
, int argc
, const char **argv
)
212 struct cli_state
*cli
;
215 if (argc
== 0 || c
->display_usage
) {
216 return net_rap_share_usage(c
, argc
, argv
);
219 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
222 ret
= cli_NetShareDelete(cli
, argv
[0]);
227 static int rap_share_add(struct net_context
*c
, int argc
, const char **argv
)
229 struct cli_state
*cli
;
232 struct rap_share_info_2 sinfo
;
236 if (argc
== 0 || c
->display_usage
) {
237 return net_rap_share_usage(c
, argc
, argv
);
240 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
243 sharename
= SMB_STRDUP(argv
[0]);
244 p
= strchr(sharename
, '=');
246 d_printf(_("Server path not specified\n"));
247 SAFE_FREE(sharename
);
248 return net_rap_share_usage(c
, argc
, argv
);
251 strlcpy((char *)sinfo
.share_name
, sharename
, sizeof(sinfo
.share_name
));
252 sinfo
.reserved1
= '\0';
253 sinfo
.share_type
= 0;
254 sinfo
.comment
= c
->opt_comment
? smb_xstrdup(c
->opt_comment
) : "";
256 sinfo
.maximum_users
= c
->opt_maxusers
;
257 sinfo
.active_users
= 0;
259 memset(sinfo
.password
, '\0', sizeof(sinfo
.password
));
260 sinfo
.reserved2
= '\0';
262 ret
= cli_NetShareAdd(cli
, &sinfo
);
264 SAFE_FREE(sharename
);
269 int net_rap_share(struct net_context
*c
, int argc
, const char **argv
)
271 struct functable func
[] = {
276 N_("Delete a share from server"),
277 N_("net rap share delete\n"
278 " Delete a share from server")
284 N_("Delete a share from server"),
285 N_("net rap share close\n"
286 " Delete a share from server\n"
287 " Alias for net rap share delete")
293 N_("Add a share to server"),
294 N_("net rap share add\n"
295 " Add a share to server")
297 {NULL
, NULL
, 0, NULL
, NULL
}
301 struct cli_state
*cli
;
304 if (c
->display_usage
) {
305 d_printf(_("Usage:\n"));
306 d_printf(_("net rap share\n"
307 " List all shares on remote server\n"));
308 net_display_usage_from_functable(func
);
312 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
315 if (c
->opt_long_list_entries
) {
317 "\nEnumerating shared resources (exports) on remote server:\n\n"
318 "\nShare name Type Description\n"
319 "---------- ---- -----------\n"));
320 ret
= cli_RNetShareEnum(cli
, long_share_fn
, NULL
);
322 ret
= cli_RNetShareEnum(cli
, share_fn
, NULL
);
328 return net_run_function(c
, argc
, argv
, "net rap share", func
);
331 int net_rap_session_usage(struct net_context
*c
, int argc
, const char **argv
)
334 "\nnet rap session [misc. options] [targets]"
335 "\n\tenumerates all active SMB/CIFS sessions on target server\n"));
337 "\nnet rap session DELETE <client_name> [misc. options] [targets] \n"
339 "\nnet rap session CLOSE <client_name> [misc. options] [targets]"
340 "\n\tDeletes (closes) a session from specified client to server\n"));
342 "\nnet rap session INFO <client_name>"
343 "\n\tEnumerates all open files in specified session\n"));
345 net_common_flags_usage(c
, argc
, argv
);
349 static void list_sessions_func(char *wsname
, char *username
, uint16 conns
,
350 uint16 opens
, uint16 users
, uint32 sess_time
,
351 uint32 idle_time
, uint32 user_flags
, char *clitype
)
353 int hrs
= idle_time
/ 3600;
354 int min
= (idle_time
/ 60) % 60;
355 int sec
= idle_time
% 60;
357 d_printf("\\\\%-18.18s %-20.20s %-18.18s %5d %2.2d:%2.2d:%2.2d\n",
358 wsname
, username
, clitype
, opens
, hrs
, min
, sec
);
361 static void display_session_func(const char *wsname
, const char *username
,
362 uint16 conns
, uint16 opens
, uint16 users
,
363 uint32 sess_time
, uint32 idle_time
,
364 uint32 user_flags
, const char *clitype
)
366 int ihrs
= idle_time
/ 3600;
367 int imin
= (idle_time
/ 60) % 60;
368 int isec
= idle_time
% 60;
369 int shrs
= sess_time
/ 3600;
370 int smin
= (sess_time
/ 60) % 60;
371 int ssec
= sess_time
% 60;
372 d_printf(_("User name %-20.20s\n"
373 "Computer %-20.20s\n"
374 "Guest logon %-20.20s\n"
375 "Client Type %-40.40s\n"
376 "Sess time %2.2d:%2.2d:%2.2d\n"
377 "Idle time %2.2d:%2.2d:%2.2d\n"),
379 (user_flags
&0x0)?_("yes"):_("no"), clitype
,
380 shrs
, smin
, ssec
, ihrs
, imin
, isec
);
383 static void display_conns_func(uint16 conn_id
, uint16 conn_type
, uint16 opens
,
384 uint16 users
, uint32 conn_time
,
385 const char *username
, const char *netname
)
387 d_printf("%-14.14s %-8.8s %5d\n",
388 netname
, net_share_type_str(conn_type
), opens
);
391 static int rap_session_info(struct net_context
*c
, int argc
, const char **argv
)
393 const char *sessname
;
394 struct cli_state
*cli
;
397 if (argc
== 0 || c
->display_usage
)
398 return net_rap_session_usage(c
, argc
, argv
);
400 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
405 ret
= cli_NetSessionGetInfo(cli
, sessname
, display_session_func
);
411 d_printf(_("Share name Type # Opens\n-------------------------"
412 "-----------------------------------------------------\n"));
413 ret
= cli_NetConnectionEnum(cli
, sessname
, display_conns_func
);
418 static int rap_session_delete(struct net_context
*c
, int argc
, const char **argv
)
420 struct cli_state
*cli
;
423 if (argc
== 0 || c
->display_usage
)
424 return net_rap_session_usage(c
, argc
, argv
);
426 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
429 ret
= cli_NetSessionDel(cli
, argv
[0]);
434 int net_rap_session(struct net_context
*c
, int argc
, const char **argv
)
436 struct functable func
[] = {
441 N_("Display information about session"),
442 N_("net rap session info\n"
443 " Display information about session")
449 N_("Close specified session"),
450 N_("net rap session delete\n"
451 " Close specified session\n"
452 " Alias for net rap session close")
458 N_("Close specified session"),
459 N_("net rap session close\n"
460 " Close specified session")
462 {NULL
, NULL
, 0, NULL
, NULL
}
466 struct cli_state
*cli
;
469 if (c
->display_usage
) {
470 d_printf(_("Usage:\n"));
471 d_printf(_("net rap session\n"
472 " List all open sessions on remote "
474 net_display_usage_from_functable(func
);
478 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
481 d_printf(_("Computer User name "
482 "Client Type Opens Idle time\n"
483 "------------------------------------------"
484 "------------------------------------\n"));
485 ret
= cli_NetSessionEnum(cli
, list_sessions_func
);
491 return net_run_function(c
, argc
, argv
, "net rap session", func
);
494 /****************************************************************************
496 ****************************************************************************/
497 static void display_server_func(const char *name
, uint32 m
,
498 const char *comment
, void * reserved
)
500 d_printf("\t%-16.16s %s\n", name
, comment
);
503 static int net_rap_server_name(struct net_context
*c
, int argc
, const char *argv
[])
505 struct cli_state
*cli
;
508 if (c
->display_usage
) {
511 _("net rap server name\n"
512 " Get the name of the server\n"));
516 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
519 if (!cli_get_server_name(NULL
, cli
, &name
)) {
520 d_fprintf(stderr
, _("cli_get_server_name failed\n"));
525 d_printf(_("Server name = %s\n"), name
);
532 static int net_rap_server_domain(struct net_context
*c
, int argc
,
535 struct cli_state
*cli
;
538 if (c
->display_usage
) {
541 _("net rap server domain\n"
542 " Enumerate servers in this domain/workgroup\n"));
546 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
549 d_printf(_("\nEnumerating servers in this domain or workgroup: \n\n"
550 "\tServer name Server description\n"
551 "\t------------- ----------------------------\n"));
553 ret
= cli_NetServerEnum(cli
, cli
->server_domain
, SV_TYPE_ALL
,
554 display_server_func
,NULL
);
559 int net_rap_server(struct net_context
*c
, int argc
, const char **argv
)
561 struct functable func
[] = {
566 N_("Get the name of the server"),
567 N_("net rap server name\n"
568 " Get the name of the server")
572 net_rap_server_domain
,
574 N_("Get the servers in this domain/workgroup"),
575 N_("net rap server domain\n"
576 " Get the servers in this domain/workgroup")
578 {NULL
, NULL
, 0, NULL
, NULL
}
581 /* smb4k uses 'net [rap|rpc] server domain' to query servers in a domain */
582 /* Fall through for 'domain', any other forms will cause to show usage message */
583 return net_run_function(c
, argc
, argv
, "net rap server", func
);
587 int net_rap_domain_usage(struct net_context
*c
, int argc
, const char **argv
)
589 d_printf(_("net rap domain [misc. options] [target]\n\tlists the"
590 " domains or workgroups visible on the current network\n"));
592 net_common_flags_usage(c
, argc
, argv
);
596 int net_rap_domain(struct net_context
*c
, int argc
, const char **argv
)
598 struct cli_state
*cli
;
601 if (c
->display_usage
)
602 return net_rap_domain_usage(c
, argc
, argv
);
604 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
607 d_printf(_("\nEnumerating domains:\n\n"
608 "\tDomain name Server name of Browse Master\n"
609 "\t------------- ----------------------------\n"));
611 ret
= cli_NetServerEnum(cli
, cli
->server_domain
, SV_TYPE_DOMAIN_ENUM
,
612 display_server_func
,NULL
);
617 int net_rap_printq_usage(struct net_context
*c
, int argc
, const char **argv
)
620 "net rap printq [misc. options] [targets]\n"
622 "net rap printq info [<queue_name>] [misc. options] [targets]\n"
623 "\tlists the specified queue and jobs on the target server.\n"
624 "\tIf the queue name is not specified, all queues are listed.\n\n"));
626 "net rap printq delete [<queue name>] [misc. options] [targets]\n"
627 "\tdeletes the specified job number on the target server, or the\n"
628 "\tprinter queue if no job number is specified\n"));
630 net_common_flags_usage(c
, argc
, argv
);
635 static void enum_queue(const char *queuename
, uint16 pri
, uint16 start
,
636 uint16 until
, const char *sep
, const char *pproc
,
637 const char *dest
, const char *qparms
,
638 const char *qcomment
, uint16 status
, uint16 jobcount
)
640 d_printf(_("%-17.17s Queue %5d jobs "),
641 queuename
, jobcount
);
645 d_printf(_("*Printer Active*\n"));
648 d_printf(_("*Printer Paused*\n"));
651 d_printf(_("*Printer error*\n"));
654 d_printf(_("*Delete Pending*\n"));
657 d_printf(_("**UNKNOWN STATUS**\n"));
661 static void enum_jobs(uint16 jobid
, const char *ownername
,
662 const char *notifyname
, const char *datatype
,
663 const char *jparms
, uint16 pos
, uint16 status
,
664 const char *jstatus
, unsigned int submitted
, unsigned int jobsize
,
667 d_printf(" %-23.23s %5d %9d ",
668 ownername
, jobid
, jobsize
);
671 d_printf(_("Waiting\n"));
674 d_printf(_("Held in queue\n"));
677 d_printf(_("Spooling\n"));
680 d_printf(_("Printing\n"));
683 d_printf(_("**UNKNOWN STATUS**\n"));
687 #define PRINTQ_ENUM_DISPLAY \
688 _("Print queues at \\\\%s\n\n"\
689 "Name Job # Size Status\n\n"\
690 "------------------------------------------------------------------"\
693 static int rap_printq_info(struct net_context
*c
, int argc
, const char **argv
)
695 struct cli_state
*cli
;
698 if (argc
== 0 || c
->display_usage
)
699 return net_rap_printq_usage(c
, argc
, argv
);
701 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
704 d_printf(PRINTQ_ENUM_DISPLAY
, cli
->desthost
); /* list header */
705 ret
= cli_NetPrintQGetInfo(cli
, argv
[0], enum_queue
, enum_jobs
);
710 static int rap_printq_delete(struct net_context
*c
, int argc
, const char **argv
)
712 struct cli_state
*cli
;
715 if (argc
== 0 || c
->display_usage
)
716 return net_rap_printq_usage(c
, argc
, argv
);
718 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
721 ret
= cli_printjob_del(cli
, atoi(argv
[0]));
726 int net_rap_printq(struct net_context
*c
, int argc
, const char **argv
)
728 struct cli_state
*cli
;
731 struct functable func
[] = {
736 N_("Display info about print queues and jobs"),
737 N_("net rap printq info [queue]\n"
738 " Display info about print jobs in queue.\n"
739 " If queue is not specified, all queues are "
746 N_("Delete print job(s)"),
747 N_("net rap printq delete\n"
748 " Delete print job(s)")
750 {NULL
, NULL
, 0, NULL
, NULL
}
754 if (c
->display_usage
) {
755 d_printf(_("Usage:\n"));
756 d_printf(_("net rap printq\n"
757 " List the print queue\n"));
758 net_display_usage_from_functable(func
);
762 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
765 d_printf(PRINTQ_ENUM_DISPLAY
, cli
->desthost
); /* list header */
766 ret
= cli_NetPrintQEnum(cli
, enum_queue
, enum_jobs
);
771 return net_run_function(c
, argc
, argv
, "net rap printq", func
);
774 static int net_rap_user_usage(struct net_context
*c
, int argc
, const char **argv
)
776 return net_user_usage(c
, argc
, argv
);
779 static void user_fn(const char *user_name
, void *state
)
781 d_printf("%-21.21s\n", user_name
);
784 static void long_user_fn(const char *user_name
, const char *comment
,
785 const char * home_dir
, const char * logon_script
,
788 d_printf("%-21.21s %s\n",
792 static void group_member_fn(const char *user_name
, void *state
)
794 d_printf("%-21.21s\n", user_name
);
797 static int rap_user_delete(struct net_context
*c
, int argc
, const char **argv
)
799 struct cli_state
*cli
;
802 if (argc
== 0 || c
->display_usage
) {
803 return net_rap_user_usage(c
, argc
, argv
);
806 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
809 ret
= cli_NetUserDelete(cli
, argv
[0]);
814 static int rap_user_add(struct net_context
*c
, int argc
, const char **argv
)
816 struct cli_state
*cli
;
818 struct rap_user_info_1 userinfo
;
820 if (argc
== 0 || c
->display_usage
) {
821 return net_rap_user_usage(c
, argc
, argv
);
824 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
827 safe_strcpy((char *)userinfo
.user_name
, argv
[0], sizeof(userinfo
.user_name
)-1);
828 if (c
->opt_flags
== 0)
831 userinfo
.userflags
= c
->opt_flags
;
832 userinfo
.reserved1
= '\0';
833 userinfo
.comment
= smb_xstrdup(c
->opt_comment
? c
->opt_comment
: "");
835 userinfo
.home_dir
= NULL
;
836 userinfo
.logon_script
= NULL
;
837 userinfo
.passwrd
[0] = '\0';
839 ret
= cli_NetUserAdd(cli
, &userinfo
);
845 static int rap_user_info(struct net_context
*c
, int argc
, const char **argv
)
847 struct cli_state
*cli
;
849 if (argc
== 0 || c
->display_usage
) {
850 return net_rap_user_usage(c
, argc
, argv
);
853 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
856 ret
= cli_NetUserGetGroups(cli
, argv
[0], group_member_fn
, NULL
);
861 int net_rap_user(struct net_context
*c
, int argc
, const char **argv
)
864 struct functable func
[] = {
869 N_("Add specified user"),
870 N_("net rap user add\n"
871 " Add specified user")
877 N_("List domain groups of specified user"),
878 N_("net rap user info\n"
879 " List domain groups of specified user")
886 N_("Remove specified user"),
887 N_("net rap user delete\n"
888 " Remove specified user")
890 {NULL
, NULL
, 0, NULL
, NULL
}
894 struct cli_state
*cli
;
895 if (c
->display_usage
) {
896 d_printf(_("Usage:\n"));
897 d_printf(_("net rap user\n"
898 " List all users\n"));
899 net_display_usage_from_functable(func
);
903 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
905 if (c
->opt_long_list_entries
) {
906 d_printf(_("\nUser name Comment"
907 "\n-----------------------------\n"));
908 ret
= cli_RNetUserEnum(cli
, long_user_fn
, NULL
);
912 ret
= cli_RNetUserEnum0(cli
, user_fn
, NULL
);
917 ret
= net_run_function(c
, argc
, argv
, "net rap user", func
);
920 DEBUG(1, (_("Net user returned: %d\n"), ret
));
926 int net_rap_group_usage(struct net_context
*c
, int argc
, const char **argv
)
928 return net_group_usage(c
, argc
, argv
);
931 static void long_group_fn(const char *group_name
, const char *comment
,
934 d_printf("%-21.21s %s\n", group_name
, comment
);
937 static void group_fn(const char *group_name
, void *state
)
939 d_printf("%-21.21s\n", group_name
);
942 static int rap_group_delete(struct net_context
*c
, int argc
, const char **argv
)
944 struct cli_state
*cli
;
946 if (argc
== 0 || c
->display_usage
) {
947 return net_rap_group_usage(c
, argc
, argv
);
950 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
953 ret
= cli_NetGroupDelete(cli
, argv
[0]);
958 static int rap_group_add(struct net_context
*c
, int argc
, const char **argv
)
960 struct cli_state
*cli
;
962 struct rap_group_info_1 grinfo
;
964 if (argc
== 0 || c
->display_usage
) {
965 return net_rap_group_usage(c
, argc
, argv
);
968 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
971 /* BB check for length 21 or smaller explicitly ? BB */
972 safe_strcpy((char *)grinfo
.group_name
, argv
[0], sizeof(grinfo
.group_name
)-1);
973 grinfo
.reserved1
= '\0';
974 grinfo
.comment
= smb_xstrdup(c
->opt_comment
? c
->opt_comment
: "");
976 ret
= cli_NetGroupAdd(cli
, &grinfo
);
981 int net_rap_group(struct net_context
*c
, int argc
, const char **argv
)
983 struct functable func
[] = {
988 N_("Add specified group"),
989 N_("net rap group add\n"
990 " Add specified group")
996 N_("Delete specified group"),
997 N_("net rap group delete\n"
998 " Delete specified group")
1000 {NULL
, NULL
, 0, NULL
, NULL
}
1004 struct cli_state
*cli
;
1006 if (c
->display_usage
) {
1007 d_printf(_("Usage:\n"));
1008 d_printf(_("net rap group\n"
1009 " List all groups\n"));
1010 net_display_usage_from_functable(func
);
1014 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1016 if (c
->opt_long_list_entries
) {
1017 d_printf(_("Group name Comment\n"
1018 "-----------------------------\n"));
1019 ret
= cli_RNetGroupEnum(cli
, long_group_fn
, NULL
);
1023 ret
= cli_RNetGroupEnum0(cli
, group_fn
, NULL
);
1028 return net_run_function(c
, argc
, argv
, "net rap group", func
);
1031 int net_rap_groupmember_usage(struct net_context
*c
, int argc
, const char **argv
)
1034 "net rap groupmember LIST <group> [misc. options] [targets]"
1035 "\n\t Enumerate users in a group\n"
1036 "\nnet rap groupmember DELETE <group> <user> [misc. options] "
1037 "[targets]\n\t Delete specified user from specified group\n"
1038 "\nnet rap groupmember ADD <group> <user> [misc. options] [targets]"
1039 "\n\t Add specified user to specified group\n"));
1041 net_common_flags_usage(c
, argc
, argv
);
1046 static int rap_groupmember_add(struct net_context
*c
, int argc
, const char **argv
)
1048 struct cli_state
*cli
;
1050 if (argc
!= 2 || c
->display_usage
) {
1051 return net_rap_groupmember_usage(c
, argc
, argv
);
1054 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1057 ret
= cli_NetGroupAddUser(cli
, argv
[0], argv
[1]);
1062 static int rap_groupmember_delete(struct net_context
*c
, int argc
, const char **argv
)
1064 struct cli_state
*cli
;
1066 if (argc
!= 2 || c
->display_usage
) {
1067 return net_rap_groupmember_usage(c
, argc
, argv
);
1070 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1073 ret
= cli_NetGroupDelUser(cli
, argv
[0], argv
[1]);
1078 static int rap_groupmember_list(struct net_context
*c
, int argc
, const char **argv
)
1080 struct cli_state
*cli
;
1082 if (argc
== 0 || c
->display_usage
) {
1083 return net_rap_groupmember_usage(c
, argc
, argv
);
1086 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1089 ret
= cli_NetGroupGetUsers(cli
, argv
[0], group_member_fn
, NULL
);
1094 int net_rap_groupmember(struct net_context
*c
, int argc
, const char **argv
)
1096 struct functable func
[] = {
1099 rap_groupmember_add
,
1101 N_("Add specified user to group"),
1102 N_("net rap groupmember add\n"
1103 " Add specified user to group")
1107 rap_groupmember_list
,
1109 N_("List users in group"),
1110 N_("net rap groupmember list\n"
1111 " List users in group")
1115 rap_groupmember_delete
,
1117 N_("Remove user from group"),
1118 N_("net rap groupmember delete\n"
1119 " Remove user from group")
1121 {NULL
, NULL
, 0, NULL
, NULL
}
1124 return net_run_function(c
, argc
, argv
, "net rap groupmember", func
);
1127 int net_rap_validate_usage(struct net_context
*c
, int argc
, const char **argv
)
1129 d_printf(_("net rap validate <username> [password]\n"
1130 "\tValidate user and password to check whether they"
1131 " can access target server or domain\n"));
1133 net_common_flags_usage(c
, argc
, argv
);
1137 int net_rap_validate(struct net_context
*c
, int argc
, const char **argv
)
1139 return errmsg_not_implemented();
1142 int net_rap_service_usage(struct net_context
*c
, int argc
, const char **argv
)
1144 d_printf(_("net rap service [misc. options] [targets] \n"
1145 "\tlists all running service daemons on target server\n"));
1146 d_printf(_("\nnet rap service START <name> [service startup arguments]"
1147 " [misc. options] [targets]"
1148 "\n\tStart named service on remote server\n"));
1149 d_printf(_("\nnet rap service STOP <name> [misc. options] [targets]\n"
1150 "\n\tStop named service on remote server\n"));
1152 net_common_flags_usage(c
, argc
, argv
);
1156 static int rap_service_start(struct net_context
*c
, int argc
, const char **argv
)
1158 return errmsg_not_implemented();
1161 static int rap_service_stop(struct net_context
*c
, int argc
, const char **argv
)
1163 return errmsg_not_implemented();
1166 static void service_fn(const char *service_name
, const char *dummy
,
1169 d_printf("%-21.21s\n", service_name
);
1172 int net_rap_service(struct net_context
*c
, int argc
, const char **argv
)
1174 struct functable func
[] = {
1179 N_("Start service on remote server"),
1180 N_("net rap service start\n"
1181 " Start service on remote server")
1187 N_("Stop named serve on remote server"),
1188 N_("net rap service stop\n"
1189 " Stop named serve on remote server")
1191 {NULL
, NULL
, 0, NULL
, NULL
}
1195 struct cli_state
*cli
;
1197 if (c
->display_usage
) {
1198 d_printf(_("Usage:\n"));
1199 d_printf(_("net rap service\n"
1200 " List services on remote server\n"));
1201 net_display_usage_from_functable(func
);
1205 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1208 if (c
->opt_long_list_entries
) {
1209 d_printf(_("Service name Comment\n"
1210 "-----------------------------\n"));
1211 ret
= cli_RNetServiceEnum(cli
, long_group_fn
, NULL
);
1213 ret
= cli_RNetServiceEnum(cli
, service_fn
, NULL
);
1218 return net_run_function(c
, argc
, argv
, "net rap service", func
);
1221 int net_rap_password_usage(struct net_context
*c
, int argc
, const char **argv
)
1224 "net rap password <user> <oldpwo> <newpw> [misc. options] [target]\n"
1225 "\tchanges the password for the specified user at target\n"));
1231 int net_rap_password(struct net_context
*c
, int argc
, const char **argv
)
1233 struct cli_state
*cli
;
1236 if (argc
< 3 || c
->display_usage
)
1237 return net_rap_password_usage(c
, argc
, argv
);
1239 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1242 /* BB Add check for password lengths? */
1243 ret
= cli_oem_change_password(cli
, argv
[0], argv
[2], argv
[1]);
1248 int net_rap_admin_usage(struct net_context
*c
, int argc
, const char **argv
)
1251 "net rap admin <remote command> [cmd args [env]] [misc. options] [targets]"
1252 "\n\texecutes a remote command on an os/2 target server\n"));
1258 int net_rap_admin(struct net_context
*c
, int argc
, const char **argv
)
1260 return errmsg_not_implemented();
1263 /* Entry-point for all the RAP functions. */
1265 int net_rap(struct net_context
*c
, int argc
, const char **argv
)
1267 struct functable func
[] = {
1272 N_("List open files"),
1280 N_("List shares exported by server"),
1281 N_("net rap share\n"
1282 " List shares exported by server")
1288 N_("List open sessions"),
1289 N_("net rap session\n"
1290 " List open sessions")
1296 N_("List servers in workgroup"),
1297 N_("net rap server\n"
1298 " List servers in domain/workgroup")
1304 N_("List domains in network"),
1305 N_("net rap domain\n"
1306 " List domains in network")
1312 N_("List printer queues on server"),
1313 N_("net rap printq\n"
1314 " List printer queues on server")
1328 N_("List user groups"),
1329 N_("net rap group\n"
1330 " List user groups")
1336 N_("Check username/password"),
1337 N_("net rap validate\n"
1338 " Check username/password")
1342 net_rap_groupmember
,
1344 N_("List/modify group memberships"),
1345 N_("net rap groupmember\n"
1346 " List/modify group memberships")
1352 N_("Execute commands on remote OS/2"),
1353 N_("net rap admin\n"
1354 " Execute commands on remote OS/2")
1360 N_("Start/stop remote service"),
1361 N_("net rap service\n"
1362 " Start/stop remote service")
1368 N_("Change user password"),
1369 N_("net rap password\n"
1370 " Change user password")
1372 {NULL
, NULL
, 0, NULL
, NULL
}
1375 return net_run_function(c
, argc
, argv
, "net rap", func
);