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"
31 #include "../libcli/smb/smbXcli_base.h"
33 /* The following messages were for error checking that is not properly
34 reported at the moment. Which should be reinstated? */
35 #define ERRMSG_TARGET_WG_NOT_VALID "\nTarget workgroup option not valid "\
36 "except on net rap server command, ignored"
37 #define ERRMSG_INVALID_HELP_OPTION "\nInvalid help option\n"
39 #define ERRMSG_BOTH_SERVER_IPADDRESS "\nTarget server and IP address both "\
40 "specified. Do not set both at the same time. The target IP address was used\n"
42 static int errmsg_not_implemented(void)
44 d_printf(_("\nNot implemented\n"));
48 int net_rap_file_usage(struct net_context
*c
, int argc
, const char **argv
)
50 return net_file_usage(c
, argc
, argv
);
53 /***************************************************************************
54 list info on an open file
55 ***************************************************************************/
56 static void file_fn(const char * pPath
, const char * pUser
, uint16_t perms
,
57 uint16_t locks
, uint32_t id
)
59 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
60 id
, pUser
, perms
, locks
, pPath
);
63 static void one_file_fn(const char *pPath
, const char *pUser
, uint16_t perms
,
64 uint16_t locks
, uint32_t id
)
66 d_printf(_("File ID %d\n"
70 "Permissions 0x%x\n"),
71 id
, pUser
, locks
, pPath
, perms
);
75 static int rap_file_close(struct net_context
*c
, int argc
, const char **argv
)
77 struct cli_state
*cli
;
79 if (argc
== 0 || c
->display_usage
) {
80 return net_rap_file_usage(c
, argc
, argv
);
83 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
86 ret
= cli_NetFileClose(cli
, atoi(argv
[0]));
91 static int rap_file_info(struct net_context
*c
, int argc
, const char **argv
)
93 struct cli_state
*cli
;
95 if (argc
== 0 || c
->display_usage
)
96 return net_rap_file_usage(c
, argc
, argv
);
98 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
101 ret
= cli_NetFileGetInfo(cli
, atoi(argv
[0]), one_file_fn
);
106 static int rap_file_user(struct net_context
*c
, int argc
, const char **argv
)
108 struct cli_state
*cli
;
111 if (argc
== 0 || c
->display_usage
)
112 return net_rap_file_usage(c
, argc
, argv
);
114 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
117 /* list open files */
119 d_printf(_("\nEnumerating open files on remote server:\n\n"
120 "\nFileId Opened by Perms Locks Path \n"
121 "------ --------- ----- ----- ---- \n"));
122 ret
= cli_NetFileEnum(cli
, argv
[0], NULL
, file_fn
);
125 d_printf(_("\nOperation not supported by server!\n\n"));
131 int net_rap_file(struct net_context
*c
, int argc
, const char **argv
)
133 struct functable func
[] = {
138 N_("Close specified file on server"),
139 N_("net rap file close\n"
140 " Close specified file on server")
146 N_("List all files opened by username"),
147 N_("net rap file user\n"
148 " List all files opened by username")
154 N_("Display info about an opened file"),
155 N_("net rap file info\n"
156 " Display info about an opened file")
158 {NULL
, NULL
, 0, NULL
, NULL
}
162 struct cli_state
*cli
;
165 if (c
->display_usage
) {
166 d_printf(_("Usage:\n"));
167 d_printf(_("net rap file\n"
168 " List all open files on rempte "
170 net_display_usage_from_functable(func
);
174 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
177 /* list open files */
179 d_printf(_("\nEnumerating open files on remote server:\n\n"
180 "\nFileId Opened by Perms Locks Path\n"
181 "------ --------- ----- ----- ----\n"));
182 ret
= cli_NetFileEnum(cli
, NULL
, NULL
, file_fn
);
185 d_printf(_("\nOperation not supported by server!\n\n"));
191 return net_run_function(c
, argc
, argv
, "net rap file", func
);
194 int net_rap_share_usage(struct net_context
*c
, int argc
, const char **argv
)
196 return net_share_usage(c
, argc
, argv
);
199 static void long_share_fn(const char *share_name
, uint32_t type
,
200 const char *comment
, void *state
)
202 d_printf("%-12s %-8.8s %-50s\n",
203 share_name
, net_share_type_str(type
), comment
);
206 static void share_fn(const char *share_name
, uint32_t type
,
207 const char *comment
, void *state
)
209 d_printf("%s\n", share_name
);
212 static int rap_share_delete(struct net_context
*c
, int argc
, const char **argv
)
214 struct cli_state
*cli
;
217 if (argc
== 0 || c
->display_usage
) {
218 return net_rap_share_usage(c
, argc
, argv
);
221 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
224 ret
= cli_NetShareDelete(cli
, argv
[0]);
229 static int rap_share_add(struct net_context
*c
, int argc
, const char **argv
)
231 struct cli_state
*cli
;
234 struct rap_share_info_2 sinfo
;
238 if (argc
== 0 || c
->display_usage
) {
239 return net_rap_share_usage(c
, argc
, argv
);
242 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
245 sharename
= SMB_STRDUP(argv
[0]);
246 p
= strchr(sharename
, '=');
248 d_printf(_("Server path not specified\n"));
249 SAFE_FREE(sharename
);
250 return net_rap_share_usage(c
, argc
, argv
);
253 strlcpy((char *)sinfo
.share_name
, sharename
, sizeof(sinfo
.share_name
));
254 sinfo
.reserved1
= '\0';
255 sinfo
.share_type
= 0;
256 sinfo
.comment
= c
->opt_comment
? smb_xstrdup(c
->opt_comment
) : "";
258 sinfo
.maximum_users
= c
->opt_maxusers
;
259 sinfo
.active_users
= 0;
261 memset(sinfo
.password
, '\0', sizeof(sinfo
.password
));
262 sinfo
.reserved2
= '\0';
264 ret
= cli_NetShareAdd(cli
, &sinfo
);
266 SAFE_FREE(sharename
);
271 int net_rap_share(struct net_context
*c
, int argc
, const char **argv
)
273 struct functable func
[] = {
278 N_("Delete a share from server"),
279 N_("net rap share delete\n"
280 " Delete a share from server")
286 N_("Delete a share from server"),
287 N_("net rap share close\n"
288 " Delete a share from server\n"
289 " Alias for net rap share delete")
295 N_("Add a share to server"),
296 N_("net rap share add\n"
297 " Add a share to server")
299 {NULL
, NULL
, 0, NULL
, NULL
}
303 struct cli_state
*cli
;
306 if (c
->display_usage
) {
307 d_printf(_("Usage:\n"));
308 d_printf(_("net rap share\n"
309 " List all shares on remote server\n"));
310 net_display_usage_from_functable(func
);
314 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
317 if (c
->opt_long_list_entries
) {
319 "\nEnumerating shared resources (exports) on remote server:\n\n"
320 "\nShare name Type Description\n"
321 "---------- ---- -----------\n"));
322 status
= cli_RNetShareEnum(cli
, long_share_fn
, NULL
);
324 status
= cli_RNetShareEnum(cli
, share_fn
, NULL
);
327 return NT_STATUS_IS_OK(status
) ? 0 : -1;
330 return net_run_function(c
, argc
, argv
, "net rap share", func
);
333 int net_rap_session_usage(struct net_context
*c
, int argc
, const char **argv
)
336 "\nnet rap session [misc. options] [targets]"
337 "\n\tenumerates all active SMB/CIFS sessions on target server\n"));
339 "\nnet rap session DELETE <client_name> [misc. options] [targets] \n"
341 "\nnet rap session CLOSE <client_name> [misc. options] [targets]"
342 "\n\tDeletes (closes) a session from specified client to server\n"));
344 "\nnet rap session INFO <client_name>"
345 "\n\tEnumerates all open files in specified session\n"));
347 net_common_flags_usage(c
, argc
, argv
);
351 static void list_sessions_func(char *wsname
, char *username
, uint16_t conns
,
352 uint16_t opens
, uint16_t users
, uint32_t sess_time
,
353 uint32_t idle_time
, uint32_t user_flags
, char *clitype
)
355 int hrs
= idle_time
/ 3600;
356 int min
= (idle_time
/ 60) % 60;
357 int sec
= idle_time
% 60;
359 d_printf("\\\\%-18.18s %-20.20s %-18.18s %5d %2.2d:%2.2d:%2.2d\n",
360 wsname
, username
, clitype
, opens
, hrs
, min
, sec
);
363 static void display_session_func(const char *wsname
, const char *username
,
364 uint16_t conns
, uint16_t opens
, uint16_t users
,
365 uint32_t sess_time
, uint32_t idle_time
,
366 uint32_t user_flags
, const char *clitype
)
368 int ihrs
= idle_time
/ 3600;
369 int imin
= (idle_time
/ 60) % 60;
370 int isec
= idle_time
% 60;
371 int shrs
= sess_time
/ 3600;
372 int smin
= (sess_time
/ 60) % 60;
373 int ssec
= sess_time
% 60;
374 d_printf(_("User name %-20.20s\n"
375 "Computer %-20.20s\n"
376 "Guest logon %-20.20s\n"
377 "Client Type %-40.40s\n"
378 "Sess time %2.2d:%2.2d:%2.2d\n"
379 "Idle time %2.2d:%2.2d:%2.2d\n"),
381 (user_flags
&0x0)?_("yes"):_("no"), clitype
,
382 shrs
, smin
, ssec
, ihrs
, imin
, isec
);
385 static void display_conns_func(uint16_t conn_id
, uint16_t conn_type
, uint16_t opens
,
386 uint16_t users
, uint32_t conn_time
,
387 const char *username
, const char *netname
)
389 d_printf("%-14.14s %-8.8s %5d\n",
390 netname
, net_share_type_str(conn_type
), opens
);
393 static int rap_session_info(struct net_context
*c
, int argc
, const char **argv
)
395 const char *sessname
;
396 struct cli_state
*cli
;
399 if (argc
== 0 || c
->display_usage
)
400 return net_rap_session_usage(c
, argc
, argv
);
402 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
407 ret
= cli_NetSessionGetInfo(cli
, sessname
, display_session_func
);
413 d_printf(_("Share name Type # Opens\n-------------------------"
414 "-----------------------------------------------------\n"));
415 ret
= cli_NetConnectionEnum(cli
, sessname
, display_conns_func
);
420 static int rap_session_delete(struct net_context
*c
, int argc
, const char **argv
)
422 struct cli_state
*cli
;
425 if (argc
== 0 || c
->display_usage
)
426 return net_rap_session_usage(c
, argc
, argv
);
428 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
431 ret
= cli_NetSessionDel(cli
, argv
[0]);
436 int net_rap_session(struct net_context
*c
, int argc
, const char **argv
)
438 struct functable func
[] = {
443 N_("Display information about session"),
444 N_("net rap session info\n"
445 " Display information about session")
451 N_("Close specified session"),
452 N_("net rap session delete\n"
453 " Close specified session\n"
454 " Alias for net rap session close")
460 N_("Close specified session"),
461 N_("net rap session close\n"
462 " Close specified session")
464 {NULL
, NULL
, 0, NULL
, NULL
}
468 struct cli_state
*cli
;
471 if (c
->display_usage
) {
472 d_printf(_("Usage:\n"));
473 d_printf(_("net rap session\n"
474 " List all open sessions on remote "
476 net_display_usage_from_functable(func
);
480 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
483 d_printf(_("Computer User name "
484 "Client Type Opens Idle time\n"
485 "------------------------------------------"
486 "------------------------------------\n"));
487 ret
= cli_NetSessionEnum(cli
, list_sessions_func
);
493 return net_run_function(c
, argc
, argv
, "net rap session", func
);
496 /****************************************************************************
498 ****************************************************************************/
499 static void display_server_func(const char *name
, uint32_t m
,
500 const char *comment
, void * reserved
)
502 d_printf("\t%-16.16s %s\n", name
, comment
);
505 static int net_rap_server_name(struct net_context
*c
, int argc
, const char *argv
[])
507 struct cli_state
*cli
;
510 if (c
->display_usage
) {
513 _("net rap server name\n"
514 " Get the name of the server\n"));
518 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
521 if (!cli_get_server_name(NULL
, cli
, &name
)) {
522 d_fprintf(stderr
, _("cli_get_server_name failed\n"));
527 d_printf(_("Server name = %s\n"), name
);
534 static int net_rap_server_domain(struct net_context
*c
, int argc
,
537 struct cli_state
*cli
;
540 if (c
->display_usage
) {
543 _("net rap server domain\n"
544 " Enumerate servers in this domain/workgroup\n"));
548 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
551 d_printf(_("\nEnumerating servers in this domain or workgroup: \n\n"
552 "\tServer name Server description\n"
553 "\t------------- ----------------------------\n"));
555 status
= cli_NetServerEnum(cli
,
561 return NT_STATUS_IS_OK(status
) ? 0 : -1;
564 int net_rap_server(struct net_context
*c
, int argc
, const char **argv
)
566 struct functable func
[] = {
571 N_("Get the name of the server"),
572 N_("net rap server name\n"
573 " Get the name of the server")
577 net_rap_server_domain
,
579 N_("Get the servers in this domain/workgroup"),
580 N_("net rap server domain\n"
581 " Get the servers in this domain/workgroup")
583 {NULL
, NULL
, 0, NULL
, NULL
}
586 /* smb4k uses 'net [rap|rpc] server domain' to query servers in a domain */
587 /* Fall through for 'domain', any other forms will cause to show usage message */
588 return net_run_function(c
, argc
, argv
, "net rap server", func
);
592 int net_rap_domain_usage(struct net_context
*c
, int argc
, const char **argv
)
594 d_printf(_("net rap domain [misc. options] [target]\n\tlists the"
595 " domains or workgroups visible on the current network\n"));
597 net_common_flags_usage(c
, argc
, argv
);
601 int net_rap_domain(struct net_context
*c
, int argc
, const char **argv
)
603 struct cli_state
*cli
;
606 if (c
->display_usage
)
607 return net_rap_domain_usage(c
, argc
, argv
);
609 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
612 d_printf(_("\nEnumerating domains:\n\n"
613 "\tDomain name Server name of Browse Master\n"
614 "\t------------- ----------------------------\n"));
616 status
= cli_NetServerEnum(cli
,
622 return NT_STATUS_IS_OK(status
) ? 0 : -1;
625 int net_rap_printq_usage(struct net_context
*c
, int argc
, const char **argv
)
628 "net rap printq [misc. options] [targets]\n"
630 "net rap printq info [<queue_name>] [misc. options] [targets]\n"
631 "\tlists the specified queue and jobs on the target server.\n"
632 "\tIf the queue name is not specified, all queues are listed.\n\n"));
634 "net rap printq delete [<queue name>] [misc. options] [targets]\n"
635 "\tdeletes the specified job number on the target server, or the\n"
636 "\tprinter queue if no job number is specified\n"));
638 net_common_flags_usage(c
, argc
, argv
);
643 static void enum_queue(const char *queuename
, uint16_t pri
, uint16_t start
,
644 uint16_t until
, const char *sep
, const char *pproc
,
645 const char *dest
, const char *qparms
,
646 const char *qcomment
, uint16_t status
, uint16_t jobcount
)
648 d_printf(_("%-17.17s Queue %5d jobs "),
649 queuename
, jobcount
);
653 d_printf(_("*Printer Active*\n"));
656 d_printf(_("*Printer Paused*\n"));
659 d_printf(_("*Printer error*\n"));
662 d_printf(_("*Delete Pending*\n"));
665 d_printf(_("**UNKNOWN STATUS**\n"));
669 static void enum_jobs(uint16_t jobid
, const char *ownername
,
670 const char *notifyname
, const char *datatype
,
671 const char *jparms
, uint16_t pos
, uint16_t status
,
672 const char *jstatus
, unsigned int submitted
, unsigned int jobsize
,
675 d_printf(" %-23.23s %5d %9d ",
676 ownername
, jobid
, jobsize
);
679 d_printf(_("Waiting\n"));
682 d_printf(_("Held in queue\n"));
685 d_printf(_("Spooling\n"));
688 d_printf(_("Printing\n"));
691 d_printf(_("**UNKNOWN STATUS**\n"));
695 #define PRINTQ_ENUM_DISPLAY \
696 _("Print queues at \\\\%s\n\n"\
697 "Name Job # Size Status\n\n"\
698 "------------------------------------------------------------------"\
701 static int rap_printq_info(struct net_context
*c
, int argc
, const char **argv
)
703 struct cli_state
*cli
;
706 if (argc
== 0 || c
->display_usage
)
707 return net_rap_printq_usage(c
, argc
, argv
);
709 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
712 d_printf(PRINTQ_ENUM_DISPLAY
, smbXcli_conn_remote_name(cli
->conn
)); /* list header */
713 ret
= cli_NetPrintQGetInfo(cli
, argv
[0], enum_queue
, enum_jobs
);
718 static int rap_printq_delete(struct net_context
*c
, int argc
, const char **argv
)
720 struct cli_state
*cli
;
723 if (argc
== 0 || c
->display_usage
)
724 return net_rap_printq_usage(c
, argc
, argv
);
726 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
729 status
= cli_printjob_del(cli
, atoi(argv
[0]));
731 if (!NT_STATUS_IS_OK(status
)) {
737 int net_rap_printq(struct net_context
*c
, int argc
, const char **argv
)
739 struct cli_state
*cli
;
742 struct functable func
[] = {
747 N_("Display info about print queues and jobs"),
748 N_("net rap printq info [queue]\n"
749 " Display info about print jobs in queue.\n"
750 " If queue is not specified, all queues are "
757 N_("Delete print job(s)"),
758 N_("net rap printq delete\n"
759 " Delete print job(s)")
761 {NULL
, NULL
, 0, NULL
, NULL
}
765 if (c
->display_usage
) {
766 d_printf(_("Usage:\n"));
767 d_printf(_("net rap printq\n"
768 " List the print queue\n"));
769 net_display_usage_from_functable(func
);
773 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
776 d_printf(PRINTQ_ENUM_DISPLAY
, smbXcli_conn_remote_name(cli
->conn
)); /* list header */
777 ret
= cli_NetPrintQEnum(cli
, enum_queue
, enum_jobs
);
782 return net_run_function(c
, argc
, argv
, "net rap printq", func
);
785 static int net_rap_user_usage(struct net_context
*c
, int argc
, const char **argv
)
787 return net_user_usage(c
, argc
, argv
);
790 static void user_fn(const char *user_name
, void *state
)
792 d_printf("%-21.21s\n", user_name
);
795 static void long_user_fn(const char *user_name
, const char *comment
,
796 const char * home_dir
, const char * logon_script
,
799 d_printf("%-21.21s %s\n",
803 static void group_member_fn(const char *user_name
, void *state
)
805 d_printf("%-21.21s\n", user_name
);
808 static int rap_user_delete(struct net_context
*c
, int argc
, const char **argv
)
810 struct cli_state
*cli
;
813 if (argc
== 0 || c
->display_usage
) {
814 return net_rap_user_usage(c
, argc
, argv
);
817 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
820 ret
= cli_NetUserDelete(cli
, argv
[0]);
825 static int rap_user_add(struct net_context
*c
, int argc
, const char **argv
)
827 struct cli_state
*cli
;
829 struct rap_user_info_1 userinfo
;
831 if (argc
== 0 || c
->display_usage
) {
832 return net_rap_user_usage(c
, argc
, argv
);
835 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
838 strlcpy((char *)userinfo
.user_name
, argv
[0], sizeof(userinfo
.user_name
));
839 if (c
->opt_flags
== 0)
842 userinfo
.userflags
= c
->opt_flags
;
843 userinfo
.reserved1
= '\0';
844 userinfo
.comment
= smb_xstrdup(c
->opt_comment
? c
->opt_comment
: "");
846 userinfo
.home_dir
= NULL
;
847 userinfo
.logon_script
= NULL
;
848 userinfo
.passwrd
[0] = '\0';
850 ret
= cli_NetUserAdd(cli
, &userinfo
);
856 static int rap_user_info(struct net_context
*c
, int argc
, const char **argv
)
858 struct cli_state
*cli
;
860 if (argc
== 0 || c
->display_usage
) {
861 return net_rap_user_usage(c
, argc
, argv
);
864 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
867 ret
= cli_NetUserGetGroups(cli
, argv
[0], group_member_fn
, NULL
);
872 int net_rap_user(struct net_context
*c
, int argc
, const char **argv
)
875 struct functable func
[] = {
880 N_("Add specified user"),
881 N_("net rap user add\n"
882 " Add specified user")
888 N_("List domain groups of specified user"),
889 N_("net rap user info\n"
890 " List domain groups of specified user")
897 N_("Remove specified user"),
898 N_("net rap user delete\n"
899 " Remove specified user")
901 {NULL
, NULL
, 0, NULL
, NULL
}
905 struct cli_state
*cli
;
906 if (c
->display_usage
) {
907 d_printf(_("Usage:\n"));
908 d_printf(_("net rap user\n"
909 " List all users\n"));
910 net_display_usage_from_functable(func
);
914 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
916 if (c
->opt_long_list_entries
) {
917 d_printf(_("\nUser name Comment"
918 "\n-----------------------------\n"));
919 ret
= cli_RNetUserEnum(cli
, long_user_fn
, NULL
);
923 ret
= cli_RNetUserEnum0(cli
, user_fn
, NULL
);
928 ret
= net_run_function(c
, argc
, argv
, "net rap user", func
);
931 DEBUG(1, (_("Net user returned: %d\n"), ret
));
937 int net_rap_group_usage(struct net_context
*c
, int argc
, const char **argv
)
939 return net_group_usage(c
, argc
, argv
);
942 static void long_group_fn(const char *group_name
, const char *comment
,
945 d_printf("%-21.21s %s\n", group_name
, comment
);
948 static void group_fn(const char *group_name
, void *state
)
950 d_printf("%-21.21s\n", group_name
);
953 static int rap_group_delete(struct net_context
*c
, int argc
, const char **argv
)
955 struct cli_state
*cli
;
957 if (argc
== 0 || c
->display_usage
) {
958 return net_rap_group_usage(c
, argc
, argv
);
961 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
964 ret
= cli_NetGroupDelete(cli
, argv
[0]);
969 static int rap_group_add(struct net_context
*c
, int argc
, const char **argv
)
971 struct cli_state
*cli
;
973 struct rap_group_info_1 grinfo
;
975 if (argc
== 0 || c
->display_usage
) {
976 return net_rap_group_usage(c
, argc
, argv
);
979 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
982 /* BB check for length 21 or smaller explicitly ? BB */
983 strlcpy((char *)grinfo
.group_name
, argv
[0], sizeof(grinfo
.group_name
));
984 grinfo
.reserved1
= '\0';
985 grinfo
.comment
= smb_xstrdup(c
->opt_comment
? c
->opt_comment
: "");
987 ret
= cli_NetGroupAdd(cli
, &grinfo
);
992 int net_rap_group(struct net_context
*c
, int argc
, const char **argv
)
994 struct functable func
[] = {
999 N_("Add specified group"),
1000 N_("net rap group add\n"
1001 " Add specified group")
1007 N_("Delete specified group"),
1008 N_("net rap group delete\n"
1009 " Delete specified group")
1011 {NULL
, NULL
, 0, NULL
, NULL
}
1015 struct cli_state
*cli
;
1017 if (c
->display_usage
) {
1018 d_printf(_("Usage:\n"));
1019 d_printf(_("net rap group\n"
1020 " List all groups\n"));
1021 net_display_usage_from_functable(func
);
1025 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1027 if (c
->opt_long_list_entries
) {
1028 d_printf(_("Group name Comment\n"
1029 "-----------------------------\n"));
1030 ret
= cli_RNetGroupEnum(cli
, long_group_fn
, NULL
);
1034 ret
= cli_RNetGroupEnum0(cli
, group_fn
, NULL
);
1039 return net_run_function(c
, argc
, argv
, "net rap group", func
);
1042 int net_rap_groupmember_usage(struct net_context
*c
, int argc
, const char **argv
)
1045 "net rap groupmember LIST <group> [misc. options] [targets]"
1046 "\n\t Enumerate users in a group\n"
1047 "\nnet rap groupmember DELETE <group> <user> [misc. options] "
1048 "[targets]\n\t Delete specified user from specified group\n"
1049 "\nnet rap groupmember ADD <group> <user> [misc. options] [targets]"
1050 "\n\t Add specified user to specified group\n"));
1052 net_common_flags_usage(c
, argc
, argv
);
1057 static int rap_groupmember_add(struct net_context
*c
, int argc
, const char **argv
)
1059 struct cli_state
*cli
;
1061 if (argc
!= 2 || c
->display_usage
) {
1062 return net_rap_groupmember_usage(c
, argc
, argv
);
1065 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1068 ret
= cli_NetGroupAddUser(cli
, argv
[0], argv
[1]);
1073 static int rap_groupmember_delete(struct net_context
*c
, int argc
, const char **argv
)
1075 struct cli_state
*cli
;
1077 if (argc
!= 2 || c
->display_usage
) {
1078 return net_rap_groupmember_usage(c
, argc
, argv
);
1081 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1084 ret
= cli_NetGroupDelUser(cli
, argv
[0], argv
[1]);
1089 static int rap_groupmember_list(struct net_context
*c
, int argc
, const char **argv
)
1091 struct cli_state
*cli
;
1093 if (argc
== 0 || c
->display_usage
) {
1094 return net_rap_groupmember_usage(c
, argc
, argv
);
1097 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1100 ret
= cli_NetGroupGetUsers(cli
, argv
[0], group_member_fn
, NULL
);
1105 int net_rap_groupmember(struct net_context
*c
, int argc
, const char **argv
)
1107 struct functable func
[] = {
1110 rap_groupmember_add
,
1112 N_("Add specified user to group"),
1113 N_("net rap groupmember add\n"
1114 " Add specified user to group")
1118 rap_groupmember_list
,
1120 N_("List users in group"),
1121 N_("net rap groupmember list\n"
1122 " List users in group")
1126 rap_groupmember_delete
,
1128 N_("Remove user from group"),
1129 N_("net rap groupmember delete\n"
1130 " Remove user from group")
1132 {NULL
, NULL
, 0, NULL
, NULL
}
1135 return net_run_function(c
, argc
, argv
, "net rap groupmember", func
);
1138 int net_rap_validate_usage(struct net_context
*c
, int argc
, const char **argv
)
1140 d_printf(_("net rap validate <username> [password]\n"
1141 "\tValidate user and password to check whether they"
1142 " can access target server or domain\n"));
1144 net_common_flags_usage(c
, argc
, argv
);
1148 int net_rap_validate(struct net_context
*c
, int argc
, const char **argv
)
1150 return errmsg_not_implemented();
1153 int net_rap_service_usage(struct net_context
*c
, int argc
, const char **argv
)
1155 d_printf(_("net rap service [misc. options] [targets] \n"
1156 "\tlists all running service daemons on target server\n"));
1157 d_printf(_("\nnet rap service START <name> [service startup arguments]"
1158 " [misc. options] [targets]"
1159 "\n\tStart named service on remote server\n"));
1160 d_printf(_("\nnet rap service STOP <name> [misc. options] [targets]\n"
1161 "\n\tStop named service on remote server\n"));
1163 net_common_flags_usage(c
, argc
, argv
);
1167 static int rap_service_start(struct net_context
*c
, int argc
, const char **argv
)
1169 return errmsg_not_implemented();
1172 static int rap_service_stop(struct net_context
*c
, int argc
, const char **argv
)
1174 return errmsg_not_implemented();
1177 static void service_fn(const char *service_name
, const char *dummy
,
1180 d_printf("%-21.21s\n", service_name
);
1183 int net_rap_service(struct net_context
*c
, int argc
, const char **argv
)
1185 struct functable func
[] = {
1190 N_("Start service on remote server"),
1191 N_("net rap service start\n"
1192 " Start service on remote server")
1198 N_("Stop named serve on remote server"),
1199 N_("net rap service stop\n"
1200 " Stop named serve on remote server")
1202 {NULL
, NULL
, 0, NULL
, NULL
}
1206 struct cli_state
*cli
;
1208 if (c
->display_usage
) {
1209 d_printf(_("Usage:\n"));
1210 d_printf(_("net rap service\n"
1211 " List services on remote server\n"));
1212 net_display_usage_from_functable(func
);
1216 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1219 if (c
->opt_long_list_entries
) {
1220 d_printf(_("Service name Comment\n"
1221 "-----------------------------\n"));
1222 ret
= cli_RNetServiceEnum(cli
, long_group_fn
, NULL
);
1228 ret
= cli_RNetServiceEnum(cli
, service_fn
, NULL
);
1233 return net_run_function(c
, argc
, argv
, "net rap service", func
);
1236 int net_rap_password_usage(struct net_context
*c
, int argc
, const char **argv
)
1239 "net rap password <user> <oldpwo> <newpw> [misc. options] [target]\n"
1240 "\tchanges the password for the specified user at target\n"));
1246 int net_rap_password(struct net_context
*c
, int argc
, const char **argv
)
1248 struct cli_state
*cli
;
1251 if (argc
< 3 || c
->display_usage
)
1252 return net_rap_password_usage(c
, argc
, argv
);
1254 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1257 /* BB Add check for password lengths? */
1258 status
= cli_oem_change_password(cli
, argv
[0], argv
[2], argv
[1]);
1260 return NT_STATUS_IS_OK(status
) ? 0 : -1;
1263 int net_rap_admin_usage(struct net_context
*c
, int argc
, const char **argv
)
1266 "net rap admin <remote command> [cmd args [env]] [misc. options] [targets]"
1267 "\n\texecutes a remote command on an os/2 target server\n"));
1273 int net_rap_admin(struct net_context
*c
, int argc
, const char **argv
)
1275 return errmsg_not_implemented();
1278 /* Entry-point for all the RAP functions. */
1280 int net_rap(struct net_context
*c
, int argc
, const char **argv
)
1282 struct functable func
[] = {
1287 N_("List open files"),
1295 N_("List shares exported by server"),
1296 N_("net rap share\n"
1297 " List shares exported by server")
1303 N_("List open sessions"),
1304 N_("net rap session\n"
1305 " List open sessions")
1311 N_("List servers in workgroup"),
1312 N_("net rap server\n"
1313 " List servers in domain/workgroup")
1319 N_("List domains in network"),
1320 N_("net rap domain\n"
1321 " List domains in network")
1327 N_("List printer queues on server"),
1328 N_("net rap printq\n"
1329 " List printer queues on server")
1343 N_("List user groups"),
1344 N_("net rap group\n"
1345 " List user groups")
1351 N_("Check username/password"),
1352 N_("net rap validate\n"
1353 " Check username/password")
1357 net_rap_groupmember
,
1359 N_("List/modify group memberships"),
1360 N_("net rap groupmember\n"
1361 " List/modify group memberships")
1367 N_("Execute commands on remote OS/2"),
1368 N_("net rap admin\n"
1369 " Execute commands on remote OS/2")
1375 N_("Start/stop remote service"),
1376 N_("net rap service\n"
1377 " Start/stop remote service")
1383 N_("Change user password"),
1384 N_("net rap password\n"
1385 " Change user password")
1387 {NULL
, NULL
, 0, NULL
, NULL
}
1390 return net_run_function(c
, argc
, argv
, "net rap", func
);