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 const char *share_type
[] = {
44 static int errmsg_not_implemented(void)
46 d_printf("\nNot implemented\n");
50 int net_rap_file_usage(struct net_context
*c
, int argc
, const char **argv
)
52 return net_file_usage(c
, argc
, argv
);
55 /***************************************************************************
56 list info on an open file
57 ***************************************************************************/
58 static void file_fn(const char * pPath
, const char * pUser
, uint16 perms
,
59 uint16 locks
, uint32 id
)
61 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
62 id
, pUser
, perms
, locks
, pPath
);
65 static void one_file_fn(const char *pPath
, const char *pUser
, uint16 perms
,
66 uint16 locks
, uint32 id
)
68 d_printf("File ID %d\n"
73 id
, pUser
, locks
, pPath
, perms
);
77 static int rap_file_close(struct net_context
*c
, int argc
, const char **argv
)
79 struct cli_state
*cli
;
81 if (argc
== 0 || c
->display_usage
) {
82 return net_rap_file_usage(c
, argc
, argv
);
85 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
88 ret
= cli_NetFileClose(cli
, atoi(argv
[0]));
93 static int rap_file_info(struct net_context
*c
, int argc
, const char **argv
)
95 struct cli_state
*cli
;
97 if (argc
== 0 || c
->display_usage
)
98 return net_rap_file_usage(c
, argc
, argv
);
100 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
103 ret
= cli_NetFileGetInfo(cli
, atoi(argv
[0]), one_file_fn
);
108 static int rap_file_user(struct net_context
*c
, int argc
, const char **argv
)
110 struct cli_state
*cli
;
113 if (argc
== 0 || c
->display_usage
)
114 return net_rap_file_usage(c
, argc
, argv
);
116 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
119 /* list open files */
121 d_printf("\nEnumerating open files on remote server:\n\n"
122 "\nFileId Opened by Perms Locks Path \n"
123 "------ --------- ----- ----- ---- \n");
124 ret
= cli_NetFileEnum(cli
, argv
[0], NULL
, file_fn
);
127 d_printf("\nOperation not supported by server!\n\n");
133 int net_rap_file(struct net_context
*c
, int argc
, const char **argv
)
135 struct functable func
[] = {
140 "Close specified file on server",
141 "net rap file close\n"
142 " Close specified file on server"
148 "List all files opened by username",
149 "net rap file user\n"
150 " List all files opened by username"
156 "Display info about an opened file",
157 "net rap file info\n"
158 " Display info about an opened file"
160 {NULL
, NULL
, 0, NULL
, NULL
}
164 struct cli_state
*cli
;
167 if (c
->display_usage
) {
168 d_printf("Usage:\n");
169 d_printf("net rap file\n"
170 " List all open files on rempte server\n");
171 net_display_usage_from_functable(func
);
175 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
178 /* list open files */
180 d_printf("\nEnumerating open files on remote server:\n\n"
181 "\nFileId Opened by Perms Locks Path \n"
182 "------ --------- ----- ----- ---- \n");
183 ret
= cli_NetFileEnum(cli
, NULL
, NULL
, file_fn
);
186 d_printf("\nOperation not supported by server!\n\n");
192 return net_run_function(c
, argc
, argv
, "net rap file", func
);
195 int net_rap_share_usage(struct net_context
*c
, int argc
, const char **argv
)
197 return net_share_usage(c
, argc
, argv
);
200 static void long_share_fn(const char *share_name
, uint32 type
,
201 const char *comment
, void *state
)
203 d_printf("%-12s %-8.8s %-50s\n",
204 share_name
, share_type
[type
], comment
);
207 static void share_fn(const char *share_name
, uint32 type
,
208 const char *comment
, void *state
)
210 d_printf("%s\n", share_name
);
213 static int rap_share_delete(struct net_context
*c
, int argc
, const char **argv
)
215 struct cli_state
*cli
;
218 if (argc
== 0 || c
->display_usage
) {
219 return net_rap_share_usage(c
, argc
, argv
);
222 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
225 ret
= cli_NetShareDelete(cli
, argv
[0]);
230 static int rap_share_add(struct net_context
*c
, int argc
, const char **argv
)
232 struct cli_state
*cli
;
235 RAP_SHARE_INFO_2 sinfo
;
239 if (argc
== 0 || c
->display_usage
) {
240 return net_rap_share_usage(c
, argc
, argv
);
243 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
246 sharename
= SMB_STRDUP(argv
[0]);
247 p
= strchr(sharename
, '=');
249 d_printf("Server path not specified\n");
250 SAFE_FREE(sharename
);
251 return net_rap_share_usage(c
, argc
, argv
);
254 strlcpy(sinfo
.share_name
, sharename
, sizeof(sinfo
.share_name
));
255 sinfo
.reserved1
= '\0';
256 sinfo
.share_type
= 0;
257 sinfo
.comment
= smb_xstrdup(c
->opt_comment
);
259 sinfo
.maximum_users
= c
->opt_maxusers
;
260 sinfo
.active_users
= 0;
262 memset(sinfo
.password
, '\0', sizeof(sinfo
.password
));
263 sinfo
.reserved2
= '\0';
265 ret
= cli_NetShareAdd(cli
, &sinfo
);
267 SAFE_FREE(sharename
);
272 int net_rap_share(struct net_context
*c
, int argc
, const char **argv
)
274 struct functable func
[] = {
279 "Delete a share from server",
280 "net rap share delete\n"
281 " Delete a share from server"
287 "Delete a share from server",
288 "net rap share close\n"
289 " Delete a share from server\n"
290 " Alias for net rap share delete"
296 "Add a share to server",
297 "net rap share add\n"
298 " Add a share to server"
300 {NULL
, NULL
, 0, NULL
, NULL
}
304 struct cli_state
*cli
;
307 if (c
->display_usage
) {
308 d_printf("Usage:\n");
309 d_printf("net rap share\n"
310 " List all shares on remote server\n");
311 net_display_usage_from_functable(func
);
315 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
318 if (c
->opt_long_list_entries
) {
320 "\nEnumerating shared resources (exports) on remote server:\n\n"
321 "\nShare name Type Description\n"
322 "---------- ---- -----------\n");
323 ret
= cli_RNetShareEnum(cli
, long_share_fn
, NULL
);
325 ret
= cli_RNetShareEnum(cli
, share_fn
, NULL
);
331 return net_run_function(c
, argc
, argv
, "net rap share", func
);
334 int net_rap_session_usage(struct net_context
*c
, int argc
, const char **argv
)
337 "\nnet rap session [misc. options] [targets]"
338 "\n\tenumerates all active SMB/CIFS sessions on target server\n");
340 "\nnet rap session DELETE <client_name> [misc. options] [targets] \n"
342 "\nnet rap session CLOSE <client_name> [misc. options] [targets]"
343 "\n\tDeletes (closes) a session from specified client to server\n");
345 "\nnet rap session INFO <client_name>"
346 "\n\tEnumerates all open files in specified session\n");
348 net_common_flags_usage(c
, argc
, argv
);
352 static void list_sessions_func(char *wsname
, char *username
, uint16 conns
,
353 uint16 opens
, uint16 users
, uint32 sess_time
,
354 uint32 idle_time
, uint32 user_flags
, char *clitype
)
356 int hrs
= idle_time
/ 3600;
357 int min
= (idle_time
/ 60) % 60;
358 int sec
= idle_time
% 60;
360 d_printf("\\\\%-18.18s %-20.20s %-18.18s %5d %2.2d:%2.2d:%2.2d\n",
361 wsname
, username
, clitype
, opens
, hrs
, min
, sec
);
364 static void display_session_func(const char *wsname
, const char *username
,
365 uint16 conns
, uint16 opens
, uint16 users
,
366 uint32 sess_time
, uint32 idle_time
,
367 uint32 user_flags
, const char *clitype
)
369 int ihrs
= idle_time
/ 3600;
370 int imin
= (idle_time
/ 60) % 60;
371 int isec
= idle_time
% 60;
372 int shrs
= sess_time
/ 3600;
373 int smin
= (sess_time
/ 60) % 60;
374 int ssec
= sess_time
% 60;
375 d_printf("User name %-20.20s\n"
376 "Computer %-20.20s\n"
377 "Guest logon %-20.20s\n"
378 "Client Type %-40.40s\n"
379 "Sess time %2.2d:%2.2d:%2.2d\n"
380 "Idle time %2.2d:%2.2d:%2.2d\n",
382 (user_flags
&0x0)?"yes":"no", clitype
,
383 shrs
, smin
, ssec
, ihrs
, imin
, isec
);
386 static void display_conns_func(uint16 conn_id
, uint16 conn_type
, uint16 opens
,
387 uint16 users
, uint32 conn_time
,
388 const char *username
, const char *netname
)
390 d_printf("%-14.14s %-8.8s %5d\n",
391 netname
, share_type
[conn_type
], opens
);
394 static int rap_session_info(struct net_context
*c
, int argc
, const char **argv
)
396 const char *sessname
;
397 struct cli_state
*cli
;
400 if (argc
== 0 || c
->display_usage
)
401 return net_rap_session_usage(c
, argc
, argv
);
403 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
408 ret
= cli_NetSessionGetInfo(cli
, sessname
, display_session_func
);
414 d_printf("Share name Type # Opens\n-------------------------"
415 "-----------------------------------------------------\n");
416 ret
= cli_NetConnectionEnum(cli
, sessname
, display_conns_func
);
421 static int rap_session_delete(struct net_context
*c
, int argc
, const char **argv
)
423 struct cli_state
*cli
;
426 if (argc
== 0 || c
->display_usage
)
427 return net_rap_session_usage(c
, argc
, argv
);
429 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
432 ret
= cli_NetSessionDel(cli
, argv
[0]);
437 int net_rap_session(struct net_context
*c
, int argc
, const char **argv
)
439 struct functable func
[] = {
444 "Display information about session",
445 "net rap session info\n"
446 " Display information about session"
452 "Close specified session",
453 "net rap session delete\n"
454 " Close specified session\n"
455 " Alias for net rap session close"
461 "Close specified session",
462 "net rap session close\n"
463 " Close specified session"
465 {NULL
, NULL
, 0, NULL
, NULL
}
469 struct cli_state
*cli
;
472 if (c
->display_usage
) {
473 d_printf("Usage:\n");
474 d_printf("net rap session\n"
475 " List all open sessions on remote server\n");
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 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
) {
512 "net rap server name\n"
513 " Get the name of the server\n");
517 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
520 if (!cli_get_server_name(NULL
, cli
, &name
)) {
521 d_fprintf(stderr
, "cli_get_server_name failed\n");
526 d_printf("Server name = %s\n", name
);
533 static int net_rap_server_domain(struct net_context
*c
, int argc
,
536 struct cli_state
*cli
;
539 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 "Get the name of the server",
567 "net rap server name\n"
568 " Get the name of the server"
572 net_rap_server_domain
,
574 "Get the servers in this domain/workgroup",
575 "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 list [<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 "Display info about print job",
737 "net rap printq info\n"
738 " Display info about print job"
744 "Delete print job(s)",
745 "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 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(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
);
833 userinfo
.home_dir
= NULL
;
834 userinfo
.logon_script
= NULL
;
836 ret
= cli_NetUserAdd(cli
, &userinfo
);
842 static int rap_user_info(struct net_context
*c
, int argc
, const char **argv
)
844 struct cli_state
*cli
;
846 if (argc
== 0 || c
->display_usage
) {
847 return net_rap_user_usage(c
, argc
, argv
);
850 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
853 ret
= cli_NetUserGetGroups(cli
, argv
[0], group_member_fn
, NULL
);
858 int net_rap_user(struct net_context
*c
, int argc
, const char **argv
)
861 struct functable func
[] = {
866 "Add specified user",
868 " Add specified user"
874 "List domain groups of specified user",
875 "net rap user info\n"
876 " List domain groups of specified user"
883 "Remove specified user",
884 "net rap user delete\n"
885 " Remove specified user"
887 {NULL
, NULL
, 0, NULL
, NULL
}
891 struct cli_state
*cli
;
892 if (c
->display_usage
) {
893 d_printf("Usage:\n");
894 d_printf("net rap user\n"
895 " List all users\n");
896 net_display_usage_from_functable(func
);
900 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
902 if (c
->opt_long_list_entries
) {
903 d_printf("\nUser name Comment"
904 "\n-----------------------------\n");
905 ret
= cli_RNetUserEnum(cli
, long_user_fn
, NULL
);
909 ret
= cli_RNetUserEnum0(cli
, user_fn
, NULL
);
914 ret
= net_run_function(c
, argc
, argv
, "net rap user", func
);
917 DEBUG(1, ("Net user returned: %d\n", ret
));
923 int net_rap_group_usage(struct net_context
*c
, int argc
, const char **argv
)
925 return net_group_usage(c
, argc
, argv
);
928 static void long_group_fn(const char *group_name
, const char *comment
,
931 d_printf("%-21.21s %s\n", group_name
, comment
);
934 static void group_fn(const char *group_name
, void *state
)
936 d_printf("%-21.21s\n", group_name
);
939 static int rap_group_delete(struct net_context
*c
, int argc
, const char **argv
)
941 struct cli_state
*cli
;
943 if (argc
== 0 || c
->display_usage
) {
944 return net_rap_group_usage(c
, argc
, argv
);
947 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
950 ret
= cli_NetGroupDelete(cli
, argv
[0]);
955 static int rap_group_add(struct net_context
*c
, int argc
, const char **argv
)
957 struct cli_state
*cli
;
959 RAP_GROUP_INFO_1 grinfo
;
961 if (argc
== 0 || c
->display_usage
) {
962 return net_rap_group_usage(c
, argc
, argv
);
965 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
968 /* BB check for length 21 or smaller explicitly ? BB */
969 safe_strcpy(grinfo
.group_name
, argv
[0], sizeof(grinfo
.group_name
)-1);
970 grinfo
.reserved1
= '\0';
971 grinfo
.comment
= smb_xstrdup(c
->opt_comment
);
973 ret
= cli_NetGroupAdd(cli
, &grinfo
);
978 int net_rap_group(struct net_context
*c
, int argc
, const char **argv
)
980 struct functable func
[] = {
985 "Add specified group",
986 "net rap group add\n"
987 " Add specified group"
993 "Delete specified group",
994 "net rap group delete\n"
995 " Delete specified group"
997 {NULL
, NULL
, 0, NULL
, NULL
}
1001 struct cli_state
*cli
;
1003 if (c
->display_usage
) {
1004 d_printf("Usage:\n");
1005 d_printf("net rap group\n"
1006 " List all groups\n");
1007 net_display_usage_from_functable(func
);
1011 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1013 if (c
->opt_long_list_entries
) {
1014 d_printf("Group name Comment\n");
1015 d_printf("-----------------------------\n");
1016 ret
= cli_RNetGroupEnum(cli
, long_group_fn
, NULL
);
1020 ret
= cli_RNetGroupEnum0(cli
, group_fn
, NULL
);
1025 return net_run_function(c
, argc
, argv
, "net rap group", func
);
1028 int net_rap_groupmember_usage(struct net_context
*c
, int argc
, const char **argv
)
1031 "net rap groupmember LIST <group> [misc. options] [targets]"
1032 "\n\t Enumerate users in a group\n"
1033 "\nnet rap groupmember DELETE <group> <user> [misc. options] "
1034 "[targets]\n\t Delete sepcified user from specified group\n"
1035 "\nnet rap groupmember ADD <group> <user> [misc. options] [targets]"
1036 "\n\t Add specified user to specified group\n");
1038 net_common_flags_usage(c
, argc
, argv
);
1043 static int rap_groupmember_add(struct net_context
*c
, int argc
, const char **argv
)
1045 struct cli_state
*cli
;
1047 if (argc
!= 2 || c
->display_usage
) {
1048 return net_rap_groupmember_usage(c
, argc
, argv
);
1051 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1054 ret
= cli_NetGroupAddUser(cli
, argv
[0], argv
[1]);
1059 static int rap_groupmember_delete(struct net_context
*c
, int argc
, const char **argv
)
1061 struct cli_state
*cli
;
1063 if (argc
!= 2 || c
->display_usage
) {
1064 return net_rap_groupmember_usage(c
, argc
, argv
);
1067 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1070 ret
= cli_NetGroupDelUser(cli
, argv
[0], argv
[1]);
1075 static int rap_groupmember_list(struct net_context
*c
, int argc
, const char **argv
)
1077 struct cli_state
*cli
;
1079 if (argc
== 0 || c
->display_usage
) {
1080 return net_rap_groupmember_usage(c
, argc
, argv
);
1083 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1086 ret
= cli_NetGroupGetUsers(cli
, argv
[0], group_member_fn
, NULL
);
1091 int net_rap_groupmember(struct net_context
*c
, int argc
, const char **argv
)
1093 struct functable func
[] = {
1096 rap_groupmember_add
,
1098 "Add specified user to group",
1099 "net rap groupmember add\n"
1100 " Add specified user to group"
1104 rap_groupmember_list
,
1106 "List users in group",
1107 "net rap groupmember list\n"
1108 " List users in group"
1112 rap_groupmember_delete
,
1114 "Remove user from group",
1115 "net rap groupmember delete\n"
1116 " Remove user from group"
1118 {NULL
, NULL
, 0, NULL
, NULL
}
1121 return net_run_function(c
, argc
, argv
, "net rap groupmember", func
);
1124 int net_rap_validate_usage(struct net_context
*c
, int argc
, const char **argv
)
1126 d_printf("net rap validate <username> [password]\n"
1127 "\tValidate user and password to check whether they"
1128 " can access target server or domain\n");
1130 net_common_flags_usage(c
, argc
, argv
);
1134 int net_rap_validate(struct net_context
*c
, int argc
, const char **argv
)
1136 return errmsg_not_implemented();
1139 int net_rap_service_usage(struct net_context
*c
, int argc
, const char **argv
)
1141 d_printf("net rap service [misc. options] [targets] \n"
1142 "\tlists all running service daemons on target server\n");
1143 d_printf("\nnet rap service START <name> [service startup arguments]"
1144 " [misc. options] [targets]"
1145 "\n\tStart named service on remote server\n");
1146 d_printf("\nnet rap service STOP <name> [misc. options] [targets]\n"
1147 "\n\tStop named service on remote server\n");
1149 net_common_flags_usage(c
, argc
, argv
);
1153 static int rap_service_start(struct net_context
*c
, int argc
, const char **argv
)
1155 return errmsg_not_implemented();
1158 static int rap_service_stop(struct net_context
*c
, int argc
, const char **argv
)
1160 return errmsg_not_implemented();
1163 static void service_fn(const char *service_name
, const char *dummy
,
1166 d_printf("%-21.21s\n", service_name
);
1169 int net_rap_service(struct net_context
*c
, int argc
, const char **argv
)
1171 struct functable func
[] = {
1176 "Start service on remote server",
1177 "net rap service start\n"
1178 " Start service on remote server"
1184 "Stop named serve on remote server",
1185 "net rap service stop\n"
1186 " Stop named serve on remote server"
1188 {NULL
, NULL
, 0, NULL
, NULL
}
1192 struct cli_state
*cli
;
1194 if (c
->display_usage
) {
1195 d_printf("Usage:\n");
1196 d_printf("net rap service\n"
1197 " List services on remote server\n");
1198 net_display_usage_from_functable(func
);
1202 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1205 if (c
->opt_long_list_entries
) {
1206 d_printf("Service name Comment\n");
1207 d_printf("-----------------------------\n");
1208 ret
= cli_RNetServiceEnum(cli
, long_group_fn
, NULL
);
1210 ret
= cli_RNetServiceEnum(cli
, service_fn
, NULL
);
1215 return net_run_function(c
, argc
, argv
, "net rap service", func
);
1218 int net_rap_password_usage(struct net_context
*c
, int argc
, const char **argv
)
1221 "net rap password <user> <oldpwo> <newpw> [misc. options] [target]\n"
1222 "\tchanges the password for the specified user at target\n");
1228 int net_rap_password(struct net_context
*c
, int argc
, const char **argv
)
1230 struct cli_state
*cli
;
1233 if (argc
< 3 || c
->display_usage
)
1234 return net_rap_password_usage(c
, argc
, argv
);
1236 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1239 /* BB Add check for password lengths? */
1240 ret
= cli_oem_change_password(cli
, argv
[0], argv
[2], argv
[1]);
1245 int net_rap_admin_usage(struct net_context
*c
, int argc
, const char **argv
)
1248 "net rap admin <remote command> [cmd args [env]] [misc. options] [targets]"
1249 "\n\texecutes a remote command on an os/2 target server\n");
1255 int net_rap_admin(struct net_context
*c
, int argc
, const char **argv
)
1257 return errmsg_not_implemented();
1260 /* Entry-point for all the RAP functions. */
1262 int net_rap(struct net_context
*c
, int argc
, const char **argv
)
1264 struct functable func
[] = {
1277 "List shares exported by server",
1279 " List shares exported by server"
1285 "List open sessions",
1287 " List open sessions"
1293 "List servers in workgroup",
1295 " List servers in domain/workgroup"
1301 "List domains in network",
1303 " List domains in network"
1309 "List printer queues on server",
1311 " List printer queues on server"
1333 "Check username/password",
1334 "net rap validate\n"
1335 " Check username/password"
1339 net_rap_groupmember
,
1341 "List/modify group memberships",
1342 "net rap groupmember\n"
1343 " List/modify group memberships"
1349 "Execute commands on remote OS/2",
1351 " Execute commands on remote OS/2"
1357 "Start/stop remote service",
1359 " Start/stop remote service"
1365 "Change user password",
1366 "net rap password\n"
1367 " Change user password"
1369 {NULL
, NULL
, 0, NULL
, NULL
}
1372 return net_run_function(c
, argc
, argv
, "net rap", func
);