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 "utils/net.h"
28 /* The following messages were for error checking that is not properly
29 reported at the moment. Which should be reinstated? */
30 #define ERRMSG_TARGET_WG_NOT_VALID "\nTarget workgroup option not valid "\
31 "except on net rap server command, ignored"
32 #define ERRMSG_INVALID_HELP_OPTION "\nInvalid help option\n"
34 #define ERRMSG_BOTH_SERVER_IPADDRESS "\nTarget server and IP address both "\
35 "specified. Do not set both at the same time. The target IP address was used\n"
37 static int errmsg_not_implemented(void)
39 d_printf(_("\nNot implemented\n"));
43 int net_rap_file_usage(struct net_context
*c
, int argc
, const char **argv
)
45 return net_file_usage(c
, argc
, argv
);
48 /***************************************************************************
49 list info on an open file
50 ***************************************************************************/
51 static void file_fn(const char * pPath
, const char * pUser
, uint16 perms
,
52 uint16 locks
, uint32 id
)
54 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
55 id
, pUser
, perms
, locks
, pPath
);
58 static void one_file_fn(const char *pPath
, const char *pUser
, uint16 perms
,
59 uint16 locks
, uint32 id
)
61 d_printf(_("File ID %d\n"
65 "Permissions 0x%x\n"),
66 id
, pUser
, locks
, pPath
, perms
);
70 static int rap_file_close(struct net_context
*c
, int argc
, const char **argv
)
72 struct cli_state
*cli
;
74 if (argc
== 0 || c
->display_usage
) {
75 return net_rap_file_usage(c
, argc
, argv
);
78 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
81 ret
= cli_NetFileClose(cli
, atoi(argv
[0]));
86 static int rap_file_info(struct net_context
*c
, int argc
, const char **argv
)
88 struct cli_state
*cli
;
90 if (argc
== 0 || c
->display_usage
)
91 return net_rap_file_usage(c
, argc
, argv
);
93 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
96 ret
= cli_NetFileGetInfo(cli
, atoi(argv
[0]), one_file_fn
);
101 static int rap_file_user(struct net_context
*c
, int argc
, const char **argv
)
103 struct cli_state
*cli
;
106 if (argc
== 0 || c
->display_usage
)
107 return net_rap_file_usage(c
, argc
, argv
);
109 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
112 /* list open files */
114 d_printf(_("\nEnumerating open files on remote server:\n\n"
115 "\nFileId Opened by Perms Locks Path \n"
116 "------ --------- ----- ----- ---- \n"));
117 ret
= cli_NetFileEnum(cli
, argv
[0], NULL
, file_fn
);
120 d_printf(_("\nOperation not supported by server!\n\n"));
126 int net_rap_file(struct net_context
*c
, int argc
, const char **argv
)
128 struct functable func
[] = {
133 N_("Close specified file on server"),
134 N_("net rap file close\n"
135 " Close specified file on server")
141 N_("List all files opened by username"),
142 N_("net rap file user\n"
143 " List all files opened by username")
149 N_("Display info about an opened file"),
150 N_("net rap file info\n"
151 " Display info about an opened file")
153 {NULL
, NULL
, 0, NULL
, NULL
}
157 struct cli_state
*cli
;
160 if (c
->display_usage
) {
161 d_printf(_("Usage:\n"));
162 d_printf(_("net rap file\n"
163 " List all open files on rempte "
165 net_display_usage_from_functable(func
);
169 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
172 /* list open files */
174 d_printf(_("\nEnumerating open files on remote server:\n\n"
175 "\nFileId Opened by Perms Locks Path\n"
176 "------ --------- ----- ----- ----\n"));
177 ret
= cli_NetFileEnum(cli
, NULL
, NULL
, file_fn
);
180 d_printf(_("\nOperation not supported by server!\n\n"));
186 return net_run_function(c
, argc
, argv
, "net rap file", func
);
189 int net_rap_share_usage(struct net_context
*c
, int argc
, const char **argv
)
191 return net_share_usage(c
, argc
, argv
);
194 static void long_share_fn(const char *share_name
, uint32 type
,
195 const char *comment
, void *state
)
197 d_printf("%-12s %-8.8s %-50s\n",
198 share_name
, net_share_type_str(type
), comment
);
201 static void share_fn(const char *share_name
, uint32 type
,
202 const char *comment
, void *state
)
204 d_printf("%s\n", share_name
);
207 static int rap_share_delete(struct net_context
*c
, int argc
, const char **argv
)
209 struct cli_state
*cli
;
212 if (argc
== 0 || c
->display_usage
) {
213 return net_rap_share_usage(c
, argc
, argv
);
216 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
219 ret
= cli_NetShareDelete(cli
, argv
[0]);
224 static int rap_share_add(struct net_context
*c
, int argc
, const char **argv
)
226 struct cli_state
*cli
;
229 RAP_SHARE_INFO_2 sinfo
;
233 if (argc
== 0 || c
->display_usage
) {
234 return net_rap_share_usage(c
, argc
, argv
);
237 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
240 sharename
= SMB_STRDUP(argv
[0]);
241 p
= strchr(sharename
, '=');
243 d_printf(_("Server path not specified\n"));
244 SAFE_FREE(sharename
);
245 return net_rap_share_usage(c
, argc
, argv
);
248 strlcpy(sinfo
.share_name
, sharename
, sizeof(sinfo
.share_name
));
249 sinfo
.reserved1
= '\0';
250 sinfo
.share_type
= 0;
251 sinfo
.comment
= smb_xstrdup(c
->opt_comment
);
253 sinfo
.maximum_users
= c
->opt_maxusers
;
254 sinfo
.active_users
= 0;
256 memset(sinfo
.password
, '\0', sizeof(sinfo
.password
));
257 sinfo
.reserved2
= '\0';
259 ret
= cli_NetShareAdd(cli
, &sinfo
);
261 SAFE_FREE(sharename
);
266 int net_rap_share(struct net_context
*c
, int argc
, const char **argv
)
268 struct functable func
[] = {
273 N_("Delete a share from server"),
274 N_("net rap share delete\n"
275 " Delete a share from server")
281 N_("Delete a share from server"),
282 N_("net rap share close\n"
283 " Delete a share from server\n"
284 " Alias for net rap share delete")
290 N_("Add a share to server"),
291 N_("net rap share add\n"
292 " Add a share to server")
294 {NULL
, NULL
, 0, NULL
, NULL
}
298 struct cli_state
*cli
;
301 if (c
->display_usage
) {
302 d_printf(_("Usage:\n"));
303 d_printf(_("net rap share\n"
304 " List all shares on remote server\n"));
305 net_display_usage_from_functable(func
);
309 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
312 if (c
->opt_long_list_entries
) {
314 "\nEnumerating shared resources (exports) on remote server:\n\n"
315 "\nShare name Type Description\n"
316 "---------- ---- -----------\n"));
317 ret
= cli_RNetShareEnum(cli
, long_share_fn
, NULL
);
319 ret
= cli_RNetShareEnum(cli
, share_fn
, NULL
);
325 return net_run_function(c
, argc
, argv
, "net rap share", func
);
328 int net_rap_session_usage(struct net_context
*c
, int argc
, const char **argv
)
331 "\nnet rap session [misc. options] [targets]"
332 "\n\tenumerates all active SMB/CIFS sessions on target server\n"));
334 "\nnet rap session DELETE <client_name> [misc. options] [targets] \n"
336 "\nnet rap session CLOSE <client_name> [misc. options] [targets]"
337 "\n\tDeletes (closes) a session from specified client to server\n"));
339 "\nnet rap session INFO <client_name>"
340 "\n\tEnumerates all open files in specified session\n"));
342 net_common_flags_usage(c
, argc
, argv
);
346 static void list_sessions_func(char *wsname
, char *username
, uint16 conns
,
347 uint16 opens
, uint16 users
, uint32 sess_time
,
348 uint32 idle_time
, uint32 user_flags
, char *clitype
)
350 int hrs
= idle_time
/ 3600;
351 int min
= (idle_time
/ 60) % 60;
352 int sec
= idle_time
% 60;
354 d_printf("\\\\%-18.18s %-20.20s %-18.18s %5d %2.2d:%2.2d:%2.2d\n",
355 wsname
, username
, clitype
, opens
, hrs
, min
, sec
);
358 static void display_session_func(const char *wsname
, const char *username
,
359 uint16 conns
, uint16 opens
, uint16 users
,
360 uint32 sess_time
, uint32 idle_time
,
361 uint32 user_flags
, const char *clitype
)
363 int ihrs
= idle_time
/ 3600;
364 int imin
= (idle_time
/ 60) % 60;
365 int isec
= idle_time
% 60;
366 int shrs
= sess_time
/ 3600;
367 int smin
= (sess_time
/ 60) % 60;
368 int ssec
= sess_time
% 60;
369 d_printf(_("User name %-20.20s\n"
370 "Computer %-20.20s\n"
371 "Guest logon %-20.20s\n"
372 "Client Type %-40.40s\n"
373 "Sess time %2.2d:%2.2d:%2.2d\n"
374 "Idle time %2.2d:%2.2d:%2.2d\n"),
376 (user_flags
&0x0)?_("yes"):_("no"), clitype
,
377 shrs
, smin
, ssec
, ihrs
, imin
, isec
);
380 static void display_conns_func(uint16 conn_id
, uint16 conn_type
, uint16 opens
,
381 uint16 users
, uint32 conn_time
,
382 const char *username
, const char *netname
)
384 d_printf("%-14.14s %-8.8s %5d\n",
385 netname
, net_share_type_str(conn_type
), opens
);
388 static int rap_session_info(struct net_context
*c
, int argc
, const char **argv
)
390 const char *sessname
;
391 struct cli_state
*cli
;
394 if (argc
== 0 || c
->display_usage
)
395 return net_rap_session_usage(c
, argc
, argv
);
397 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
402 ret
= cli_NetSessionGetInfo(cli
, sessname
, display_session_func
);
408 d_printf(_("Share name Type # Opens\n-------------------------"
409 "-----------------------------------------------------\n"));
410 ret
= cli_NetConnectionEnum(cli
, sessname
, display_conns_func
);
415 static int rap_session_delete(struct net_context
*c
, int argc
, const char **argv
)
417 struct cli_state
*cli
;
420 if (argc
== 0 || c
->display_usage
)
421 return net_rap_session_usage(c
, argc
, argv
);
423 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
426 ret
= cli_NetSessionDel(cli
, argv
[0]);
431 int net_rap_session(struct net_context
*c
, int argc
, const char **argv
)
433 struct functable func
[] = {
438 N_("Display information about session"),
439 N_("net rap session info\n"
440 " Display information about session")
446 N_("Close specified session"),
447 N_("net rap session delete\n"
448 " Close specified session\n"
449 " Alias for net rap session close")
455 N_("Close specified session"),
456 N_("net rap session close\n"
457 " Close specified session")
459 {NULL
, NULL
, 0, NULL
, NULL
}
463 struct cli_state
*cli
;
466 if (c
->display_usage
) {
467 d_printf(_("Usage:\n"));
468 d_printf(_("net rap session\n"
469 " List all open sessions on remote "
471 net_display_usage_from_functable(func
);
475 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
478 d_printf(_("Computer User name "
479 "Client Type Opens Idle time\n"
480 "------------------------------------------"
481 "------------------------------------\n"));
482 ret
= cli_NetSessionEnum(cli
, list_sessions_func
);
488 return net_run_function(c
, argc
, argv
, "net rap session", func
);
491 /****************************************************************************
493 ****************************************************************************/
494 static void display_server_func(const char *name
, uint32 m
,
495 const char *comment
, void * reserved
)
497 d_printf("\t%-16.16s %s\n", name
, comment
);
500 static int net_rap_server_name(struct net_context
*c
, int argc
, const char *argv
[])
502 struct cli_state
*cli
;
505 if (c
->display_usage
) {
506 d_printf(_("Usage:\n"
507 "net rap server name\n"
508 " Get the name of the server\n"));
512 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
515 if (!cli_get_server_name(NULL
, cli
, &name
)) {
516 d_fprintf(stderr
, _("cli_get_server_name failed\n"));
521 d_printf(_("Server name = %s\n"), name
);
528 static int net_rap_server_domain(struct net_context
*c
, int argc
,
531 struct cli_state
*cli
;
534 if (c
->display_usage
) {
535 d_printf(_("Usage:\n"
536 "net rap server domain\n"
537 " Enumerate servers in this domain/workgroup\n"));
541 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
544 d_printf(_("\nEnumerating servers in this domain or workgroup: \n\n"
545 "\tServer name Server description\n"
546 "\t------------- ----------------------------\n"));
548 ret
= cli_NetServerEnum(cli
, cli
->server_domain
, SV_TYPE_ALL
,
549 display_server_func
,NULL
);
554 int net_rap_server(struct net_context
*c
, int argc
, const char **argv
)
556 struct functable func
[] = {
561 N_("Get the name of the server"),
562 N_("net rap server name\n"
563 " Get the name of the server")
567 net_rap_server_domain
,
569 N_("Get the servers in this domain/workgroup"),
570 N_("net rap server domain\n"
571 " Get the servers in this domain/workgroup")
573 {NULL
, NULL
, 0, NULL
, NULL
}
576 /* smb4k uses 'net [rap|rpc] server domain' to query servers in a domain */
577 /* Fall through for 'domain', any other forms will cause to show usage message */
578 return net_run_function(c
, argc
, argv
, "net rap server", func
);
582 int net_rap_domain_usage(struct net_context
*c
, int argc
, const char **argv
)
584 d_printf(_("net rap domain [misc. options] [target]\n\tlists the"
585 " domains or workgroups visible on the current network\n"));
587 net_common_flags_usage(c
, argc
, argv
);
591 int net_rap_domain(struct net_context
*c
, int argc
, const char **argv
)
593 struct cli_state
*cli
;
596 if (c
->display_usage
)
597 return net_rap_domain_usage(c
, argc
, argv
);
599 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
602 d_printf(_("\nEnumerating domains:\n\n"
603 "\tDomain name Server name of Browse Master\n"
604 "\t------------- ----------------------------\n"));
606 ret
= cli_NetServerEnum(cli
, cli
->server_domain
, SV_TYPE_DOMAIN_ENUM
,
607 display_server_func
,NULL
);
612 int net_rap_printq_usage(struct net_context
*c
, int argc
, const char **argv
)
615 "net rap printq [misc. options] [targets]\n"
617 "net rap printq info [<queue_name>] [misc. options] [targets]\n"
618 "\tlists the specified queue and jobs on the target server.\n"
619 "\tIf the queue name is not specified, all queues are listed.\n\n"));
621 "net rap printq delete [<queue name>] [misc. options] [targets]\n"
622 "\tdeletes the specified job number on the target server, or the\n"
623 "\tprinter queue if no job number is specified\n"));
625 net_common_flags_usage(c
, argc
, argv
);
630 static void enum_queue(const char *queuename
, uint16 pri
, uint16 start
,
631 uint16 until
, const char *sep
, const char *pproc
,
632 const char *dest
, const char *qparms
,
633 const char *qcomment
, uint16 status
, uint16 jobcount
)
635 d_printf(_("%-17.17s Queue %5d jobs "),
636 queuename
, jobcount
);
640 d_printf(_("*Printer Active*\n"));
643 d_printf(_("*Printer Paused*\n"));
646 d_printf(_("*Printer error*\n"));
649 d_printf(_("*Delete Pending*\n"));
652 d_printf(_("**UNKNOWN STATUS**\n"));
656 static void enum_jobs(uint16 jobid
, const char *ownername
,
657 const char *notifyname
, const char *datatype
,
658 const char *jparms
, uint16 pos
, uint16 status
,
659 const char *jstatus
, unsigned int submitted
, unsigned int jobsize
,
662 d_printf(" %-23.23s %5d %9d ",
663 ownername
, jobid
, jobsize
);
666 d_printf(_("Waiting\n"));
669 d_printf(_("Held in queue\n"));
672 d_printf(_("Spooling\n"));
675 d_printf(_("Printing\n"));
678 d_printf(_("**UNKNOWN STATUS**\n"));
682 #define PRINTQ_ENUM_DISPLAY \
683 _("Print queues at \\\\%s\n\n"\
684 "Name Job # Size Status\n\n"\
685 "------------------------------------------------------------------"\
688 static int rap_printq_info(struct net_context
*c
, int argc
, const char **argv
)
690 struct cli_state
*cli
;
693 if (argc
== 0 || c
->display_usage
)
694 return net_rap_printq_usage(c
, argc
, argv
);
696 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
699 d_printf(PRINTQ_ENUM_DISPLAY
, cli
->desthost
); /* list header */
700 ret
= cli_NetPrintQGetInfo(cli
, argv
[0], enum_queue
, enum_jobs
);
705 static int rap_printq_delete(struct net_context
*c
, int argc
, const char **argv
)
707 struct cli_state
*cli
;
710 if (argc
== 0 || c
->display_usage
)
711 return net_rap_printq_usage(c
, argc
, argv
);
713 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
716 ret
= cli_printjob_del(cli
, atoi(argv
[0]));
721 int net_rap_printq(struct net_context
*c
, int argc
, const char **argv
)
723 struct cli_state
*cli
;
726 struct functable func
[] = {
731 N_("Display info about print queues and jobs"),
732 N_("net rap printq info [queue]\n"
733 " Display info about print jobs in queue.\n"
734 " If queue is not specified, all queues are "
741 N_("Delete print job(s)"),
742 N_("net rap printq delete\n"
743 " Delete print job(s)")
745 {NULL
, NULL
, 0, NULL
, NULL
}
749 if (c
->display_usage
) {
750 d_printf(_("Usage:\n"));
751 d_printf(_("net rap printq\n"
752 " List the print queue\n"));
753 net_display_usage_from_functable(func
);
757 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
760 d_printf(PRINTQ_ENUM_DISPLAY
, cli
->desthost
); /* list header */
761 ret
= cli_NetPrintQEnum(cli
, enum_queue
, enum_jobs
);
766 return net_run_function(c
, argc
, argv
, "net rap printq", func
);
769 static int net_rap_user_usage(struct net_context
*c
, int argc
, const char **argv
)
771 return net_user_usage(c
, argc
, argv
);
774 static void user_fn(const char *user_name
, void *state
)
776 d_printf("%-21.21s\n", user_name
);
779 static void long_user_fn(const char *user_name
, const char *comment
,
780 const char * home_dir
, const char * logon_script
,
783 d_printf("%-21.21s %s\n",
787 static void group_member_fn(const char *user_name
, void *state
)
789 d_printf("%-21.21s\n", user_name
);
792 static int rap_user_delete(struct net_context
*c
, int argc
, const char **argv
)
794 struct cli_state
*cli
;
797 if (argc
== 0 || c
->display_usage
) {
798 return net_rap_user_usage(c
, argc
, argv
);
801 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
804 ret
= cli_NetUserDelete(cli
, argv
[0]);
809 static int rap_user_add(struct net_context
*c
, int argc
, const char **argv
)
811 struct cli_state
*cli
;
813 RAP_USER_INFO_1 userinfo
;
815 if (argc
== 0 || c
->display_usage
) {
816 return net_rap_user_usage(c
, argc
, argv
);
819 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
822 safe_strcpy(userinfo
.user_name
, argv
[0], sizeof(userinfo
.user_name
)-1);
823 if (c
->opt_flags
== -1)
826 userinfo
.userflags
= c
->opt_flags
;
827 userinfo
.reserved1
= '\0';
828 userinfo
.comment
= smb_xstrdup(c
->opt_comment
? c
->opt_comment
: "");
830 userinfo
.home_dir
= NULL
;
831 userinfo
.logon_script
= NULL
;
832 userinfo
.passwrd
[0] = '\0';
834 ret
= cli_NetUserAdd(cli
, &userinfo
);
840 static int rap_user_info(struct net_context
*c
, int argc
, const char **argv
)
842 struct cli_state
*cli
;
844 if (argc
== 0 || c
->display_usage
) {
845 return net_rap_user_usage(c
, argc
, argv
);
848 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
851 ret
= cli_NetUserGetGroups(cli
, argv
[0], group_member_fn
, NULL
);
856 int net_rap_user(struct net_context
*c
, int argc
, const char **argv
)
859 struct functable func
[] = {
864 N_("Add specified user"),
865 N_("net rap user add\n"
866 " Add specified user")
872 N_("List domain groups of specified user"),
873 N_("net rap user info\n"
874 " List domain groups of specified user")
881 N_("Remove specified user"),
882 N_("net rap user delete\n"
883 " Remove specified user")
885 {NULL
, NULL
, 0, NULL
, NULL
}
889 struct cli_state
*cli
;
890 if (c
->display_usage
) {
891 d_printf(_("Usage:\n"));
892 d_printf(_("net rap user\n"
893 " List all users\n"));
894 net_display_usage_from_functable(func
);
898 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
900 if (c
->opt_long_list_entries
) {
901 d_printf(_("\nUser name Comment"
902 "\n-----------------------------\n"));
903 ret
= cli_RNetUserEnum(cli
, long_user_fn
, NULL
);
907 ret
= cli_RNetUserEnum0(cli
, user_fn
, NULL
);
912 ret
= net_run_function(c
, argc
, argv
, "net rap user", func
);
915 DEBUG(1, (_("Net user returned: %d\n"), ret
));
921 int net_rap_group_usage(struct net_context
*c
, int argc
, const char **argv
)
923 return net_group_usage(c
, argc
, argv
);
926 static void long_group_fn(const char *group_name
, const char *comment
,
929 d_printf("%-21.21s %s\n", group_name
, comment
);
932 static void group_fn(const char *group_name
, void *state
)
934 d_printf("%-21.21s\n", group_name
);
937 static int rap_group_delete(struct net_context
*c
, int argc
, const char **argv
)
939 struct cli_state
*cli
;
941 if (argc
== 0 || c
->display_usage
) {
942 return net_rap_group_usage(c
, argc
, argv
);
945 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
948 ret
= cli_NetGroupDelete(cli
, argv
[0]);
953 static int rap_group_add(struct net_context
*c
, int argc
, const char **argv
)
955 struct cli_state
*cli
;
957 RAP_GROUP_INFO_1 grinfo
;
959 if (argc
== 0 || c
->display_usage
) {
960 return net_rap_group_usage(c
, argc
, argv
);
963 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
966 /* BB check for length 21 or smaller explicitly ? BB */
967 safe_strcpy(grinfo
.group_name
, argv
[0], sizeof(grinfo
.group_name
)-1);
968 grinfo
.reserved1
= '\0';
969 grinfo
.comment
= smb_xstrdup(c
->opt_comment
? c
->opt_comment
: "");
971 ret
= cli_NetGroupAdd(cli
, &grinfo
);
976 int net_rap_group(struct net_context
*c
, int argc
, const char **argv
)
978 struct functable func
[] = {
983 N_("Add specified group"),
984 N_("net rap group add\n"
985 " Add specified group")
991 N_("Delete specified group"),
992 N_("net rap group delete\n"
993 " Delete specified group")
995 {NULL
, NULL
, 0, NULL
, NULL
}
999 struct cli_state
*cli
;
1001 if (c
->display_usage
) {
1002 d_printf(_("Usage:\n"));
1003 d_printf(_("net rap group\n"
1004 " List all groups\n"));
1005 net_display_usage_from_functable(func
);
1009 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1011 if (c
->opt_long_list_entries
) {
1012 d_printf(_("Group name Comment\n"
1013 "-----------------------------\n"));
1014 ret
= cli_RNetGroupEnum(cli
, long_group_fn
, NULL
);
1018 ret
= cli_RNetGroupEnum0(cli
, group_fn
, NULL
);
1023 return net_run_function(c
, argc
, argv
, "net rap group", func
);
1026 int net_rap_groupmember_usage(struct net_context
*c
, int argc
, const char **argv
)
1029 "net rap groupmember LIST <group> [misc. options] [targets]"
1030 "\n\t Enumerate users in a group\n"
1031 "\nnet rap groupmember DELETE <group> <user> [misc. options] "
1032 "[targets]\n\t Delete specified user from specified group\n"
1033 "\nnet rap groupmember ADD <group> <user> [misc. options] [targets]"
1034 "\n\t Add specified user to specified group\n"));
1036 net_common_flags_usage(c
, argc
, argv
);
1041 static int rap_groupmember_add(struct net_context
*c
, int argc
, const char **argv
)
1043 struct cli_state
*cli
;
1045 if (argc
!= 2 || c
->display_usage
) {
1046 return net_rap_groupmember_usage(c
, argc
, argv
);
1049 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1052 ret
= cli_NetGroupAddUser(cli
, argv
[0], argv
[1]);
1057 static int rap_groupmember_delete(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_NetGroupDelUser(cli
, argv
[0], argv
[1]);
1073 static int rap_groupmember_list(struct net_context
*c
, int argc
, const char **argv
)
1075 struct cli_state
*cli
;
1077 if (argc
== 0 || 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_NetGroupGetUsers(cli
, argv
[0], group_member_fn
, NULL
);
1089 int net_rap_groupmember(struct net_context
*c
, int argc
, const char **argv
)
1091 struct functable func
[] = {
1094 rap_groupmember_add
,
1096 N_("Add specified user to group"),
1097 N_("net rap groupmember add\n"
1098 " Add specified user to group")
1102 rap_groupmember_list
,
1104 N_("List users in group"),
1105 N_("net rap groupmember list\n"
1106 " List users in group")
1110 rap_groupmember_delete
,
1112 N_("Remove user from group"),
1113 N_("net rap groupmember delete\n"
1114 " Remove user from group")
1116 {NULL
, NULL
, 0, NULL
, NULL
}
1119 return net_run_function(c
, argc
, argv
, "net rap groupmember", func
);
1122 int net_rap_validate_usage(struct net_context
*c
, int argc
, const char **argv
)
1124 d_printf(_("net rap validate <username> [password]\n"
1125 "\tValidate user and password to check whether they"
1126 " can access target server or domain\n"));
1128 net_common_flags_usage(c
, argc
, argv
);
1132 int net_rap_validate(struct net_context
*c
, int argc
, const char **argv
)
1134 return errmsg_not_implemented();
1137 int net_rap_service_usage(struct net_context
*c
, int argc
, const char **argv
)
1139 d_printf(_("net rap service [misc. options] [targets] \n"
1140 "\tlists all running service daemons on target server\n"));
1141 d_printf(_("\nnet rap service START <name> [service startup arguments]"
1142 " [misc. options] [targets]"
1143 "\n\tStart named service on remote server\n"));
1144 d_printf(_("\nnet rap service STOP <name> [misc. options] [targets]\n"
1145 "\n\tStop named service on remote server\n"));
1147 net_common_flags_usage(c
, argc
, argv
);
1151 static int rap_service_start(struct net_context
*c
, int argc
, const char **argv
)
1153 return errmsg_not_implemented();
1156 static int rap_service_stop(struct net_context
*c
, int argc
, const char **argv
)
1158 return errmsg_not_implemented();
1161 static void service_fn(const char *service_name
, const char *dummy
,
1164 d_printf("%-21.21s\n", service_name
);
1167 int net_rap_service(struct net_context
*c
, int argc
, const char **argv
)
1169 struct functable func
[] = {
1174 N_("Start service on remote server"),
1175 N_("net rap service start\n"
1176 " Start service on remote server")
1182 N_("Stop named serve on remote server"),
1183 N_("net rap service stop\n"
1184 " Stop named serve on remote server")
1186 {NULL
, NULL
, 0, NULL
, NULL
}
1190 struct cli_state
*cli
;
1192 if (c
->display_usage
) {
1193 d_printf(_("Usage:\n"));
1194 d_printf(_("net rap service\n"
1195 " List services on remote server\n"));
1196 net_display_usage_from_functable(func
);
1200 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1203 if (c
->opt_long_list_entries
) {
1204 d_printf(_("Service name Comment\n"
1205 "-----------------------------\n"));
1206 ret
= cli_RNetServiceEnum(cli
, long_group_fn
, NULL
);
1208 ret
= cli_RNetServiceEnum(cli
, service_fn
, NULL
);
1213 return net_run_function(c
, argc
, argv
, "net rap service", func
);
1216 int net_rap_password_usage(struct net_context
*c
, int argc
, const char **argv
)
1219 "net rap password <user> <oldpwo> <newpw> [misc. options] [target]\n"
1220 "\tchanges the password for the specified user at target\n"));
1226 int net_rap_password(struct net_context
*c
, int argc
, const char **argv
)
1228 struct cli_state
*cli
;
1231 if (argc
< 3 || c
->display_usage
)
1232 return net_rap_password_usage(c
, argc
, argv
);
1234 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1237 /* BB Add check for password lengths? */
1238 ret
= cli_oem_change_password(cli
, argv
[0], argv
[2], argv
[1]);
1243 int net_rap_admin_usage(struct net_context
*c
, int argc
, const char **argv
)
1246 "net rap admin <remote command> [cmd args [env]] [misc. options] [targets]"
1247 "\n\texecutes a remote command on an os/2 target server\n"));
1253 int net_rap_admin(struct net_context
*c
, int argc
, const char **argv
)
1255 return errmsg_not_implemented();
1258 /* Entry-point for all the RAP functions. */
1260 int net_rap(struct net_context
*c
, int argc
, const char **argv
)
1262 struct functable func
[] = {
1267 N_("List open files"),
1275 N_("List shares exported by server"),
1276 N_("net rap share\n"
1277 " List shares exported by server")
1283 N_("List open sessions"),
1284 N_("net rap session\n"
1285 " List open sessions")
1291 N_("List servers in workgroup"),
1292 N_("net rap server\n"
1293 " List servers in domain/workgroup")
1299 N_("List domains in network"),
1300 N_("net rap domain\n"
1301 " List domains in network")
1307 N_("List printer queues on server"),
1308 N_("net rap printq\n"
1309 " List printer queues on server")
1323 N_("List user groups"),
1324 N_("net rap group\n"
1325 " List user groups")
1331 N_("Check username/password"),
1332 N_("net rap validate\n"
1333 " Check username/password")
1337 net_rap_groupmember
,
1339 N_("List/modify group memberships"),
1340 N_("net rap groupmember\n"
1341 " List/modify group memberships")
1347 N_("Execute commands on remote OS/2"),
1348 N_("net rap admin\n"
1349 " Execute commands on remote OS/2")
1355 N_("Start/stop remote service"),
1356 N_("net rap service\n"
1357 " Start/stop remote service")
1363 N_("Change user password"),
1364 N_("net rap password\n"
1365 " Change user password")
1367 {NULL
, NULL
, 0, NULL
, NULL
}
1370 return net_run_function(c
, argc
, argv
, "net rap", func
);