s3-dcerpc: Pull packet in the caller, before validation
[Samba.git] / source3 / utils / net_rap.c
blob04e81f95f737538ff063daef322bb12ad783f8cd
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 "../librpc/gen_ndr/rap.h"
27 #include "../librpc/gen_ndr/svcctl.h"
28 #include "utils/net.h"
30 /* The following messages were for error checking that is not properly
31 reported at the moment. Which should be reinstated? */
32 #define ERRMSG_TARGET_WG_NOT_VALID "\nTarget workgroup option not valid "\
33 "except on net rap server command, ignored"
34 #define ERRMSG_INVALID_HELP_OPTION "\nInvalid help option\n"
36 #define ERRMSG_BOTH_SERVER_IPADDRESS "\nTarget server and IP address both "\
37 "specified. Do not set both at the same time. The target IP address was used\n"
39 static int errmsg_not_implemented(void)
41 d_printf(_("\nNot implemented\n"));
42 return 0;
45 int net_rap_file_usage(struct net_context *c, int argc, const char **argv)
47 return net_file_usage(c, argc, argv);
50 /***************************************************************************
51 list info on an open file
52 ***************************************************************************/
53 static void file_fn(const char * pPath, const char * pUser, uint16 perms,
54 uint16 locks, uint32 id)
56 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
57 id, pUser, perms, locks, pPath);
60 static void one_file_fn(const char *pPath, const char *pUser, uint16 perms,
61 uint16 locks, uint32 id)
63 d_printf(_("File ID %d\n"
64 "User name %s\n"
65 "Locks 0x%-4.2x\n"
66 "Path %s\n"
67 "Permissions 0x%x\n"),
68 id, pUser, locks, pPath, perms);
72 static int rap_file_close(struct net_context *c, int argc, const char **argv)
74 struct cli_state *cli;
75 int ret;
76 if (argc == 0 || c->display_usage) {
77 return net_rap_file_usage(c, argc, argv);
80 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
81 return -1;
83 ret = cli_NetFileClose(cli, atoi(argv[0]));
84 cli_shutdown(cli);
85 return ret;
88 static int rap_file_info(struct net_context *c, int argc, const char **argv)
90 struct cli_state *cli;
91 int ret;
92 if (argc == 0 || c->display_usage)
93 return net_rap_file_usage(c, argc, argv);
95 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
96 return -1;
98 ret = cli_NetFileGetInfo(cli, atoi(argv[0]), one_file_fn);
99 cli_shutdown(cli);
100 return ret;
103 static int rap_file_user(struct net_context *c, int argc, const char **argv)
105 struct cli_state *cli;
106 int ret;
108 if (argc == 0 || c->display_usage)
109 return net_rap_file_usage(c, argc, argv);
111 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
112 return -1;
114 /* list open files */
116 d_printf(_("\nEnumerating open files on remote server:\n\n"
117 "\nFileId Opened by Perms Locks Path \n"
118 "------ --------- ----- ----- ---- \n"));
119 ret = cli_NetFileEnum(cli, argv[0], NULL, file_fn);
121 if (ret == -1)
122 d_printf(_("\nOperation not supported by server!\n\n"));
124 cli_shutdown(cli);
125 return ret;
128 int net_rap_file(struct net_context *c, int argc, const char **argv)
130 struct functable func[] = {
132 "close",
133 rap_file_close,
134 NET_TRANSPORT_RAP,
135 N_("Close specified file on server"),
136 N_("net rap file close\n"
137 " Close specified file on server")
140 "user",
141 rap_file_user,
142 NET_TRANSPORT_RAP,
143 N_("List all files opened by username"),
144 N_("net rap file user\n"
145 " List all files opened by username")
148 "info",
149 rap_file_info,
150 NET_TRANSPORT_RAP,
151 N_("Display info about an opened file"),
152 N_("net rap file info\n"
153 " Display info about an opened file")
155 {NULL, NULL, 0, NULL, NULL}
158 if (argc == 0) {
159 struct cli_state *cli;
160 int ret;
162 if (c->display_usage) {
163 d_printf(_("Usage:\n"));
164 d_printf(_("net rap file\n"
165 " List all open files on rempte "
166 "server\n"));
167 net_display_usage_from_functable(func);
168 return 0;
171 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
172 return -1;
174 /* list open files */
176 d_printf(_("\nEnumerating open files on remote server:\n\n"
177 "\nFileId Opened by Perms Locks Path\n"
178 "------ --------- ----- ----- ----\n"));
179 ret = cli_NetFileEnum(cli, NULL, NULL, file_fn);
181 if (ret == -1)
182 d_printf(_("\nOperation not supported by server!\n\n"));
184 cli_shutdown(cli);
185 return ret;
188 return net_run_function(c, argc, argv, "net rap file", func);
191 int net_rap_share_usage(struct net_context *c, int argc, const char **argv)
193 return net_share_usage(c, argc, argv);
196 static void long_share_fn(const char *share_name, uint32 type,
197 const char *comment, void *state)
199 d_printf("%-12s %-8.8s %-50s\n",
200 share_name, net_share_type_str(type), comment);
203 static void share_fn(const char *share_name, uint32 type,
204 const char *comment, void *state)
206 d_printf("%s\n", share_name);
209 static int rap_share_delete(struct net_context *c, int argc, const char **argv)
211 struct cli_state *cli;
212 int ret;
214 if (argc == 0 || c->display_usage) {
215 return net_rap_share_usage(c, argc, argv);
218 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
219 return -1;
221 ret = cli_NetShareDelete(cli, argv[0]);
222 cli_shutdown(cli);
223 return ret;
226 static int rap_share_add(struct net_context *c, int argc, const char **argv)
228 struct cli_state *cli;
229 int ret;
231 struct rap_share_info_2 sinfo;
232 char *p;
233 char *sharename;
235 if (argc == 0 || c->display_usage) {
236 return net_rap_share_usage(c, argc, argv);
239 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
240 return -1;
242 sharename = SMB_STRDUP(argv[0]);
243 p = strchr(sharename, '=');
244 if (p == NULL) {
245 d_printf(_("Server path not specified\n"));
246 SAFE_FREE(sharename);
247 return net_rap_share_usage(c, argc, argv);
249 *p = 0;
250 strlcpy((char *)sinfo.share_name, sharename, sizeof(sinfo.share_name));
251 sinfo.reserved1 = '\0';
252 sinfo.share_type = 0;
253 sinfo.comment = c->opt_comment ? smb_xstrdup(c->opt_comment) : "";
254 sinfo.perms = 0;
255 sinfo.maximum_users = c->opt_maxusers;
256 sinfo.active_users = 0;
257 sinfo.path = p+1;
258 memset(sinfo.password, '\0', sizeof(sinfo.password));
259 sinfo.reserved2 = '\0';
261 ret = cli_NetShareAdd(cli, &sinfo);
262 cli_shutdown(cli);
263 SAFE_FREE(sharename);
264 return ret;
268 int net_rap_share(struct net_context *c, int argc, const char **argv)
270 struct functable func[] = {
272 "delete",
273 rap_share_delete,
274 NET_TRANSPORT_RAP,
275 N_("Delete a share from server"),
276 N_("net rap share delete\n"
277 " Delete a share from server")
280 "close",
281 rap_share_delete,
282 NET_TRANSPORT_RAP,
283 N_("Delete a share from server"),
284 N_("net rap share close\n"
285 " Delete a share from server\n"
286 " Alias for net rap share delete")
289 "add",
290 rap_share_add,
291 NET_TRANSPORT_RAP,
292 N_("Add a share to server"),
293 N_("net rap share add\n"
294 " Add a share to server")
296 {NULL, NULL, 0, NULL, NULL}
299 if (argc == 0) {
300 struct cli_state *cli;
301 int ret;
303 if (c->display_usage) {
304 d_printf(_("Usage:\n"));
305 d_printf(_("net rap share\n"
306 " List all shares on remote server\n"));
307 net_display_usage_from_functable(func);
308 return 0;
311 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
312 return -1;
314 if (c->opt_long_list_entries) {
315 d_printf(_(
316 "\nEnumerating shared resources (exports) on remote server:\n\n"
317 "\nShare name Type Description\n"
318 "---------- ---- -----------\n"));
319 ret = cli_RNetShareEnum(cli, long_share_fn, NULL);
320 } else {
321 ret = cli_RNetShareEnum(cli, share_fn, NULL);
323 cli_shutdown(cli);
324 return ret;
327 return net_run_function(c, argc, argv, "net rap share", func);
330 int net_rap_session_usage(struct net_context *c, int argc, const char **argv)
332 d_printf(_(
333 "\nnet rap session [misc. options] [targets]"
334 "\n\tenumerates all active SMB/CIFS sessions on target server\n"));
335 d_printf(_(
336 "\nnet rap session DELETE <client_name> [misc. options] [targets] \n"
337 "\tor"
338 "\nnet rap session CLOSE <client_name> [misc. options] [targets]"
339 "\n\tDeletes (closes) a session from specified client to server\n"));
340 d_printf(_(
341 "\nnet rap session INFO <client_name>"
342 "\n\tEnumerates all open files in specified session\n"));
344 net_common_flags_usage(c, argc, argv);
345 return -1;
348 static void list_sessions_func(char *wsname, char *username, uint16 conns,
349 uint16 opens, uint16 users, uint32 sess_time,
350 uint32 idle_time, uint32 user_flags, char *clitype)
352 int hrs = idle_time / 3600;
353 int min = (idle_time / 60) % 60;
354 int sec = idle_time % 60;
356 d_printf("\\\\%-18.18s %-20.20s %-18.18s %5d %2.2d:%2.2d:%2.2d\n",
357 wsname, username, clitype, opens, hrs, min, sec);
360 static void display_session_func(const char *wsname, const char *username,
361 uint16 conns, uint16 opens, uint16 users,
362 uint32 sess_time, uint32 idle_time,
363 uint32 user_flags, const char *clitype)
365 int ihrs = idle_time / 3600;
366 int imin = (idle_time / 60) % 60;
367 int isec = idle_time % 60;
368 int shrs = sess_time / 3600;
369 int smin = (sess_time / 60) % 60;
370 int ssec = sess_time % 60;
371 d_printf(_("User name %-20.20s\n"
372 "Computer %-20.20s\n"
373 "Guest logon %-20.20s\n"
374 "Client Type %-40.40s\n"
375 "Sess time %2.2d:%2.2d:%2.2d\n"
376 "Idle time %2.2d:%2.2d:%2.2d\n"),
377 username, wsname,
378 (user_flags&0x0)?_("yes"):_("no"), clitype,
379 shrs, smin, ssec, ihrs, imin, isec);
382 static void display_conns_func(uint16 conn_id, uint16 conn_type, uint16 opens,
383 uint16 users, uint32 conn_time,
384 const char *username, const char *netname)
386 d_printf("%-14.14s %-8.8s %5d\n",
387 netname, net_share_type_str(conn_type), opens);
390 static int rap_session_info(struct net_context *c, int argc, const char **argv)
392 const char *sessname;
393 struct cli_state *cli;
394 int ret;
396 if (argc == 0 || c->display_usage)
397 return net_rap_session_usage(c, argc, argv);
399 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
400 return -1;
402 sessname = argv[0];
404 ret = cli_NetSessionGetInfo(cli, sessname, display_session_func);
405 if (ret < 0) {
406 cli_shutdown(cli);
407 return ret;
410 d_printf(_("Share name Type # Opens\n-------------------------"
411 "-----------------------------------------------------\n"));
412 ret = cli_NetConnectionEnum(cli, sessname, display_conns_func);
413 cli_shutdown(cli);
414 return ret;
417 static int rap_session_delete(struct net_context *c, int argc, const char **argv)
419 struct cli_state *cli;
420 int ret;
422 if (argc == 0 || c->display_usage)
423 return net_rap_session_usage(c, argc, argv);
425 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
426 return -1;
428 ret = cli_NetSessionDel(cli, argv[0]);
429 cli_shutdown(cli);
430 return ret;
433 int net_rap_session(struct net_context *c, int argc, const char **argv)
435 struct functable func[] = {
437 "info",
438 rap_session_info,
439 NET_TRANSPORT_RAP,
440 N_("Display information about session"),
441 N_("net rap session info\n"
442 " Display information about session")
445 "delete",
446 rap_session_delete,
447 NET_TRANSPORT_RAP,
448 N_("Close specified session"),
449 N_("net rap session delete\n"
450 " Close specified session\n"
451 " Alias for net rap session close")
454 "close",
455 rap_session_delete,
456 NET_TRANSPORT_RAP,
457 N_("Close specified session"),
458 N_("net rap session close\n"
459 " Close specified session")
461 {NULL, NULL, 0, NULL, NULL}
464 if (argc == 0) {
465 struct cli_state *cli;
466 int ret;
468 if (c->display_usage) {
469 d_printf(_("Usage:\n"));
470 d_printf(_("net rap session\n"
471 " List all open sessions on remote "
472 "server\n"));
473 net_display_usage_from_functable(func);
474 return 0;
477 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
478 return -1;
480 d_printf(_("Computer User name "
481 "Client Type Opens Idle time\n"
482 "------------------------------------------"
483 "------------------------------------\n"));
484 ret = cli_NetSessionEnum(cli, list_sessions_func);
486 cli_shutdown(cli);
487 return ret;
490 return net_run_function(c, argc, argv, "net rap session", func);
493 /****************************************************************************
494 list a server name
495 ****************************************************************************/
496 static void display_server_func(const char *name, uint32 m,
497 const char *comment, void * reserved)
499 d_printf("\t%-16.16s %s\n", name, comment);
502 static int net_rap_server_name(struct net_context *c, int argc, const char *argv[])
504 struct cli_state *cli;
505 char *name;
507 if (c->display_usage) {
508 d_printf("%s\n%s",
509 _("Usage:"),
510 _("net rap server name\n"
511 " Get the name of the server\n"));
512 return 0;
515 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
516 return -1;
518 if (!cli_get_server_name(NULL, cli, &name)) {
519 d_fprintf(stderr, _("cli_get_server_name failed\n"));
520 cli_shutdown(cli);
521 return -1;
524 d_printf(_("Server name = %s\n"), name);
526 TALLOC_FREE(name);
527 cli_shutdown(cli);
528 return 0;
531 static int net_rap_server_domain(struct net_context *c, int argc,
532 const char **argv)
534 struct cli_state *cli;
535 int ret;
537 if (c->display_usage) {
538 d_printf("%s\n%s",
539 _("Usage:"),
540 _("net rap server domain\n"
541 " Enumerate servers in this domain/workgroup\n"));
542 return 0;
545 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
546 return -1;
548 d_printf(_("\nEnumerating servers in this domain or workgroup: \n\n"
549 "\tServer name Server description\n"
550 "\t------------- ----------------------------\n"));
552 ret = cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_ALL,
553 display_server_func,NULL);
554 cli_shutdown(cli);
555 return ret;
558 int net_rap_server(struct net_context *c, int argc, const char **argv)
560 struct functable func[] = {
562 "name",
563 net_rap_server_name,
564 NET_TRANSPORT_RAP,
565 N_("Get the name of the server"),
566 N_("net rap server name\n"
567 " Get the name of the server")
570 "domain",
571 net_rap_server_domain,
572 NET_TRANSPORT_RAP,
573 N_("Get the servers in this domain/workgroup"),
574 N_("net rap server domain\n"
575 " Get the servers in this domain/workgroup")
577 {NULL, NULL, 0, NULL, NULL}
580 /* smb4k uses 'net [rap|rpc] server domain' to query servers in a domain */
581 /* Fall through for 'domain', any other forms will cause to show usage message */
582 return net_run_function(c, argc, argv, "net rap server", func);
586 int net_rap_domain_usage(struct net_context *c, int argc, const char **argv)
588 d_printf(_("net rap domain [misc. options] [target]\n\tlists the"
589 " domains or workgroups visible on the current network\n"));
591 net_common_flags_usage(c, argc, argv);
592 return -1;
595 int net_rap_domain(struct net_context *c, int argc, const char **argv)
597 struct cli_state *cli;
598 int ret;
600 if (c->display_usage)
601 return net_rap_domain_usage(c, argc, argv);
603 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
604 return -1;
606 d_printf(_("\nEnumerating domains:\n\n"
607 "\tDomain name Server name of Browse Master\n"
608 "\t------------- ----------------------------\n"));
610 ret = cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_DOMAIN_ENUM,
611 display_server_func,NULL);
612 cli_shutdown(cli);
613 return ret;
616 int net_rap_printq_usage(struct net_context *c, int argc, const char **argv)
618 d_printf(_(
619 "net rap printq [misc. options] [targets]\n"
620 "\tor\n"
621 "net rap printq info [<queue_name>] [misc. options] [targets]\n"
622 "\tlists the specified queue and jobs on the target server.\n"
623 "\tIf the queue name is not specified, all queues are listed.\n\n"));
624 d_printf(_(
625 "net rap printq delete [<queue name>] [misc. options] [targets]\n"
626 "\tdeletes the specified job number on the target server, or the\n"
627 "\tprinter queue if no job number is specified\n"));
629 net_common_flags_usage(c, argc, argv);
631 return -1;
634 static void enum_queue(const char *queuename, uint16 pri, uint16 start,
635 uint16 until, const char *sep, const char *pproc,
636 const char *dest, const char *qparms,
637 const char *qcomment, uint16 status, uint16 jobcount)
639 d_printf(_("%-17.17s Queue %5d jobs "),
640 queuename, jobcount);
642 switch (status) {
643 case 0:
644 d_printf(_("*Printer Active*\n"));
645 break;
646 case 1:
647 d_printf(_("*Printer Paused*\n"));
648 break;
649 case 2:
650 d_printf(_("*Printer error*\n"));
651 break;
652 case 3:
653 d_printf(_("*Delete Pending*\n"));
654 break;
655 default:
656 d_printf(_("**UNKNOWN STATUS**\n"));
660 static void enum_jobs(uint16 jobid, const char *ownername,
661 const char *notifyname, const char *datatype,
662 const char *jparms, uint16 pos, uint16 status,
663 const char *jstatus, unsigned int submitted, unsigned int jobsize,
664 const char *comment)
666 d_printf(" %-23.23s %5d %9d ",
667 ownername, jobid, jobsize);
668 switch (status) {
669 case 0:
670 d_printf(_("Waiting\n"));
671 break;
672 case 1:
673 d_printf(_("Held in queue\n"));
674 break;
675 case 2:
676 d_printf(_("Spooling\n"));
677 break;
678 case 3:
679 d_printf(_("Printing\n"));
680 break;
681 default:
682 d_printf(_("**UNKNOWN STATUS**\n"));
686 #define PRINTQ_ENUM_DISPLAY \
687 _("Print queues at \\\\%s\n\n"\
688 "Name Job # Size Status\n\n"\
689 "------------------------------------------------------------------"\
690 "-------------\n")
692 static int rap_printq_info(struct net_context *c, int argc, const char **argv)
694 struct cli_state *cli;
695 int ret;
697 if (argc == 0 || c->display_usage)
698 return net_rap_printq_usage(c, argc, argv);
700 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
701 return -1;
703 d_printf(PRINTQ_ENUM_DISPLAY, cli->desthost); /* list header */
704 ret = cli_NetPrintQGetInfo(cli, argv[0], enum_queue, enum_jobs);
705 cli_shutdown(cli);
706 return ret;
709 static int rap_printq_delete(struct net_context *c, int argc, const char **argv)
711 struct cli_state *cli;
712 int ret;
714 if (argc == 0 || c->display_usage)
715 return net_rap_printq_usage(c, argc, argv);
717 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
718 return -1;
720 ret = cli_printjob_del(cli, atoi(argv[0]));
721 cli_shutdown(cli);
722 return ret;
725 int net_rap_printq(struct net_context *c, int argc, const char **argv)
727 struct cli_state *cli;
728 int ret;
730 struct functable func[] = {
732 "info",
733 rap_printq_info,
734 NET_TRANSPORT_RAP,
735 N_("Display info about print queues and jobs"),
736 N_("net rap printq info [queue]\n"
737 " Display info about print jobs in queue.\n"
738 " If queue is not specified, all queues are "
739 "listed")
742 "delete",
743 rap_printq_delete,
744 NET_TRANSPORT_RAP,
745 N_("Delete print job(s)"),
746 N_("net rap printq delete\n"
747 " Delete print job(s)")
749 {NULL, NULL, 0, NULL, NULL}
752 if (argc == 0) {
753 if (c->display_usage) {
754 d_printf(_("Usage:\n"));
755 d_printf(_("net rap printq\n"
756 " List the print queue\n"));
757 net_display_usage_from_functable(func);
758 return 0;
761 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
762 return -1;
764 d_printf(PRINTQ_ENUM_DISPLAY, cli->desthost); /* list header */
765 ret = cli_NetPrintQEnum(cli, enum_queue, enum_jobs);
766 cli_shutdown(cli);
767 return ret;
770 return net_run_function(c, argc, argv, "net rap printq", func);
773 static int net_rap_user_usage(struct net_context *c, int argc, const char **argv)
775 return net_user_usage(c, argc, argv);
778 static void user_fn(const char *user_name, void *state)
780 d_printf("%-21.21s\n", user_name);
783 static void long_user_fn(const char *user_name, const char *comment,
784 const char * home_dir, const char * logon_script,
785 void *state)
787 d_printf("%-21.21s %s\n",
788 user_name, comment);
791 static void group_member_fn(const char *user_name, void *state)
793 d_printf("%-21.21s\n", user_name);
796 static int rap_user_delete(struct net_context *c, int argc, const char **argv)
798 struct cli_state *cli;
799 int ret;
801 if (argc == 0 || c->display_usage) {
802 return net_rap_user_usage(c, argc, argv);
805 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
806 return -1;
808 ret = cli_NetUserDelete(cli, argv[0]);
809 cli_shutdown(cli);
810 return ret;
813 static int rap_user_add(struct net_context *c, int argc, const char **argv)
815 struct cli_state *cli;
816 int ret;
817 struct rap_user_info_1 userinfo;
819 if (argc == 0 || c->display_usage) {
820 return net_rap_user_usage(c, argc, argv);
823 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
824 return -1;
826 safe_strcpy((char *)userinfo.user_name, argv[0], sizeof(userinfo.user_name)-1);
827 if (c->opt_flags == -1)
828 c->opt_flags = 0x21;
830 userinfo.userflags = c->opt_flags;
831 userinfo.reserved1 = '\0';
832 userinfo.comment = smb_xstrdup(c->opt_comment ? c->opt_comment : "");
833 userinfo.priv = 1;
834 userinfo.home_dir = NULL;
835 userinfo.logon_script = NULL;
836 userinfo.passwrd[0] = '\0';
838 ret = cli_NetUserAdd(cli, &userinfo);
840 cli_shutdown(cli);
841 return ret;
844 static int rap_user_info(struct net_context *c, int argc, const char **argv)
846 struct cli_state *cli;
847 int ret;
848 if (argc == 0 || c->display_usage) {
849 return net_rap_user_usage(c, argc, argv);
852 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
853 return -1;
855 ret = cli_NetUserGetGroups(cli, argv[0], group_member_fn, NULL);
856 cli_shutdown(cli);
857 return ret;
860 int net_rap_user(struct net_context *c, int argc, const char **argv)
862 int ret = -1;
863 struct functable func[] = {
865 "add",
866 rap_user_add,
867 NET_TRANSPORT_RAP,
868 N_("Add specified user"),
869 N_("net rap user add\n"
870 " Add specified user")
873 "info",
874 rap_user_info,
875 NET_TRANSPORT_RAP,
876 N_("List domain groups of specified user"),
877 N_("net rap user info\n"
878 " List domain groups of specified user")
882 "delete",
883 rap_user_delete,
884 NET_TRANSPORT_RAP,
885 N_("Remove specified user"),
886 N_("net rap user delete\n"
887 " Remove specified user")
889 {NULL, NULL, 0, NULL, NULL}
892 if (argc == 0) {
893 struct cli_state *cli;
894 if (c->display_usage) {
895 d_printf(_("Usage:\n"));
896 d_printf(_("net rap user\n"
897 " List all users\n"));
898 net_display_usage_from_functable(func);
899 return 0;
902 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
903 goto done;
904 if (c->opt_long_list_entries) {
905 d_printf(_("\nUser name Comment"
906 "\n-----------------------------\n"));
907 ret = cli_RNetUserEnum(cli, long_user_fn, NULL);
908 cli_shutdown(cli);
909 goto done;
911 ret = cli_RNetUserEnum0(cli, user_fn, NULL);
912 cli_shutdown(cli);
913 goto done;
916 ret = net_run_function(c, argc, argv, "net rap user", func);
917 done:
918 if (ret != 0) {
919 DEBUG(1, (_("Net user returned: %d\n"), ret));
921 return ret;
925 int net_rap_group_usage(struct net_context *c, int argc, const char **argv)
927 return net_group_usage(c, argc, argv);
930 static void long_group_fn(const char *group_name, const char *comment,
931 void *state)
933 d_printf("%-21.21s %s\n", group_name, comment);
936 static void group_fn(const char *group_name, void *state)
938 d_printf("%-21.21s\n", group_name);
941 static int rap_group_delete(struct net_context *c, int argc, const char **argv)
943 struct cli_state *cli;
944 int ret;
945 if (argc == 0 || c->display_usage) {
946 return net_rap_group_usage(c, argc, argv);
949 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
950 return -1;
952 ret = cli_NetGroupDelete(cli, argv[0]);
953 cli_shutdown(cli);
954 return ret;
957 static int rap_group_add(struct net_context *c, int argc, const char **argv)
959 struct cli_state *cli;
960 int ret;
961 struct rap_group_info_1 grinfo;
963 if (argc == 0 || c->display_usage) {
964 return net_rap_group_usage(c, argc, argv);
967 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
968 return -1;
970 /* BB check for length 21 or smaller explicitly ? BB */
971 safe_strcpy((char *)grinfo.group_name, argv[0], sizeof(grinfo.group_name)-1);
972 grinfo.reserved1 = '\0';
973 grinfo.comment = smb_xstrdup(c->opt_comment ? c->opt_comment : "");
975 ret = cli_NetGroupAdd(cli, &grinfo);
976 cli_shutdown(cli);
977 return ret;
980 int net_rap_group(struct net_context *c, int argc, const char **argv)
982 struct functable func[] = {
984 "add",
985 rap_group_add,
986 NET_TRANSPORT_RAP,
987 N_("Add specified group"),
988 N_("net rap group add\n"
989 " Add specified group")
992 "delete",
993 rap_group_delete,
994 NET_TRANSPORT_RAP,
995 N_("Delete specified group"),
996 N_("net rap group delete\n"
997 " Delete specified group")
999 {NULL, NULL, 0, NULL, NULL}
1002 if (argc == 0) {
1003 struct cli_state *cli;
1004 int ret;
1005 if (c->display_usage) {
1006 d_printf(_("Usage:\n"));
1007 d_printf(_("net rap group\n"
1008 " List all groups\n"));
1009 net_display_usage_from_functable(func);
1010 return 0;
1013 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1014 return -1;
1015 if (c->opt_long_list_entries) {
1016 d_printf(_("Group name Comment\n"
1017 "-----------------------------\n"));
1018 ret = cli_RNetGroupEnum(cli, long_group_fn, NULL);
1019 cli_shutdown(cli);
1020 return ret;
1022 ret = cli_RNetGroupEnum0(cli, group_fn, NULL);
1023 cli_shutdown(cli);
1024 return ret;
1027 return net_run_function(c, argc, argv, "net rap group", func);
1030 int net_rap_groupmember_usage(struct net_context *c, int argc, const char **argv)
1032 d_printf(_(
1033 "net rap groupmember LIST <group> [misc. options] [targets]"
1034 "\n\t Enumerate users in a group\n"
1035 "\nnet rap groupmember DELETE <group> <user> [misc. options] "
1036 "[targets]\n\t Delete specified user from specified group\n"
1037 "\nnet rap groupmember ADD <group> <user> [misc. options] [targets]"
1038 "\n\t Add specified user to specified group\n"));
1040 net_common_flags_usage(c, argc, argv);
1041 return -1;
1045 static int rap_groupmember_add(struct net_context *c, int argc, const char **argv)
1047 struct cli_state *cli;
1048 int ret;
1049 if (argc != 2 || c->display_usage) {
1050 return net_rap_groupmember_usage(c, argc, argv);
1053 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1054 return -1;
1056 ret = cli_NetGroupAddUser(cli, argv[0], argv[1]);
1057 cli_shutdown(cli);
1058 return ret;
1061 static int rap_groupmember_delete(struct net_context *c, int argc, const char **argv)
1063 struct cli_state *cli;
1064 int ret;
1065 if (argc != 2 || c->display_usage) {
1066 return net_rap_groupmember_usage(c, argc, argv);
1069 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1070 return -1;
1072 ret = cli_NetGroupDelUser(cli, argv[0], argv[1]);
1073 cli_shutdown(cli);
1074 return ret;
1077 static int rap_groupmember_list(struct net_context *c, int argc, const char **argv)
1079 struct cli_state *cli;
1080 int ret;
1081 if (argc == 0 || c->display_usage) {
1082 return net_rap_groupmember_usage(c, argc, argv);
1085 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1086 return -1;
1088 ret = cli_NetGroupGetUsers(cli, argv[0], group_member_fn, NULL );
1089 cli_shutdown(cli);
1090 return ret;
1093 int net_rap_groupmember(struct net_context *c, int argc, const char **argv)
1095 struct functable func[] = {
1097 "add",
1098 rap_groupmember_add,
1099 NET_TRANSPORT_RAP,
1100 N_("Add specified user to group"),
1101 N_("net rap groupmember add\n"
1102 " Add specified user to group")
1105 "list",
1106 rap_groupmember_list,
1107 NET_TRANSPORT_RAP,
1108 N_("List users in group"),
1109 N_("net rap groupmember list\n"
1110 " List users in group")
1113 "delete",
1114 rap_groupmember_delete,
1115 NET_TRANSPORT_RAP,
1116 N_("Remove user from group"),
1117 N_("net rap groupmember delete\n"
1118 " Remove user from group")
1120 {NULL, NULL, 0, NULL, NULL}
1123 return net_run_function(c, argc, argv, "net rap groupmember", func);
1126 int net_rap_validate_usage(struct net_context *c, int argc, const char **argv)
1128 d_printf(_("net rap validate <username> [password]\n"
1129 "\tValidate user and password to check whether they"
1130 " can access target server or domain\n"));
1132 net_common_flags_usage(c, argc, argv);
1133 return -1;
1136 int net_rap_validate(struct net_context *c, int argc, const char **argv)
1138 return errmsg_not_implemented();
1141 int net_rap_service_usage(struct net_context *c, int argc, const char **argv)
1143 d_printf(_("net rap service [misc. options] [targets] \n"
1144 "\tlists all running service daemons on target server\n"));
1145 d_printf(_("\nnet rap service START <name> [service startup arguments]"
1146 " [misc. options] [targets]"
1147 "\n\tStart named service on remote server\n"));
1148 d_printf(_("\nnet rap service STOP <name> [misc. options] [targets]\n"
1149 "\n\tStop named service on remote server\n"));
1151 net_common_flags_usage(c, argc, argv);
1152 return -1;
1155 static int rap_service_start(struct net_context *c, int argc, const char **argv)
1157 return errmsg_not_implemented();
1160 static int rap_service_stop(struct net_context *c, int argc, const char **argv)
1162 return errmsg_not_implemented();
1165 static void service_fn(const char *service_name, const char *dummy,
1166 void *state)
1168 d_printf("%-21.21s\n", service_name);
1171 int net_rap_service(struct net_context *c, int argc, const char **argv)
1173 struct functable func[] = {
1175 "start",
1176 rap_service_start,
1177 NET_TRANSPORT_RAP,
1178 N_("Start service on remote server"),
1179 N_("net rap service start\n"
1180 " Start service on remote server")
1183 "stop",
1184 rap_service_stop,
1185 NET_TRANSPORT_RAP,
1186 N_("Stop named serve on remote server"),
1187 N_("net rap service stop\n"
1188 " Stop named serve on remote server")
1190 {NULL, NULL, 0, NULL, NULL}
1193 if (argc == 0) {
1194 struct cli_state *cli;
1195 int ret;
1196 if (c->display_usage) {
1197 d_printf(_("Usage:\n"));
1198 d_printf(_("net rap service\n"
1199 " List services on remote server\n"));
1200 net_display_usage_from_functable(func);
1201 return 0;
1204 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1205 return -1;
1207 if (c->opt_long_list_entries) {
1208 d_printf(_("Service name Comment\n"
1209 "-----------------------------\n"));
1210 ret = cli_RNetServiceEnum(cli, long_group_fn, NULL);
1212 ret = cli_RNetServiceEnum(cli, service_fn, NULL);
1213 cli_shutdown(cli);
1214 return ret;
1217 return net_run_function(c, argc, argv, "net rap service", func);
1220 int net_rap_password_usage(struct net_context *c, int argc, const char **argv)
1222 d_printf(_(
1223 "net rap password <user> <oldpwo> <newpw> [misc. options] [target]\n"
1224 "\tchanges the password for the specified user at target\n"));
1226 return -1;
1230 int net_rap_password(struct net_context *c, int argc, const char **argv)
1232 struct cli_state *cli;
1233 int ret;
1235 if (argc < 3 || c->display_usage)
1236 return net_rap_password_usage(c, argc, argv);
1238 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1239 return -1;
1241 /* BB Add check for password lengths? */
1242 ret = cli_oem_change_password(cli, argv[0], argv[2], argv[1]);
1243 cli_shutdown(cli);
1244 return ret;
1247 int net_rap_admin_usage(struct net_context *c, int argc, const char **argv)
1249 d_printf(_(
1250 "net rap admin <remote command> [cmd args [env]] [misc. options] [targets]"
1251 "\n\texecutes a remote command on an os/2 target server\n"));
1253 return -1;
1257 int net_rap_admin(struct net_context *c, int argc, const char **argv)
1259 return errmsg_not_implemented();
1262 /* Entry-point for all the RAP functions. */
1264 int net_rap(struct net_context *c, int argc, const char **argv)
1266 struct functable func[] = {
1268 "file",
1269 net_rap_file,
1270 NET_TRANSPORT_RAP,
1271 N_("List open files"),
1272 N_("net rap file\n"
1273 " List open files")
1276 "share",
1277 net_rap_share,
1278 NET_TRANSPORT_RAP,
1279 N_("List shares exported by server"),
1280 N_("net rap share\n"
1281 " List shares exported by server")
1284 "session",
1285 net_rap_session,
1286 NET_TRANSPORT_RAP,
1287 N_("List open sessions"),
1288 N_("net rap session\n"
1289 " List open sessions")
1292 "server",
1293 net_rap_server,
1294 NET_TRANSPORT_RAP,
1295 N_("List servers in workgroup"),
1296 N_("net rap server\n"
1297 " List servers in domain/workgroup")
1300 "domain",
1301 net_rap_domain,
1302 NET_TRANSPORT_RAP,
1303 N_("List domains in network"),
1304 N_("net rap domain\n"
1305 " List domains in network")
1308 "printq",
1309 net_rap_printq,
1310 NET_TRANSPORT_RAP,
1311 N_("List printer queues on server"),
1312 N_("net rap printq\n"
1313 " List printer queues on server")
1316 "user",
1317 net_rap_user,
1318 NET_TRANSPORT_RAP,
1319 N_("List users"),
1320 N_("net rap user\n"
1321 " List users")
1324 "group",
1325 net_rap_group,
1326 NET_TRANSPORT_RAP,
1327 N_("List user groups"),
1328 N_("net rap group\n"
1329 " List user groups")
1332 "validate",
1333 net_rap_validate,
1334 NET_TRANSPORT_RAP,
1335 N_("Check username/password"),
1336 N_("net rap validate\n"
1337 " Check username/password")
1340 "groupmember",
1341 net_rap_groupmember,
1342 NET_TRANSPORT_RAP,
1343 N_("List/modify group memberships"),
1344 N_("net rap groupmember\n"
1345 " List/modify group memberships")
1348 "admin",
1349 net_rap_admin,
1350 NET_TRANSPORT_RAP,
1351 N_("Execute commands on remote OS/2"),
1352 N_("net rap admin\n"
1353 " Execute commands on remote OS/2")
1356 "service",
1357 net_rap_service,
1358 NET_TRANSPORT_RAP,
1359 N_("Start/stop remote service"),
1360 N_("net rap service\n"
1361 " Start/stop remote service")
1364 "password",
1365 net_rap_password,
1366 NET_TRANSPORT_RAP,
1367 N_("Change user password"),
1368 N_("net rap password\n"
1369 " Change user password")
1371 {NULL, NULL, 0, NULL, NULL}
1374 return net_run_function(c, argc, argv, "net rap", func);