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"
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 "Close specified file on server",
134 "net rap file close\n"
135 " Close specified file on server"
141 "List all files opened by username",
142 "net rap file user\n"
143 " List all files opened by username"
149 "Display info about an opened file",
150 "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 server\n");
164 net_display_usage_from_functable(func
);
168 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
171 /* list open files */
173 d_printf("\nEnumerating open files on remote server:\n\n"
174 "\nFileId Opened by Perms Locks Path \n"
175 "------ --------- ----- ----- ---- \n");
176 ret
= cli_NetFileEnum(cli
, NULL
, NULL
, file_fn
);
179 d_printf("\nOperation not supported by server!\n\n");
185 return net_run_function(c
, argc
, argv
, "net rap file", func
);
188 int net_rap_share_usage(struct net_context
*c
, int argc
, const char **argv
)
190 return net_share_usage(c
, argc
, argv
);
193 static void long_share_fn(const char *share_name
, uint32 type
,
194 const char *comment
, void *state
)
196 d_printf("%-12s %-8.8s %-50s\n",
197 share_name
, net_share_type_str(type
), comment
);
200 static void share_fn(const char *share_name
, uint32 type
,
201 const char *comment
, void *state
)
203 d_printf("%s\n", share_name
);
206 static int rap_share_delete(struct net_context
*c
, int argc
, const char **argv
)
208 struct cli_state
*cli
;
211 if (argc
== 0 || c
->display_usage
) {
212 return net_rap_share_usage(c
, argc
, argv
);
215 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
218 ret
= cli_NetShareDelete(cli
, argv
[0]);
223 static int rap_share_add(struct net_context
*c
, int argc
, const char **argv
)
225 struct cli_state
*cli
;
228 RAP_SHARE_INFO_2 sinfo
;
232 if (argc
== 0 || c
->display_usage
) {
233 return net_rap_share_usage(c
, argc
, argv
);
236 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
239 sharename
= SMB_STRDUP(argv
[0]);
240 p
= strchr(sharename
, '=');
242 d_printf("Server path not specified\n");
243 SAFE_FREE(sharename
);
244 return net_rap_share_usage(c
, argc
, argv
);
247 strlcpy(sinfo
.share_name
, sharename
, sizeof(sinfo
.share_name
));
248 sinfo
.reserved1
= '\0';
249 sinfo
.share_type
= 0;
250 sinfo
.comment
= smb_xstrdup(c
->opt_comment
);
252 sinfo
.maximum_users
= c
->opt_maxusers
;
253 sinfo
.active_users
= 0;
255 memset(sinfo
.password
, '\0', sizeof(sinfo
.password
));
256 sinfo
.reserved2
= '\0';
258 ret
= cli_NetShareAdd(cli
, &sinfo
);
260 SAFE_FREE(sharename
);
265 int net_rap_share(struct net_context
*c
, int argc
, const char **argv
)
267 struct functable func
[] = {
272 "Delete a share from server",
273 "net rap share delete\n"
274 " Delete a share from server"
280 "Delete a share from server",
281 "net rap share close\n"
282 " Delete a share from server\n"
283 " Alias for net rap share delete"
289 "Add a share to server",
290 "net rap share add\n"
291 " Add a share to server"
293 {NULL
, NULL
, 0, NULL
, NULL
}
297 struct cli_state
*cli
;
300 if (c
->display_usage
) {
301 d_printf("Usage:\n");
302 d_printf("net rap share\n"
303 " List all shares on remote server\n");
304 net_display_usage_from_functable(func
);
308 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
311 if (c
->opt_long_list_entries
) {
313 "\nEnumerating shared resources (exports) on remote server:\n\n"
314 "\nShare name Type Description\n"
315 "---------- ---- -----------\n");
316 ret
= cli_RNetShareEnum(cli
, long_share_fn
, NULL
);
318 ret
= cli_RNetShareEnum(cli
, share_fn
, NULL
);
324 return net_run_function(c
, argc
, argv
, "net rap share", func
);
327 int net_rap_session_usage(struct net_context
*c
, int argc
, const char **argv
)
330 "\nnet rap session [misc. options] [targets]"
331 "\n\tenumerates all active SMB/CIFS sessions on target server\n");
333 "\nnet rap session DELETE <client_name> [misc. options] [targets] \n"
335 "\nnet rap session CLOSE <client_name> [misc. options] [targets]"
336 "\n\tDeletes (closes) a session from specified client to server\n");
338 "\nnet rap session INFO <client_name>"
339 "\n\tEnumerates all open files in specified session\n");
341 net_common_flags_usage(c
, argc
, argv
);
345 static void list_sessions_func(char *wsname
, char *username
, uint16 conns
,
346 uint16 opens
, uint16 users
, uint32 sess_time
,
347 uint32 idle_time
, uint32 user_flags
, char *clitype
)
349 int hrs
= idle_time
/ 3600;
350 int min
= (idle_time
/ 60) % 60;
351 int sec
= idle_time
% 60;
353 d_printf("\\\\%-18.18s %-20.20s %-18.18s %5d %2.2d:%2.2d:%2.2d\n",
354 wsname
, username
, clitype
, opens
, hrs
, min
, sec
);
357 static void display_session_func(const char *wsname
, const char *username
,
358 uint16 conns
, uint16 opens
, uint16 users
,
359 uint32 sess_time
, uint32 idle_time
,
360 uint32 user_flags
, const char *clitype
)
362 int ihrs
= idle_time
/ 3600;
363 int imin
= (idle_time
/ 60) % 60;
364 int isec
= idle_time
% 60;
365 int shrs
= sess_time
/ 3600;
366 int smin
= (sess_time
/ 60) % 60;
367 int ssec
= sess_time
% 60;
368 d_printf("User name %-20.20s\n"
369 "Computer %-20.20s\n"
370 "Guest logon %-20.20s\n"
371 "Client Type %-40.40s\n"
372 "Sess time %2.2d:%2.2d:%2.2d\n"
373 "Idle time %2.2d:%2.2d:%2.2d\n",
375 (user_flags
&0x0)?"yes":"no", clitype
,
376 shrs
, smin
, ssec
, ihrs
, imin
, isec
);
379 static void display_conns_func(uint16 conn_id
, uint16 conn_type
, uint16 opens
,
380 uint16 users
, uint32 conn_time
,
381 const char *username
, const char *netname
)
383 d_printf("%-14.14s %-8.8s %5d\n",
384 netname
, net_share_type_str(conn_type
), opens
);
387 static int rap_session_info(struct net_context
*c
, int argc
, const char **argv
)
389 const char *sessname
;
390 struct cli_state
*cli
;
393 if (argc
== 0 || c
->display_usage
)
394 return net_rap_session_usage(c
, argc
, argv
);
396 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
401 ret
= cli_NetSessionGetInfo(cli
, sessname
, display_session_func
);
407 d_printf("Share name Type # Opens\n-------------------------"
408 "-----------------------------------------------------\n");
409 ret
= cli_NetConnectionEnum(cli
, sessname
, display_conns_func
);
414 static int rap_session_delete(struct net_context
*c
, int argc
, const char **argv
)
416 struct cli_state
*cli
;
419 if (argc
== 0 || c
->display_usage
)
420 return net_rap_session_usage(c
, argc
, argv
);
422 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
425 ret
= cli_NetSessionDel(cli
, argv
[0]);
430 int net_rap_session(struct net_context
*c
, int argc
, const char **argv
)
432 struct functable func
[] = {
437 "Display information about session",
438 "net rap session info\n"
439 " Display information about session"
445 "Close specified session",
446 "net rap session delete\n"
447 " Close specified session\n"
448 " Alias for net rap session close"
454 "Close specified session",
455 "net rap session close\n"
456 " Close specified session"
458 {NULL
, NULL
, 0, NULL
, NULL
}
462 struct cli_state
*cli
;
465 if (c
->display_usage
) {
466 d_printf("Usage:\n");
467 d_printf("net rap session\n"
468 " List all open sessions on remote server\n");
469 net_display_usage_from_functable(func
);
473 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
476 d_printf("Computer User name "
477 "Client Type Opens Idle time\n"
478 "------------------------------------------"
479 "------------------------------------\n");
480 ret
= cli_NetSessionEnum(cli
, list_sessions_func
);
486 return net_run_function(c
, argc
, argv
, "net rap session", func
);
489 /****************************************************************************
491 ****************************************************************************/
492 static void display_server_func(const char *name
, uint32 m
,
493 const char *comment
, void * reserved
)
495 d_printf("\t%-16.16s %s\n", name
, comment
);
498 static int net_rap_server_name(struct net_context
*c
, int argc
, const char *argv
[])
500 struct cli_state
*cli
;
503 if (c
->display_usage
) {
505 "net rap server name\n"
506 " Get the name of the server\n");
510 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
513 if (!cli_get_server_name(NULL
, cli
, &name
)) {
514 d_fprintf(stderr
, "cli_get_server_name failed\n");
519 d_printf("Server name = %s\n", name
);
526 static int net_rap_server_domain(struct net_context
*c
, int argc
,
529 struct cli_state
*cli
;
532 if (c
->display_usage
) {
534 "net rap server domain\n"
535 " Enumerate servers in this domain/workgroup\n");
539 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
542 d_printf("\nEnumerating servers in this domain or workgroup: \n\n"
543 "\tServer name Server description\n"
544 "\t------------- ----------------------------\n");
546 ret
= cli_NetServerEnum(cli
, cli
->server_domain
, SV_TYPE_ALL
,
547 display_server_func
,NULL
);
552 int net_rap_server(struct net_context
*c
, int argc
, const char **argv
)
554 struct functable func
[] = {
559 "Get the name of the server",
560 "net rap server name\n"
561 " Get the name of the server"
565 net_rap_server_domain
,
567 "Get the servers in this domain/workgroup",
568 "net rap server domain\n"
569 " Get the servers in this domain/workgroup"
571 {NULL
, NULL
, 0, NULL
, NULL
}
574 /* smb4k uses 'net [rap|rpc] server domain' to query servers in a domain */
575 /* Fall through for 'domain', any other forms will cause to show usage message */
576 return net_run_function(c
, argc
, argv
, "net rap server", func
);
580 int net_rap_domain_usage(struct net_context
*c
, int argc
, const char **argv
)
582 d_printf("net rap domain [misc. options] [target]\n\tlists the"
583 " domains or workgroups visible on the current network\n");
585 net_common_flags_usage(c
, argc
, argv
);
589 int net_rap_domain(struct net_context
*c
, int argc
, const char **argv
)
591 struct cli_state
*cli
;
594 if (c
->display_usage
)
595 return net_rap_domain_usage(c
, argc
, argv
);
597 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
600 d_printf("\nEnumerating domains:\n\n"
601 "\tDomain name Server name of Browse Master\n"
602 "\t------------- ----------------------------\n");
604 ret
= cli_NetServerEnum(cli
, cli
->server_domain
, SV_TYPE_DOMAIN_ENUM
,
605 display_server_func
,NULL
);
610 int net_rap_printq_usage(struct net_context
*c
, int argc
, const char **argv
)
613 "net rap printq [misc. options] [targets]\n"
615 "net rap printq info [<queue_name>] [misc. options] [targets]\n"
616 "\tlists the specified queue and jobs on the target server.\n"
617 "\tIf the queue name is not specified, all queues are listed.\n\n");
619 "net rap printq delete [<queue name>] [misc. options] [targets]\n"
620 "\tdeletes the specified job number on the target server, or the\n"
621 "\tprinter queue if no job number is specified\n");
623 net_common_flags_usage(c
, argc
, argv
);
628 static void enum_queue(const char *queuename
, uint16 pri
, uint16 start
,
629 uint16 until
, const char *sep
, const char *pproc
,
630 const char *dest
, const char *qparms
,
631 const char *qcomment
, uint16 status
, uint16 jobcount
)
633 d_printf("%-17.17s Queue %5d jobs ",
634 queuename
, jobcount
);
638 d_printf("*Printer Active*\n");
641 d_printf("*Printer Paused*\n");
644 d_printf("*Printer error*\n");
647 d_printf("*Delete Pending*\n");
650 d_printf("**UNKNOWN STATUS**\n");
654 static void enum_jobs(uint16 jobid
, const char *ownername
,
655 const char *notifyname
, const char *datatype
,
656 const char *jparms
, uint16 pos
, uint16 status
,
657 const char *jstatus
, unsigned int submitted
, unsigned int jobsize
,
660 d_printf(" %-23.23s %5d %9d ",
661 ownername
, jobid
, jobsize
);
664 d_printf("Waiting\n");
667 d_printf("Held in queue\n");
670 d_printf("Spooling\n");
673 d_printf("Printing\n");
676 d_printf("**UNKNOWN STATUS**\n");
680 #define PRINTQ_ENUM_DISPLAY \
681 "Print queues at \\\\%s\n\n"\
682 "Name Job # Size Status\n\n"\
683 "------------------------------------------------------------------"\
686 static int rap_printq_info(struct net_context
*c
, int argc
, const char **argv
)
688 struct cli_state
*cli
;
691 if (argc
== 0 || c
->display_usage
)
692 return net_rap_printq_usage(c
, argc
, argv
);
694 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
697 d_printf(PRINTQ_ENUM_DISPLAY
, cli
->desthost
); /* list header */
698 ret
= cli_NetPrintQGetInfo(cli
, argv
[0], enum_queue
, enum_jobs
);
703 static int rap_printq_delete(struct net_context
*c
, int argc
, const char **argv
)
705 struct cli_state
*cli
;
708 if (argc
== 0 || c
->display_usage
)
709 return net_rap_printq_usage(c
, argc
, argv
);
711 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
714 ret
= cli_printjob_del(cli
, atoi(argv
[0]));
719 int net_rap_printq(struct net_context
*c
, int argc
, const char **argv
)
721 struct cli_state
*cli
;
724 struct functable func
[] = {
729 "Display info about print queues and jobs",
730 "net rap printq info [queue]\n"
731 " Display info about print jobs in queue.\n"
732 " If queue is not specified, all queues are listed"
738 "Delete print job(s)",
739 "net rap printq delete\n"
740 " Delete print job(s)"
742 {NULL
, NULL
, 0, NULL
, NULL
}
746 if (c
->display_usage
) {
747 d_printf("Usage:\n");
748 d_printf("net rap printq\n"
749 " List the print queue\n");
750 net_display_usage_from_functable(func
);
754 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
757 d_printf(PRINTQ_ENUM_DISPLAY
, cli
->desthost
); /* list header */
758 ret
= cli_NetPrintQEnum(cli
, enum_queue
, enum_jobs
);
763 return net_run_function(c
, argc
, argv
, "net rap printq", func
);
766 static int net_rap_user_usage(struct net_context
*c
, int argc
, const char **argv
)
768 return net_user_usage(c
, argc
, argv
);
771 static void user_fn(const char *user_name
, void *state
)
773 d_printf("%-21.21s\n", user_name
);
776 static void long_user_fn(const char *user_name
, const char *comment
,
777 const char * home_dir
, const char * logon_script
,
780 d_printf("%-21.21s %s\n",
784 static void group_member_fn(const char *user_name
, void *state
)
786 d_printf("%-21.21s\n", user_name
);
789 static int rap_user_delete(struct net_context
*c
, int argc
, const char **argv
)
791 struct cli_state
*cli
;
794 if (argc
== 0 || c
->display_usage
) {
795 return net_rap_user_usage(c
, argc
, argv
);
798 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
801 ret
= cli_NetUserDelete(cli
, argv
[0]);
806 static int rap_user_add(struct net_context
*c
, int argc
, const char **argv
)
808 struct cli_state
*cli
;
810 RAP_USER_INFO_1 userinfo
;
812 if (argc
== 0 || c
->display_usage
) {
813 return net_rap_user_usage(c
, argc
, argv
);
816 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
819 safe_strcpy(userinfo
.user_name
, argv
[0], sizeof(userinfo
.user_name
)-1);
820 if (c
->opt_flags
== -1)
823 userinfo
.userflags
= c
->opt_flags
;
824 userinfo
.reserved1
= '\0';
825 userinfo
.comment
= smb_xstrdup(c
->opt_comment
);
827 userinfo
.home_dir
= NULL
;
828 userinfo
.logon_script
= NULL
;
830 ret
= cli_NetUserAdd(cli
, &userinfo
);
836 static int rap_user_info(struct net_context
*c
, int argc
, const char **argv
)
838 struct cli_state
*cli
;
840 if (argc
== 0 || c
->display_usage
) {
841 return net_rap_user_usage(c
, argc
, argv
);
844 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
847 ret
= cli_NetUserGetGroups(cli
, argv
[0], group_member_fn
, NULL
);
852 int net_rap_user(struct net_context
*c
, int argc
, const char **argv
)
855 struct functable func
[] = {
860 "Add specified user",
862 " Add specified user"
868 "List domain groups of specified user",
869 "net rap user info\n"
870 " List domain groups of specified user"
877 "Remove specified user",
878 "net rap user delete\n"
879 " Remove specified user"
881 {NULL
, NULL
, 0, NULL
, NULL
}
885 struct cli_state
*cli
;
886 if (c
->display_usage
) {
887 d_printf("Usage:\n");
888 d_printf("net rap user\n"
889 " List all users\n");
890 net_display_usage_from_functable(func
);
894 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
896 if (c
->opt_long_list_entries
) {
897 d_printf("\nUser name Comment"
898 "\n-----------------------------\n");
899 ret
= cli_RNetUserEnum(cli
, long_user_fn
, NULL
);
903 ret
= cli_RNetUserEnum0(cli
, user_fn
, NULL
);
908 ret
= net_run_function(c
, argc
, argv
, "net rap user", func
);
911 DEBUG(1, ("Net user returned: %d\n", ret
));
917 int net_rap_group_usage(struct net_context
*c
, int argc
, const char **argv
)
919 return net_group_usage(c
, argc
, argv
);
922 static void long_group_fn(const char *group_name
, const char *comment
,
925 d_printf("%-21.21s %s\n", group_name
, comment
);
928 static void group_fn(const char *group_name
, void *state
)
930 d_printf("%-21.21s\n", group_name
);
933 static int rap_group_delete(struct net_context
*c
, int argc
, const char **argv
)
935 struct cli_state
*cli
;
937 if (argc
== 0 || c
->display_usage
) {
938 return net_rap_group_usage(c
, argc
, argv
);
941 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
944 ret
= cli_NetGroupDelete(cli
, argv
[0]);
949 static int rap_group_add(struct net_context
*c
, int argc
, const char **argv
)
951 struct cli_state
*cli
;
953 RAP_GROUP_INFO_1 grinfo
;
955 if (argc
== 0 || c
->display_usage
) {
956 return net_rap_group_usage(c
, argc
, argv
);
959 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
962 /* BB check for length 21 or smaller explicitly ? BB */
963 safe_strcpy(grinfo
.group_name
, argv
[0], sizeof(grinfo
.group_name
)-1);
964 grinfo
.reserved1
= '\0';
965 grinfo
.comment
= smb_xstrdup(c
->opt_comment
);
967 ret
= cli_NetGroupAdd(cli
, &grinfo
);
972 int net_rap_group(struct net_context
*c
, int argc
, const char **argv
)
974 struct functable func
[] = {
979 "Add specified group",
980 "net rap group add\n"
981 " Add specified group"
987 "Delete specified group",
988 "net rap group delete\n"
989 " Delete specified group"
991 {NULL
, NULL
, 0, NULL
, NULL
}
995 struct cli_state
*cli
;
997 if (c
->display_usage
) {
998 d_printf("Usage:\n");
999 d_printf("net rap group\n"
1000 " List all groups\n");
1001 net_display_usage_from_functable(func
);
1005 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1007 if (c
->opt_long_list_entries
) {
1008 d_printf("Group name Comment\n");
1009 d_printf("-----------------------------\n");
1010 ret
= cli_RNetGroupEnum(cli
, long_group_fn
, NULL
);
1014 ret
= cli_RNetGroupEnum0(cli
, group_fn
, NULL
);
1019 return net_run_function(c
, argc
, argv
, "net rap group", func
);
1022 int net_rap_groupmember_usage(struct net_context
*c
, int argc
, const char **argv
)
1025 "net rap groupmember LIST <group> [misc. options] [targets]"
1026 "\n\t Enumerate users in a group\n"
1027 "\nnet rap groupmember DELETE <group> <user> [misc. options] "
1028 "[targets]\n\t Delete specified user from specified group\n"
1029 "\nnet rap groupmember ADD <group> <user> [misc. options] [targets]"
1030 "\n\t Add specified user to specified group\n");
1032 net_common_flags_usage(c
, argc
, argv
);
1037 static int rap_groupmember_add(struct net_context
*c
, int argc
, const char **argv
)
1039 struct cli_state
*cli
;
1041 if (argc
!= 2 || c
->display_usage
) {
1042 return net_rap_groupmember_usage(c
, argc
, argv
);
1045 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1048 ret
= cli_NetGroupAddUser(cli
, argv
[0], argv
[1]);
1053 static int rap_groupmember_delete(struct net_context
*c
, int argc
, const char **argv
)
1055 struct cli_state
*cli
;
1057 if (argc
!= 2 || c
->display_usage
) {
1058 return net_rap_groupmember_usage(c
, argc
, argv
);
1061 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1064 ret
= cli_NetGroupDelUser(cli
, argv
[0], argv
[1]);
1069 static int rap_groupmember_list(struct net_context
*c
, int argc
, const char **argv
)
1071 struct cli_state
*cli
;
1073 if (argc
== 0 || c
->display_usage
) {
1074 return net_rap_groupmember_usage(c
, argc
, argv
);
1077 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1080 ret
= cli_NetGroupGetUsers(cli
, argv
[0], group_member_fn
, NULL
);
1085 int net_rap_groupmember(struct net_context
*c
, int argc
, const char **argv
)
1087 struct functable func
[] = {
1090 rap_groupmember_add
,
1092 "Add specified user to group",
1093 "net rap groupmember add\n"
1094 " Add specified user to group"
1098 rap_groupmember_list
,
1100 "List users in group",
1101 "net rap groupmember list\n"
1102 " List users in group"
1106 rap_groupmember_delete
,
1108 "Remove user from group",
1109 "net rap groupmember delete\n"
1110 " Remove user from group"
1112 {NULL
, NULL
, 0, NULL
, NULL
}
1115 return net_run_function(c
, argc
, argv
, "net rap groupmember", func
);
1118 int net_rap_validate_usage(struct net_context
*c
, int argc
, const char **argv
)
1120 d_printf("net rap validate <username> [password]\n"
1121 "\tValidate user and password to check whether they"
1122 " can access target server or domain\n");
1124 net_common_flags_usage(c
, argc
, argv
);
1128 int net_rap_validate(struct net_context
*c
, int argc
, const char **argv
)
1130 return errmsg_not_implemented();
1133 int net_rap_service_usage(struct net_context
*c
, int argc
, const char **argv
)
1135 d_printf("net rap service [misc. options] [targets] \n"
1136 "\tlists all running service daemons on target server\n");
1137 d_printf("\nnet rap service START <name> [service startup arguments]"
1138 " [misc. options] [targets]"
1139 "\n\tStart named service on remote server\n");
1140 d_printf("\nnet rap service STOP <name> [misc. options] [targets]\n"
1141 "\n\tStop named service on remote server\n");
1143 net_common_flags_usage(c
, argc
, argv
);
1147 static int rap_service_start(struct net_context
*c
, int argc
, const char **argv
)
1149 return errmsg_not_implemented();
1152 static int rap_service_stop(struct net_context
*c
, int argc
, const char **argv
)
1154 return errmsg_not_implemented();
1157 static void service_fn(const char *service_name
, const char *dummy
,
1160 d_printf("%-21.21s\n", service_name
);
1163 int net_rap_service(struct net_context
*c
, int argc
, const char **argv
)
1165 struct functable func
[] = {
1170 "Start service on remote server",
1171 "net rap service start\n"
1172 " Start service on remote server"
1178 "Stop named serve on remote server",
1179 "net rap service stop\n"
1180 " Stop named serve on remote server"
1182 {NULL
, NULL
, 0, NULL
, NULL
}
1186 struct cli_state
*cli
;
1188 if (c
->display_usage
) {
1189 d_printf("Usage:\n");
1190 d_printf("net rap service\n"
1191 " List services on remote server\n");
1192 net_display_usage_from_functable(func
);
1196 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1199 if (c
->opt_long_list_entries
) {
1200 d_printf("Service name Comment\n");
1201 d_printf("-----------------------------\n");
1202 ret
= cli_RNetServiceEnum(cli
, long_group_fn
, NULL
);
1204 ret
= cli_RNetServiceEnum(cli
, service_fn
, NULL
);
1209 return net_run_function(c
, argc
, argv
, "net rap service", func
);
1212 int net_rap_password_usage(struct net_context
*c
, int argc
, const char **argv
)
1215 "net rap password <user> <oldpwo> <newpw> [misc. options] [target]\n"
1216 "\tchanges the password for the specified user at target\n");
1222 int net_rap_password(struct net_context
*c
, int argc
, const char **argv
)
1224 struct cli_state
*cli
;
1227 if (argc
< 3 || c
->display_usage
)
1228 return net_rap_password_usage(c
, argc
, argv
);
1230 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c
, 0, &cli
)))
1233 /* BB Add check for password lengths? */
1234 ret
= cli_oem_change_password(cli
, argv
[0], argv
[2], argv
[1]);
1239 int net_rap_admin_usage(struct net_context
*c
, int argc
, const char **argv
)
1242 "net rap admin <remote command> [cmd args [env]] [misc. options] [targets]"
1243 "\n\texecutes a remote command on an os/2 target server\n");
1249 int net_rap_admin(struct net_context
*c
, int argc
, const char **argv
)
1251 return errmsg_not_implemented();
1254 /* Entry-point for all the RAP functions. */
1256 int net_rap(struct net_context
*c
, int argc
, const char **argv
)
1258 struct functable func
[] = {
1271 "List shares exported by server",
1273 " List shares exported by server"
1279 "List open sessions",
1281 " List open sessions"
1287 "List servers in workgroup",
1289 " List servers in domain/workgroup"
1295 "List domains in network",
1297 " List domains in network"
1303 "List printer queues on server",
1305 " List printer queues on server"
1327 "Check username/password",
1328 "net rap validate\n"
1329 " Check username/password"
1333 net_rap_groupmember
,
1335 "List/modify group memberships",
1336 "net rap groupmember\n"
1337 " List/modify group memberships"
1343 "Execute commands on remote OS/2",
1345 " Execute commands on remote OS/2"
1351 "Start/stop remote service",
1353 " Start/stop remote service"
1359 "Change user password",
1360 "net rap password\n"
1361 " Change user password"
1363 {NULL
, NULL
, 0, NULL
, NULL
}
1366 return net_run_function(c
, argc
, argv
, "net rap", func
);