Document how to enable the name aliasing support in Winbind.
[Samba.git] / source / utils / net_rap.c
blob883524dc2df247f9e767b925fd11169699b6f55e
1 /*
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
10 November 2001.
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/>. */
25 #include "includes.h"
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[] = {
38 "Disk",
39 "Print",
40 "Dev",
41 "IPC"
44 static int errmsg_not_implemented(void)
46 d_printf("\nNot implemented\n");
47 return 0;
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"
69 "User name %s\n"
70 "Locks 0x%-4.2x\n"
71 "Path %s\n"
72 "Permissions 0x%x\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;
80 int ret;
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)))
86 return -1;
88 ret = cli_NetFileClose(cli, atoi(argv[0]));
89 cli_shutdown(cli);
90 return ret;
93 static int rap_file_info(struct net_context *c, int argc, const char **argv)
95 struct cli_state *cli;
96 int ret;
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)))
101 return -1;
103 ret = cli_NetFileGetInfo(cli, atoi(argv[0]), one_file_fn);
104 cli_shutdown(cli);
105 return ret;
108 static int rap_file_user(struct net_context *c, int argc, const char **argv)
110 struct cli_state *cli;
111 int ret;
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)))
117 return -1;
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);
126 if (ret == -1)
127 d_printf("\nOperation not supported by server!\n\n");
129 cli_shutdown(cli);
130 return ret;
133 int net_rap_file(struct net_context *c, int argc, const char **argv)
135 struct functable func[] = {
137 "close",
138 rap_file_close,
139 NET_TRANSPORT_RAP,
140 "Close specified file on server",
141 "net rap file close\n"
142 " Close specified file on server"
145 "user",
146 rap_file_user,
147 NET_TRANSPORT_RAP,
148 "List all files opened by username",
149 "net rap file user\n"
150 " List all files opened by username"
153 "info",
154 rap_file_info,
155 NET_TRANSPORT_RAP,
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}
163 if (argc == 0) {
164 struct cli_state *cli;
165 int ret;
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);
172 return 0;
175 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
176 return -1;
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);
185 if (ret == -1)
186 d_printf("\nOperation not supported by server!\n\n");
188 cli_shutdown(cli);
189 return ret;
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;
216 int ret;
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)))
223 return -1;
225 ret = cli_NetShareDelete(cli, argv[0]);
226 cli_shutdown(cli);
227 return ret;
230 static int rap_share_add(struct net_context *c, int argc, const char **argv)
232 struct cli_state *cli;
233 int ret;
235 RAP_SHARE_INFO_2 sinfo;
236 char *p;
237 char *sharename;
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)))
244 return -1;
246 sharename = SMB_STRDUP(argv[0]);
247 p = strchr(sharename, '=');
248 if (p == NULL) {
249 d_printf("Server path not specified\n");
250 SAFE_FREE(sharename);
251 return net_rap_share_usage(c, argc, argv);
253 *p = 0;
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);
258 sinfo.perms = 0;
259 sinfo.maximum_users = c->opt_maxusers;
260 sinfo.active_users = 0;
261 sinfo.path = p+1;
262 memset(sinfo.password, '\0', sizeof(sinfo.password));
263 sinfo.reserved2 = '\0';
265 ret = cli_NetShareAdd(cli, &sinfo);
266 cli_shutdown(cli);
267 SAFE_FREE(sharename);
268 return ret;
272 int net_rap_share(struct net_context *c, int argc, const char **argv)
274 struct functable func[] = {
276 "delete",
277 rap_share_delete,
278 NET_TRANSPORT_RAP,
279 "Delete a share from server",
280 "net rap share delete\n"
281 " Delete a share from server"
284 "close",
285 rap_share_delete,
286 NET_TRANSPORT_RAP,
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"
293 "add",
294 rap_share_add,
295 NET_TRANSPORT_RAP,
296 "Add a share to server",
297 "net rap share add\n"
298 " Add a share to server"
300 {NULL, NULL, 0, NULL, NULL}
303 if (argc == 0) {
304 struct cli_state *cli;
305 int ret;
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);
312 return 0;
315 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
316 return -1;
318 if (c->opt_long_list_entries) {
319 d_printf(
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);
324 } else {
325 ret = cli_RNetShareEnum(cli, share_fn, NULL);
327 cli_shutdown(cli);
328 return ret;
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)
336 d_printf(
337 "\nnet rap session [misc. options] [targets]"
338 "\n\tenumerates all active SMB/CIFS sessions on target server\n");
339 d_printf(
340 "\nnet rap session DELETE <client_name> [misc. options] [targets] \n"
341 "\tor"
342 "\nnet rap session CLOSE <client_name> [misc. options] [targets]"
343 "\n\tDeletes (closes) a session from specified client to server\n");
344 d_printf(
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);
349 return -1;
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",
381 username, wsname,
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;
398 int ret;
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)))
404 return -1;
406 sessname = argv[0];
408 ret = cli_NetSessionGetInfo(cli, sessname, display_session_func);
409 if (ret < 0) {
410 cli_shutdown(cli);
411 return ret;
414 d_printf("Share name Type # Opens\n-------------------------"
415 "-----------------------------------------------------\n");
416 ret = cli_NetConnectionEnum(cli, sessname, display_conns_func);
417 cli_shutdown(cli);
418 return ret;
421 static int rap_session_delete(struct net_context *c, int argc, const char **argv)
423 struct cli_state *cli;
424 int ret;
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)))
430 return -1;
432 ret = cli_NetSessionDel(cli, argv[0]);
433 cli_shutdown(cli);
434 return ret;
437 int net_rap_session(struct net_context *c, int argc, const char **argv)
439 struct functable func[] = {
441 "info",
442 rap_session_info,
443 NET_TRANSPORT_RAP,
444 "Display information about session",
445 "net rap session info\n"
446 " Display information about session"
449 "delete",
450 rap_session_delete,
451 NET_TRANSPORT_RAP,
452 "Close specified session",
453 "net rap session delete\n"
454 " Close specified session\n"
455 " Alias for net rap session close"
458 "close",
459 rap_session_delete,
460 NET_TRANSPORT_RAP,
461 "Close specified session",
462 "net rap session close\n"
463 " Close specified session"
465 {NULL, NULL, 0, NULL, NULL}
468 if (argc == 0) {
469 struct cli_state *cli;
470 int ret;
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);
477 return 0;
480 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
481 return -1;
483 d_printf("Computer User name "
484 "Client Type Opens Idle time\n"
485 "------------------------------------------"
486 "------------------------------------\n");
487 ret = cli_NetSessionEnum(cli, list_sessions_func);
489 cli_shutdown(cli);
490 return ret;
493 return net_run_function(c, argc, argv, "net rap session", func);
496 /****************************************************************************
497 list a server name
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;
508 char *name;
510 if (c->display_usage) {
511 d_printf("Usage:\n"
512 "net rap server name\n"
513 " Get the name of the server\n");
514 return 0;
517 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
518 return -1;
520 if (!cli_get_server_name(NULL, cli, &name)) {
521 d_fprintf(stderr, "cli_get_server_name failed\n");
522 cli_shutdown(cli);
523 return -1;
526 d_printf("Server name = %s\n", name);
528 TALLOC_FREE(name);
529 cli_shutdown(cli);
530 return 0;
533 static int net_rap_server_domain(struct net_context *c, int argc,
534 const char **argv)
536 struct cli_state *cli;
537 int ret;
539 if (c->display_usage) {
540 d_printf("Usage:\n"
541 "net rap server domain\n"
542 " Enumerate servers in this domain/workgroup\n");
543 return 0;
546 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
547 return -1;
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);
555 cli_shutdown(cli);
556 return ret;
559 int net_rap_server(struct net_context *c, int argc, const char **argv)
561 struct functable func[] = {
563 "name",
564 net_rap_server_name,
565 NET_TRANSPORT_RAP,
566 "Get the name of the server",
567 "net rap server name\n"
568 " Get the name of the server"
571 "domain",
572 net_rap_server_domain,
573 NET_TRANSPORT_RAP,
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);
593 return -1;
596 int net_rap_domain(struct net_context *c, int argc, const char **argv)
598 struct cli_state *cli;
599 int ret;
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)))
605 return -1;
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);
613 cli_shutdown(cli);
614 return ret;
617 int net_rap_printq_usage(struct net_context *c, int argc, const char **argv)
619 d_printf(
620 "net rap printq [misc. options] [targets]\n"
621 "\tor\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");
625 d_printf(
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);
632 return -1;
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);
643 switch (status) {
644 case 0:
645 d_printf("*Printer Active*\n");
646 break;
647 case 1:
648 d_printf("*Printer Paused*\n");
649 break;
650 case 2:
651 d_printf("*Printer error*\n");
652 break;
653 case 3:
654 d_printf("*Delete Pending*\n");
655 break;
656 default:
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,
665 const char *comment)
667 d_printf(" %-23.23s %5d %9d ",
668 ownername, jobid, jobsize);
669 switch (status) {
670 case 0:
671 d_printf("Waiting\n");
672 break;
673 case 1:
674 d_printf("Held in queue\n");
675 break;
676 case 2:
677 d_printf("Spooling\n");
678 break;
679 case 3:
680 d_printf("Printing\n");
681 break;
682 default:
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 "------------------------------------------------------------------"\
691 "-------------\n"
693 static int rap_printq_info(struct net_context *c, int argc, const char **argv)
695 struct cli_state *cli;
696 int ret;
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)))
702 return -1;
704 d_printf(PRINTQ_ENUM_DISPLAY, cli->desthost); /* list header */
705 ret = cli_NetPrintQGetInfo(cli, argv[0], enum_queue, enum_jobs);
706 cli_shutdown(cli);
707 return ret;
710 static int rap_printq_delete(struct net_context *c, int argc, const char **argv)
712 struct cli_state *cli;
713 int ret;
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)))
719 return -1;
721 ret = cli_printjob_del(cli, atoi(argv[0]));
722 cli_shutdown(cli);
723 return ret;
726 int net_rap_printq(struct net_context *c, int argc, const char **argv)
728 struct cli_state *cli;
729 int ret;
731 struct functable func[] = {
733 "info",
734 rap_printq_info,
735 NET_TRANSPORT_RAP,
736 "Display info about print job",
737 "net rap printq info\n"
738 " Display info about print job"
741 "delete",
742 rap_printq_delete,
743 NET_TRANSPORT_RAP,
744 "Delete print job(s)",
745 "net rap printq delete\n"
746 " Delete print job(s)"
748 {NULL, NULL, 0, NULL, NULL}
751 if (argc == 0) {
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);
757 return 0;
760 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
761 return -1;
763 d_printf(PRINTQ_ENUM_DISPLAY, cli->desthost); /* list header */
764 ret = cli_NetPrintQEnum(cli, enum_queue, enum_jobs);
765 cli_shutdown(cli);
766 return ret;
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,
784 void *state)
786 d_printf("%-21.21s %s\n",
787 user_name, comment);
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;
798 int ret;
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)))
805 return -1;
807 ret = cli_NetUserDelete(cli, argv[0]);
808 cli_shutdown(cli);
809 return ret;
812 static int rap_user_add(struct net_context *c, int argc, const char **argv)
814 struct cli_state *cli;
815 int ret;
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)))
823 return -1;
825 safe_strcpy(userinfo.user_name, argv[0], sizeof(userinfo.user_name)-1);
826 if (c->opt_flags == -1)
827 c->opt_flags = 0x21;
829 userinfo.userflags = c->opt_flags;
830 userinfo.reserved1 = '\0';
831 userinfo.comment = smb_xstrdup(c->opt_comment);
832 userinfo.priv = 1;
833 userinfo.home_dir = NULL;
834 userinfo.logon_script = NULL;
836 ret = cli_NetUserAdd(cli, &userinfo);
838 cli_shutdown(cli);
839 return ret;
842 static int rap_user_info(struct net_context *c, int argc, const char **argv)
844 struct cli_state *cli;
845 int ret;
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)))
851 return -1;
853 ret = cli_NetUserGetGroups(cli, argv[0], group_member_fn, NULL);
854 cli_shutdown(cli);
855 return ret;
858 int net_rap_user(struct net_context *c, int argc, const char **argv)
860 int ret = -1;
861 struct functable func[] = {
863 "add",
864 rap_user_add,
865 NET_TRANSPORT_RAP,
866 "Add specified user",
867 "net rap user add\n"
868 " Add specified user"
871 "info",
872 rap_user_info,
873 NET_TRANSPORT_RAP,
874 "List domain groups of specified user",
875 "net rap user info\n"
876 " List domain groups of specified user"
880 "delete",
881 rap_user_delete,
882 NET_TRANSPORT_RAP,
883 "Remove specified user",
884 "net rap user delete\n"
885 " Remove specified user"
887 {NULL, NULL, 0, NULL, NULL}
890 if (argc == 0) {
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);
897 return 0;
900 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
901 goto done;
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);
906 cli_shutdown(cli);
907 goto done;
909 ret = cli_RNetUserEnum0(cli, user_fn, NULL);
910 cli_shutdown(cli);
911 goto done;
914 ret = net_run_function(c, argc, argv, "net rap user", func);
915 done:
916 if (ret != 0) {
917 DEBUG(1, ("Net user returned: %d\n", ret));
919 return 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,
929 void *state)
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;
942 int ret;
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)))
948 return -1;
950 ret = cli_NetGroupDelete(cli, argv[0]);
951 cli_shutdown(cli);
952 return ret;
955 static int rap_group_add(struct net_context *c, int argc, const char **argv)
957 struct cli_state *cli;
958 int ret;
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)))
966 return -1;
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);
974 cli_shutdown(cli);
975 return ret;
978 int net_rap_group(struct net_context *c, int argc, const char **argv)
980 struct functable func[] = {
982 "add",
983 rap_group_add,
984 NET_TRANSPORT_RAP,
985 "Add specified group",
986 "net rap group add\n"
987 " Add specified group"
990 "delete",
991 rap_group_delete,
992 NET_TRANSPORT_RAP,
993 "Delete specified group",
994 "net rap group delete\n"
995 " Delete specified group"
997 {NULL, NULL, 0, NULL, NULL}
1000 if (argc == 0) {
1001 struct cli_state *cli;
1002 int ret;
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);
1008 return 0;
1011 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1012 return -1;
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);
1017 cli_shutdown(cli);
1018 return ret;
1020 ret = cli_RNetGroupEnum0(cli, group_fn, NULL);
1021 cli_shutdown(cli);
1022 return ret;
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)
1030 d_printf(
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);
1039 return -1;
1043 static int rap_groupmember_add(struct net_context *c, int argc, const char **argv)
1045 struct cli_state *cli;
1046 int ret;
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)))
1052 return -1;
1054 ret = cli_NetGroupAddUser(cli, argv[0], argv[1]);
1055 cli_shutdown(cli);
1056 return ret;
1059 static int rap_groupmember_delete(struct net_context *c, int argc, const char **argv)
1061 struct cli_state *cli;
1062 int ret;
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)))
1068 return -1;
1070 ret = cli_NetGroupDelUser(cli, argv[0], argv[1]);
1071 cli_shutdown(cli);
1072 return ret;
1075 static int rap_groupmember_list(struct net_context *c, int argc, const char **argv)
1077 struct cli_state *cli;
1078 int ret;
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)))
1084 return -1;
1086 ret = cli_NetGroupGetUsers(cli, argv[0], group_member_fn, NULL );
1087 cli_shutdown(cli);
1088 return ret;
1091 int net_rap_groupmember(struct net_context *c, int argc, const char **argv)
1093 struct functable func[] = {
1095 "add",
1096 rap_groupmember_add,
1097 NET_TRANSPORT_RAP,
1098 "Add specified user to group",
1099 "net rap groupmember add\n"
1100 " Add specified user to group"
1103 "list",
1104 rap_groupmember_list,
1105 NET_TRANSPORT_RAP,
1106 "List users in group",
1107 "net rap groupmember list\n"
1108 " List users in group"
1111 "delete",
1112 rap_groupmember_delete,
1113 NET_TRANSPORT_RAP,
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);
1131 return -1;
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);
1150 return -1;
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,
1164 void *state)
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[] = {
1173 "start",
1174 rap_service_start,
1175 NET_TRANSPORT_RAP,
1176 "Start service on remote server",
1177 "net rap service start\n"
1178 " Start service on remote server"
1181 "stop",
1182 rap_service_stop,
1183 NET_TRANSPORT_RAP,
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}
1191 if (argc == 0) {
1192 struct cli_state *cli;
1193 int ret;
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);
1199 return 0;
1202 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1203 return -1;
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);
1211 cli_shutdown(cli);
1212 return ret;
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)
1220 d_printf(
1221 "net rap password <user> <oldpwo> <newpw> [misc. options] [target]\n"
1222 "\tchanges the password for the specified user at target\n");
1224 return -1;
1228 int net_rap_password(struct net_context *c, int argc, const char **argv)
1230 struct cli_state *cli;
1231 int ret;
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)))
1237 return -1;
1239 /* BB Add check for password lengths? */
1240 ret = cli_oem_change_password(cli, argv[0], argv[2], argv[1]);
1241 cli_shutdown(cli);
1242 return ret;
1245 int net_rap_admin_usage(struct net_context *c, int argc, const char **argv)
1247 d_printf(
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");
1251 return -1;
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[] = {
1266 "file",
1267 net_rap_file,
1268 NET_TRANSPORT_RAP,
1269 "List open files",
1270 "net rap file\n"
1271 " List open files"
1274 "share",
1275 net_rap_share,
1276 NET_TRANSPORT_RAP,
1277 "List shares exported by server",
1278 "net rap share\n"
1279 " List shares exported by server"
1282 "session",
1283 net_rap_session,
1284 NET_TRANSPORT_RAP,
1285 "List open sessions",
1286 "net rap session\n"
1287 " List open sessions"
1290 "server",
1291 net_rap_server,
1292 NET_TRANSPORT_RAP,
1293 "List servers in workgroup",
1294 "net rap server\n"
1295 " List servers in domain/workgroup"
1298 "domain",
1299 net_rap_domain,
1300 NET_TRANSPORT_RAP,
1301 "List domains in network",
1302 "net rap domain\n"
1303 " List domains in network"
1306 "printq",
1307 net_rap_printq,
1308 NET_TRANSPORT_RAP,
1309 "List printer queues on server",
1310 "net rap printq\n"
1311 " List printer queues on server"
1314 "user",
1315 net_rap_user,
1316 NET_TRANSPORT_RAP,
1317 "List users",
1318 "net rap user\n"
1319 " List users"
1322 "group",
1323 net_rap_group,
1324 NET_TRANSPORT_RAP,
1325 "List user groups",
1326 "net rap group\n"
1327 " List user groups"
1330 "validate",
1331 net_rap_validate,
1332 NET_TRANSPORT_RAP,
1333 "Check username/password",
1334 "net rap validate\n"
1335 " Check username/password"
1338 "groupmember",
1339 net_rap_groupmember,
1340 NET_TRANSPORT_RAP,
1341 "List/modify group memberships",
1342 "net rap groupmember\n"
1343 " List/modify group memberships"
1346 "admin",
1347 net_rap_admin,
1348 NET_TRANSPORT_RAP,
1349 "Execute commands on remote OS/2",
1350 "net rap admin\n"
1351 " Execute commands on remote OS/2"
1354 "service",
1355 net_rap_service,
1356 NET_TRANSPORT_RAP,
1357 "Start/stop remote service",
1358 "net rap service\n"
1359 " Start/stop remote service"
1362 "password",
1363 net_rap_password,
1364 NET_TRANSPORT_RAP,
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);