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 "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 static int errmsg_not_implemented(void)
40 d_printf(_("\nNot implemented\n"));
44 int net_rap_file_usage(struct net_context
*c
, int argc
, const char **argv
)
46 return net_file_usage(c
, argc
, argv
);
49 /***************************************************************************
50 list info on an open file
51 ***************************************************************************/
52 static void file_fn(const char * pPath
, const char * pUser
, uint16 perms
,
53 uint16 locks
, uint32 id
)
55 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
56 id
, pUser
, perms
, locks
, pPath
);
59 static void one_file_fn(const char *pPath
, const char *pUser
, uint16 perms
,
60 uint16 locks
, uint32 id
)
62 d_printf(_("File ID %d\n"
66 "Permissions 0x%x\n"),
67 id
, pUser
, locks
, pPath
, perms
);
71 static int rap_file_close(struct net_context
*c
, int argc
, const char **argv
)
73 struct cli_state
*cli
;
75 if (argc
== 0 || c
->display_usage
) {
76 return net_rap_file_usage(c
, argc
, argv
);
79 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
82 ret
= cli_NetFileClose(cli
, atoi(argv
[0]));
87 static int rap_file_info(struct net_context
*c
, int argc
, const char **argv
)
89 struct cli_state
*cli
;
91 if (argc
== 0 || c
->display_usage
)
92 return net_rap_file_usage(c
, argc
, argv
);
94 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
97 ret
= cli_NetFileGetInfo(cli
, atoi(argv
[0]), one_file_fn
);
102 static int rap_file_user(struct net_context
*c
, int argc
, const char **argv
)
104 struct cli_state
*cli
;
107 if (argc
== 0 || c
->display_usage
)
108 return net_rap_file_usage(c
, argc
, argv
);
110 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
113 /* list open files */
115 d_printf(_("\nEnumerating open files on remote server:\n\n"
116 "\nFileId Opened by Perms Locks Path \n"
117 "------ --------- ----- ----- ---- \n"));
118 ret
= cli_NetFileEnum(cli
, argv
[0], NULL
, file_fn
);
121 d_printf(_("\nOperation not supported by server!\n\n"));
127 int net_rap_file(struct net_context
*c
, int argc
, const char **argv
)
129 struct functable func
[] = {
134 N_("Close specified file on server"),
135 N_("net rap file close\n"
136 " Close specified file on server")
142 N_("List all files opened by username"),
143 N_("net rap file user\n"
144 " List all files opened by username")
150 N_("Display info about an opened file"),
151 N_("net rap file info\n"
152 " Display info about an opened file")
154 {NULL
, NULL
, 0, NULL
, NULL
}
158 struct cli_state
*cli
;
161 if (c
->display_usage
) {
162 d_printf(_("Usage:\n"));
163 d_printf(_("net rap file\n"
164 " List all open files on rempte "
166 net_display_usage_from_functable(func
);
170 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
173 /* list open files */
175 d_printf(_("\nEnumerating open files on remote server:\n\n"
176 "\nFileId Opened by Perms Locks Path\n"
177 "------ --------- ----- ----- ----\n"));
178 ret
= cli_NetFileEnum(cli
, NULL
, NULL
, file_fn
);
181 d_printf(_("\nOperation not supported by server!\n\n"));
187 return net_run_function(c
, argc
, argv
, "net rap file", func
);
190 int net_rap_share_usage(struct net_context
*c
, int argc
, const char **argv
)
192 return net_share_usage(c
, argc
, argv
);
195 static void long_share_fn(const char *share_name
, uint32 type
,
196 const char *comment
, void *state
)
198 d_printf("%-12s %-8.8s %-50s\n",
199 share_name
, net_share_type_str(type
), comment
);
202 static void share_fn(const char *share_name
, uint32 type
,
203 const char *comment
, void *state
)
205 d_printf("%s\n", share_name
);
208 static int rap_share_delete(struct net_context
*c
, int argc
, const char **argv
)
210 struct cli_state
*cli
;
213 if (argc
== 0 || c
->display_usage
) {
214 return net_rap_share_usage(c
, argc
, argv
);
217 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
220 ret
= cli_NetShareDelete(cli
, argv
[0]);
225 static int rap_share_add(struct net_context
*c
, int argc
, const char **argv
)
227 struct cli_state
*cli
;
230 struct rap_share_info_2 sinfo
;
234 if (argc
== 0 || c
->display_usage
) {
235 return net_rap_share_usage(c
, argc
, argv
);
238 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
241 sharename
= SMB_STRDUP(argv
[0]);
242 p
= strchr(sharename
, '=');
244 d_printf(_("Server path not specified\n"));
245 SAFE_FREE(sharename
);
246 return net_rap_share_usage(c
, argc
, argv
);
249 strlcpy((char *)sinfo
.share_name
, sharename
, sizeof(sinfo
.share_name
));
250 sinfo
.reserved1
= '\0';
251 sinfo
.share_type
= 0;
252 sinfo
.comment
= c
->opt_comment
? smb_xstrdup(c
->opt_comment
) : "";
254 sinfo
.maximum_users
= c
->opt_maxusers
;
255 sinfo
.active_users
= 0;
257 memset(sinfo
.password
, '\0', sizeof(sinfo
.password
));
258 sinfo
.reserved2
= '\0';
260 ret
= cli_NetShareAdd(cli
, &sinfo
);
262 SAFE_FREE(sharename
);
267 int net_rap_share(struct net_context
*c
, int argc
, const char **argv
)
269 struct functable func
[] = {
274 N_("Delete a share from server"),
275 N_("net rap share delete\n"
276 " Delete a share from server")
282 N_("Delete a share from server"),
283 N_("net rap share close\n"
284 " Delete a share from server\n"
285 " Alias for net rap share delete")
291 N_("Add a share to server"),
292 N_("net rap share add\n"
293 " Add a share to server")
295 {NULL
, NULL
, 0, NULL
, NULL
}
299 struct cli_state
*cli
;
302 if (c
->display_usage
) {
303 d_printf(_("Usage:\n"));
304 d_printf(_("net rap share\n"
305 " List all shares on remote server\n"));
306 net_display_usage_from_functable(func
);
310 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
313 if (c
->opt_long_list_entries
) {
315 "\nEnumerating shared resources (exports) on remote server:\n\n"
316 "\nShare name Type Description\n"
317 "---------- ---- -----------\n"));
318 ret
= cli_RNetShareEnum(cli
, long_share_fn
, NULL
);
320 ret
= cli_RNetShareEnum(cli
, share_fn
, NULL
);
326 return net_run_function(c
, argc
, argv
, "net rap share", func
);
329 int net_rap_session_usage(struct net_context
*c
, int argc
, const char **argv
)
332 "\nnet rap session [misc. options] [targets]"
333 "\n\tenumerates all active SMB/CIFS sessions on target server\n"));
335 "\nnet rap session DELETE <client_name> [misc. options] [targets] \n"
337 "\nnet rap session CLOSE <client_name> [misc. options] [targets]"
338 "\n\tDeletes (closes) a session from specified client to server\n"));
340 "\nnet rap session INFO <client_name>"
341 "\n\tEnumerates all open files in specified session\n"));
343 net_common_flags_usage(c
, argc
, argv
);
347 static void list_sessions_func(char *wsname
, char *username
, uint16 conns
,
348 uint16 opens
, uint16 users
, uint32 sess_time
,
349 uint32 idle_time
, uint32 user_flags
, char *clitype
)
351 int hrs
= idle_time
/ 3600;
352 int min
= (idle_time
/ 60) % 60;
353 int sec
= idle_time
% 60;
355 d_printf("\\\\%-18.18s %-20.20s %-18.18s %5d %2.2d:%2.2d:%2.2d\n",
356 wsname
, username
, clitype
, opens
, hrs
, min
, sec
);
359 static void display_session_func(const char *wsname
, const char *username
,
360 uint16 conns
, uint16 opens
, uint16 users
,
361 uint32 sess_time
, uint32 idle_time
,
362 uint32 user_flags
, const char *clitype
)
364 int ihrs
= idle_time
/ 3600;
365 int imin
= (idle_time
/ 60) % 60;
366 int isec
= idle_time
% 60;
367 int shrs
= sess_time
/ 3600;
368 int smin
= (sess_time
/ 60) % 60;
369 int ssec
= sess_time
% 60;
370 d_printf(_("User name %-20.20s\n"
371 "Computer %-20.20s\n"
372 "Guest logon %-20.20s\n"
373 "Client Type %-40.40s\n"
374 "Sess time %2.2d:%2.2d:%2.2d\n"
375 "Idle time %2.2d:%2.2d:%2.2d\n"),
377 (user_flags
&0x0)?_("yes"):_("no"), clitype
,
378 shrs
, smin
, ssec
, ihrs
, imin
, isec
);
381 static void display_conns_func(uint16 conn_id
, uint16 conn_type
, uint16 opens
,
382 uint16 users
, uint32 conn_time
,
383 const char *username
, const char *netname
)
385 d_printf("%-14.14s %-8.8s %5d\n",
386 netname
, net_share_type_str(conn_type
), opens
);
389 static int rap_session_info(struct net_context
*c
, int argc
, const char **argv
)
391 const char *sessname
;
392 struct cli_state
*cli
;
395 if (argc
== 0 || c
->display_usage
)
396 return net_rap_session_usage(c
, argc
, argv
);
398 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
403 ret
= cli_NetSessionGetInfo(cli
, sessname
, display_session_func
);
409 d_printf(_("Share name Type # Opens\n-------------------------"
410 "-----------------------------------------------------\n"));
411 ret
= cli_NetConnectionEnum(cli
, sessname
, display_conns_func
);
416 static int rap_session_delete(struct net_context
*c
, int argc
, const char **argv
)
418 struct cli_state
*cli
;
421 if (argc
== 0 || c
->display_usage
)
422 return net_rap_session_usage(c
, argc
, argv
);
424 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
427 ret
= cli_NetSessionDel(cli
, argv
[0]);
432 int net_rap_session(struct net_context
*c
, int argc
, const char **argv
)
434 struct functable func
[] = {
439 N_("Display information about session"),
440 N_("net rap session info\n"
441 " Display information about session")
447 N_("Close specified session"),
448 N_("net rap session delete\n"
449 " Close specified session\n"
450 " Alias for net rap session close")
456 N_("Close specified session"),
457 N_("net rap session close\n"
458 " Close specified session")
460 {NULL
, NULL
, 0, NULL
, NULL
}
464 struct cli_state
*cli
;
467 if (c
->display_usage
) {
468 d_printf(_("Usage:\n"));
469 d_printf(_("net rap session\n"
470 " List all open sessions on remote "
472 net_display_usage_from_functable(func
);
476 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
479 d_printf(_("Computer User name "
480 "Client Type Opens Idle time\n"
481 "------------------------------------------"
482 "------------------------------------\n"));
483 ret
= cli_NetSessionEnum(cli
, list_sessions_func
);
489 return net_run_function(c
, argc
, argv
, "net rap session", func
);
492 /****************************************************************************
494 ****************************************************************************/
495 static void display_server_func(const char *name
, uint32 m
,
496 const char *comment
, void * reserved
)
498 d_printf("\t%-16.16s %s\n", name
, comment
);
501 static int net_rap_server_name(struct net_context
*c
, int argc
, const char *argv
[])
503 struct cli_state
*cli
;
506 if (c
->display_usage
) {
509 _("net rap server name\n"
510 " Get the name of the server\n"));
514 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
517 if (!cli_get_server_name(NULL
, cli
, &name
)) {
518 d_fprintf(stderr
, _("cli_get_server_name failed\n"));
523 d_printf(_("Server name = %s\n"), name
);
530 static int net_rap_server_domain(struct net_context
*c
, int argc
,
533 struct cli_state
*cli
;
536 if (c
->display_usage
) {
539 _("net rap server domain\n"
540 " Enumerate servers in this domain/workgroup\n"));
544 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
547 d_printf(_("\nEnumerating servers in this domain or workgroup: \n\n"
548 "\tServer name Server description\n"
549 "\t------------- ----------------------------\n"));
551 ret
= cli_NetServerEnum(cli
, cli
->server_domain
, SV_TYPE_ALL
,
552 display_server_func
,NULL
);
557 int net_rap_server(struct net_context
*c
, int argc
, const char **argv
)
559 struct functable func
[] = {
564 N_("Get the name of the server"),
565 N_("net rap server name\n"
566 " Get the name of the server")
570 net_rap_server_domain
,
572 N_("Get the servers in this domain/workgroup"),
573 N_("net rap server domain\n"
574 " Get the servers in this domain/workgroup")
576 {NULL
, NULL
, 0, NULL
, NULL
}
579 /* smb4k uses 'net [rap|rpc] server domain' to query servers in a domain */
580 /* Fall through for 'domain', any other forms will cause to show usage message */
581 return net_run_function(c
, argc
, argv
, "net rap server", func
);
585 int net_rap_domain_usage(struct net_context
*c
, int argc
, const char **argv
)
587 d_printf(_("net rap domain [misc. options] [target]\n\tlists the"
588 " domains or workgroups visible on the current network\n"));
590 net_common_flags_usage(c
, argc
, argv
);
594 int net_rap_domain(struct net_context
*c
, int argc
, const char **argv
)
596 struct cli_state
*cli
;
599 if (c
->display_usage
)
600 return net_rap_domain_usage(c
, argc
, argv
);
602 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
605 d_printf(_("\nEnumerating domains:\n\n"
606 "\tDomain name Server name of Browse Master\n"
607 "\t------------- ----------------------------\n"));
609 ret
= cli_NetServerEnum(cli
, cli
->server_domain
, SV_TYPE_DOMAIN_ENUM
,
610 display_server_func
,NULL
);
615 int net_rap_printq_usage(struct net_context
*c
, int argc
, const char **argv
)
618 "net rap printq [misc. options] [targets]\n"
620 "net rap printq info [<queue_name>] [misc. options] [targets]\n"
621 "\tlists the specified queue and jobs on the target server.\n"
622 "\tIf the queue name is not specified, all queues are listed.\n\n"));
624 "net rap printq delete [<queue name>] [misc. options] [targets]\n"
625 "\tdeletes the specified job number on the target server, or the\n"
626 "\tprinter queue if no job number is specified\n"));
628 net_common_flags_usage(c
, argc
, argv
);
633 static void enum_queue(const char *queuename
, uint16 pri
, uint16 start
,
634 uint16 until
, const char *sep
, const char *pproc
,
635 const char *dest
, const char *qparms
,
636 const char *qcomment
, uint16 status
, uint16 jobcount
)
638 d_printf(_("%-17.17s Queue %5d jobs "),
639 queuename
, jobcount
);
643 d_printf(_("*Printer Active*\n"));
646 d_printf(_("*Printer Paused*\n"));
649 d_printf(_("*Printer error*\n"));
652 d_printf(_("*Delete Pending*\n"));
655 d_printf(_("**UNKNOWN STATUS**\n"));
659 static void enum_jobs(uint16 jobid
, const char *ownername
,
660 const char *notifyname
, const char *datatype
,
661 const char *jparms
, uint16 pos
, uint16 status
,
662 const char *jstatus
, unsigned int submitted
, unsigned int jobsize
,
665 d_printf(" %-23.23s %5d %9d ",
666 ownername
, jobid
, jobsize
);
669 d_printf(_("Waiting\n"));
672 d_printf(_("Held in queue\n"));
675 d_printf(_("Spooling\n"));
678 d_printf(_("Printing\n"));
681 d_printf(_("**UNKNOWN STATUS**\n"));
685 #define PRINTQ_ENUM_DISPLAY \
686 _("Print queues at \\\\%s\n\n"\
687 "Name Job # Size Status\n\n"\
688 "------------------------------------------------------------------"\
691 static int rap_printq_info(struct net_context
*c
, int argc
, const char **argv
)
693 struct cli_state
*cli
;
696 if (argc
== 0 || c
->display_usage
)
697 return net_rap_printq_usage(c
, argc
, argv
);
699 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
702 d_printf(PRINTQ_ENUM_DISPLAY
, cli
->desthost
); /* list header */
703 ret
= cli_NetPrintQGetInfo(cli
, argv
[0], enum_queue
, enum_jobs
);
708 static int rap_printq_delete(struct net_context
*c
, int argc
, const char **argv
)
710 struct cli_state
*cli
;
713 if (argc
== 0 || c
->display_usage
)
714 return net_rap_printq_usage(c
, argc
, argv
);
716 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
719 ret
= cli_printjob_del(cli
, atoi(argv
[0]));
724 int net_rap_printq(struct net_context
*c
, int argc
, const char **argv
)
726 struct cli_state
*cli
;
729 struct functable func
[] = {
734 N_("Display info about print queues and jobs"),
735 N_("net rap printq info [queue]\n"
736 " Display info about print jobs in queue.\n"
737 " If queue is not specified, all queues are "
744 N_("Delete print job(s)"),
745 N_("net rap printq delete\n"
746 " Delete print job(s)")
748 {NULL
, NULL
, 0, NULL
, NULL
}
752 if (c
->display_usage
) {
753 d_printf(_("Usage:\n"));
754 d_printf(_("net rap printq\n"
755 " List the print queue\n"));
756 net_display_usage_from_functable(func
);
760 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
763 d_printf(PRINTQ_ENUM_DISPLAY
, cli
->desthost
); /* list header */
764 ret
= cli_NetPrintQEnum(cli
, enum_queue
, enum_jobs
);
769 return net_run_function(c
, argc
, argv
, "net rap printq", func
);
772 static int net_rap_user_usage(struct net_context
*c
, int argc
, const char **argv
)
774 return net_user_usage(c
, argc
, argv
);
777 static void user_fn(const char *user_name
, void *state
)
779 d_printf("%-21.21s\n", user_name
);
782 static void long_user_fn(const char *user_name
, const char *comment
,
783 const char * home_dir
, const char * logon_script
,
786 d_printf("%-21.21s %s\n",
790 static void group_member_fn(const char *user_name
, void *state
)
792 d_printf("%-21.21s\n", user_name
);
795 static int rap_user_delete(struct net_context
*c
, int argc
, const char **argv
)
797 struct cli_state
*cli
;
800 if (argc
== 0 || c
->display_usage
) {
801 return net_rap_user_usage(c
, argc
, argv
);
804 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
807 ret
= cli_NetUserDelete(cli
, argv
[0]);
812 static int rap_user_add(struct net_context
*c
, int argc
, const char **argv
)
814 struct cli_state
*cli
;
816 struct rap_user_info_1 userinfo
;
818 if (argc
== 0 || c
->display_usage
) {
819 return net_rap_user_usage(c
, argc
, argv
);
822 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
825 safe_strcpy((char *)userinfo
.user_name
, argv
[0], sizeof(userinfo
.user_name
)-1);
826 if (c
->opt_flags
== -1)
829 userinfo
.userflags
= c
->opt_flags
;
830 userinfo
.reserved1
= '\0';
831 userinfo
.comment
= smb_xstrdup(c
->opt_comment
? c
->opt_comment
: "");
833 userinfo
.home_dir
= NULL
;
834 userinfo
.logon_script
= NULL
;
835 userinfo
.passwrd
[0] = '\0';
837 ret
= cli_NetUserAdd(cli
, &userinfo
);
843 static int rap_user_info(struct net_context
*c
, int argc
, const char **argv
)
845 struct cli_state
*cli
;
847 if (argc
== 0 || c
->display_usage
) {
848 return net_rap_user_usage(c
, argc
, argv
);
851 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
854 ret
= cli_NetUserGetGroups(cli
, argv
[0], group_member_fn
, NULL
);
859 int net_rap_user(struct net_context
*c
, int argc
, const char **argv
)
862 struct functable func
[] = {
867 N_("Add specified user"),
868 N_("net rap user add\n"
869 " Add specified user")
875 N_("List domain groups of specified user"),
876 N_("net rap user info\n"
877 " List domain groups of specified user")
884 N_("Remove specified user"),
885 N_("net rap user delete\n"
886 " Remove specified user")
888 {NULL
, NULL
, 0, NULL
, NULL
}
892 struct cli_state
*cli
;
893 if (c
->display_usage
) {
894 d_printf(_("Usage:\n"));
895 d_printf(_("net rap user\n"
896 " List all users\n"));
897 net_display_usage_from_functable(func
);
901 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
903 if (c
->opt_long_list_entries
) {
904 d_printf(_("\nUser name Comment"
905 "\n-----------------------------\n"));
906 ret
= cli_RNetUserEnum(cli
, long_user_fn
, NULL
);
910 ret
= cli_RNetUserEnum0(cli
, user_fn
, NULL
);
915 ret
= net_run_function(c
, argc
, argv
, "net rap user", func
);
918 DEBUG(1, (_("Net user returned: %d\n"), ret
));
924 int net_rap_group_usage(struct net_context
*c
, int argc
, const char **argv
)
926 return net_group_usage(c
, argc
, argv
);
929 static void long_group_fn(const char *group_name
, const char *comment
,
932 d_printf("%-21.21s %s\n", group_name
, comment
);
935 static void group_fn(const char *group_name
, void *state
)
937 d_printf("%-21.21s\n", group_name
);
940 static int rap_group_delete(struct net_context
*c
, int argc
, const char **argv
)
942 struct cli_state
*cli
;
944 if (argc
== 0 || c
->display_usage
) {
945 return net_rap_group_usage(c
, argc
, argv
);
948 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
951 ret
= cli_NetGroupDelete(cli
, argv
[0]);
956 static int rap_group_add(struct net_context
*c
, int argc
, const char **argv
)
958 struct cli_state
*cli
;
960 struct rap_group_info_1 grinfo
;
962 if (argc
== 0 || c
->display_usage
) {
963 return net_rap_group_usage(c
, argc
, argv
);
966 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
969 /* BB check for length 21 or smaller explicitly ? BB */
970 safe_strcpy((char *)grinfo
.group_name
, argv
[0], sizeof(grinfo
.group_name
)-1);
971 grinfo
.reserved1
= '\0';
972 grinfo
.comment
= smb_xstrdup(c
->opt_comment
? c
->opt_comment
: "");
974 ret
= cli_NetGroupAdd(cli
, &grinfo
);
979 int net_rap_group(struct net_context
*c
, int argc
, const char **argv
)
981 struct functable func
[] = {
986 N_("Add specified group"),
987 N_("net rap group add\n"
988 " Add specified group")
994 N_("Delete specified group"),
995 N_("net rap group delete\n"
996 " Delete specified group")
998 {NULL
, NULL
, 0, NULL
, NULL
}
1002 struct cli_state
*cli
;
1004 if (c
->display_usage
) {
1005 d_printf(_("Usage:\n"));
1006 d_printf(_("net rap group\n"
1007 " List all groups\n"));
1008 net_display_usage_from_functable(func
);
1012 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1014 if (c
->opt_long_list_entries
) {
1015 d_printf(_("Group name Comment\n"
1016 "-----------------------------\n"));
1017 ret
= cli_RNetGroupEnum(cli
, long_group_fn
, NULL
);
1021 ret
= cli_RNetGroupEnum0(cli
, group_fn
, NULL
);
1026 return net_run_function(c
, argc
, argv
, "net rap group", func
);
1029 int net_rap_groupmember_usage(struct net_context
*c
, int argc
, const char **argv
)
1032 "net rap groupmember LIST <group> [misc. options] [targets]"
1033 "\n\t Enumerate users in a group\n"
1034 "\nnet rap groupmember DELETE <group> <user> [misc. options] "
1035 "[targets]\n\t Delete specified user from specified group\n"
1036 "\nnet rap groupmember ADD <group> <user> [misc. options] [targets]"
1037 "\n\t Add specified user to specified group\n"));
1039 net_common_flags_usage(c
, argc
, argv
);
1044 static int rap_groupmember_add(struct net_context
*c
, int argc
, const char **argv
)
1046 struct cli_state
*cli
;
1048 if (argc
!= 2 || c
->display_usage
) {
1049 return net_rap_groupmember_usage(c
, argc
, argv
);
1052 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1055 ret
= cli_NetGroupAddUser(cli
, argv
[0], argv
[1]);
1060 static int rap_groupmember_delete(struct net_context
*c
, int argc
, const char **argv
)
1062 struct cli_state
*cli
;
1064 if (argc
!= 2 || c
->display_usage
) {
1065 return net_rap_groupmember_usage(c
, argc
, argv
);
1068 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1071 ret
= cli_NetGroupDelUser(cli
, argv
[0], argv
[1]);
1076 static int rap_groupmember_list(struct net_context
*c
, int argc
, const char **argv
)
1078 struct cli_state
*cli
;
1080 if (argc
== 0 || c
->display_usage
) {
1081 return net_rap_groupmember_usage(c
, argc
, argv
);
1084 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1087 ret
= cli_NetGroupGetUsers(cli
, argv
[0], group_member_fn
, NULL
);
1092 int net_rap_groupmember(struct net_context
*c
, int argc
, const char **argv
)
1094 struct functable func
[] = {
1097 rap_groupmember_add
,
1099 N_("Add specified user to group"),
1100 N_("net rap groupmember add\n"
1101 " Add specified user to group")
1105 rap_groupmember_list
,
1107 N_("List users in group"),
1108 N_("net rap groupmember list\n"
1109 " List users in group")
1113 rap_groupmember_delete
,
1115 N_("Remove user from group"),
1116 N_("net rap groupmember delete\n"
1117 " Remove user from group")
1119 {NULL
, NULL
, 0, NULL
, NULL
}
1122 return net_run_function(c
, argc
, argv
, "net rap groupmember", func
);
1125 int net_rap_validate_usage(struct net_context
*c
, int argc
, const char **argv
)
1127 d_printf(_("net rap validate <username> [password]\n"
1128 "\tValidate user and password to check whether they"
1129 " can access target server or domain\n"));
1131 net_common_flags_usage(c
, argc
, argv
);
1135 int net_rap_validate(struct net_context
*c
, int argc
, const char **argv
)
1137 return errmsg_not_implemented();
1140 int net_rap_service_usage(struct net_context
*c
, int argc
, const char **argv
)
1142 d_printf(_("net rap service [misc. options] [targets] \n"
1143 "\tlists all running service daemons on target server\n"));
1144 d_printf(_("\nnet rap service START <name> [service startup arguments]"
1145 " [misc. options] [targets]"
1146 "\n\tStart named service on remote server\n"));
1147 d_printf(_("\nnet rap service STOP <name> [misc. options] [targets]\n"
1148 "\n\tStop named service on remote server\n"));
1150 net_common_flags_usage(c
, argc
, argv
);
1154 static int rap_service_start(struct net_context
*c
, int argc
, const char **argv
)
1156 return errmsg_not_implemented();
1159 static int rap_service_stop(struct net_context
*c
, int argc
, const char **argv
)
1161 return errmsg_not_implemented();
1164 static void service_fn(const char *service_name
, const char *dummy
,
1167 d_printf("%-21.21s\n", service_name
);
1170 int net_rap_service(struct net_context
*c
, int argc
, const char **argv
)
1172 struct functable func
[] = {
1177 N_("Start service on remote server"),
1178 N_("net rap service start\n"
1179 " Start service on remote server")
1185 N_("Stop named serve on remote server"),
1186 N_("net rap service stop\n"
1187 " Stop named serve on remote server")
1189 {NULL
, NULL
, 0, NULL
, NULL
}
1193 struct cli_state
*cli
;
1195 if (c
->display_usage
) {
1196 d_printf(_("Usage:\n"));
1197 d_printf(_("net rap service\n"
1198 " List services on remote server\n"));
1199 net_display_usage_from_functable(func
);
1203 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1206 if (c
->opt_long_list_entries
) {
1207 d_printf(_("Service name Comment\n"
1208 "-----------------------------\n"));
1209 ret
= cli_RNetServiceEnum(cli
, long_group_fn
, NULL
);
1211 ret
= cli_RNetServiceEnum(cli
, service_fn
, NULL
);
1216 return net_run_function(c
, argc
, argv
, "net rap service", func
);
1219 int net_rap_password_usage(struct net_context
*c
, int argc
, const char **argv
)
1222 "net rap password <user> <oldpwo> <newpw> [misc. options] [target]\n"
1223 "\tchanges the password for the specified user at target\n"));
1229 int net_rap_password(struct net_context
*c
, int argc
, const char **argv
)
1231 struct cli_state
*cli
;
1234 if (argc
< 3 || c
->display_usage
)
1235 return net_rap_password_usage(c
, argc
, argv
);
1237 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1240 /* BB Add check for password lengths? */
1241 ret
= cli_oem_change_password(cli
, argv
[0], argv
[2], argv
[1]);
1246 int net_rap_admin_usage(struct net_context
*c
, int argc
, const char **argv
)
1249 "net rap admin <remote command> [cmd args [env]] [misc. options] [targets]"
1250 "\n\texecutes a remote command on an os/2 target server\n"));
1256 int net_rap_admin(struct net_context
*c
, int argc
, const char **argv
)
1258 return errmsg_not_implemented();
1261 /* Entry-point for all the RAP functions. */
1263 int net_rap(struct net_context
*c
, int argc
, const char **argv
)
1265 struct functable func
[] = {
1270 N_("List open files"),
1278 N_("List shares exported by server"),
1279 N_("net rap share\n"
1280 " List shares exported by server")
1286 N_("List open sessions"),
1287 N_("net rap session\n"
1288 " List open sessions")
1294 N_("List servers in workgroup"),
1295 N_("net rap server\n"
1296 " List servers in domain/workgroup")
1302 N_("List domains in network"),
1303 N_("net rap domain\n"
1304 " List domains in network")
1310 N_("List printer queues on server"),
1311 N_("net rap printq\n"
1312 " List printer queues on server")
1326 N_("List user groups"),
1327 N_("net rap group\n"
1328 " List user groups")
1334 N_("Check username/password"),
1335 N_("net rap validate\n"
1336 " Check username/password")
1340 net_rap_groupmember
,
1342 N_("List/modify group memberships"),
1343 N_("net rap groupmember\n"
1344 " List/modify group memberships")
1350 N_("Execute commands on remote OS/2"),
1351 N_("net rap admin\n"
1352 " Execute commands on remote OS/2")
1358 N_("Start/stop remote service"),
1359 N_("net rap service\n"
1360 " Start/stop remote service")
1366 N_("Change user password"),
1367 N_("net rap password\n"
1368 " Change user password")
1370 {NULL
, NULL
, 0, NULL
, NULL
}
1373 return net_run_function(c
, argc
, argv
, "net rap", func
);