s3: Fix an uninitialized variable
[Samba/gebeck_regimport.git] / source3 / utils / net_rap.c
blob9b42a088c0c0b4cd5689782603a3f000aa226f8c
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 "utils/net.h"
29 /* The following messages were for error checking that is not properly
30 reported at the moment. Which should be reinstated? */
31 #define ERRMSG_TARGET_WG_NOT_VALID "\nTarget workgroup option not valid "\
32 "except on net rap server command, ignored"
33 #define ERRMSG_INVALID_HELP_OPTION "\nInvalid help option\n"
35 #define ERRMSG_BOTH_SERVER_IPADDRESS "\nTarget server and IP address both "\
36 "specified. Do not set both at the same time. The target IP address was used\n"
38 static int errmsg_not_implemented(void)
40 d_printf(_("\nNot implemented\n"));
41 return 0;
44 int net_rap_file_usage(struct net_context *c, int argc, const char **argv)
46 return net_file_usage(c, argc, argv);
49 /***************************************************************************
50 list info on an open file
51 ***************************************************************************/
52 static void file_fn(const char * pPath, const char * pUser, uint16 perms,
53 uint16 locks, uint32 id)
55 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
56 id, pUser, perms, locks, pPath);
59 static void one_file_fn(const char *pPath, const char *pUser, uint16 perms,
60 uint16 locks, uint32 id)
62 d_printf(_("File ID %d\n"
63 "User name %s\n"
64 "Locks 0x%-4.2x\n"
65 "Path %s\n"
66 "Permissions 0x%x\n"),
67 id, pUser, locks, pPath, perms);
71 static int rap_file_close(struct net_context *c, int argc, const char **argv)
73 struct cli_state *cli;
74 int ret;
75 if (argc == 0 || c->display_usage) {
76 return net_rap_file_usage(c, argc, argv);
79 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
80 return -1;
82 ret = cli_NetFileClose(cli, atoi(argv[0]));
83 cli_shutdown(cli);
84 return ret;
87 static int rap_file_info(struct net_context *c, int argc, const char **argv)
89 struct cli_state *cli;
90 int ret;
91 if (argc == 0 || c->display_usage)
92 return net_rap_file_usage(c, argc, argv);
94 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
95 return -1;
97 ret = cli_NetFileGetInfo(cli, atoi(argv[0]), one_file_fn);
98 cli_shutdown(cli);
99 return ret;
102 static int rap_file_user(struct net_context *c, int argc, const char **argv)
104 struct cli_state *cli;
105 int ret;
107 if (argc == 0 || c->display_usage)
108 return net_rap_file_usage(c, argc, argv);
110 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
111 return -1;
113 /* list open files */
115 d_printf(_("\nEnumerating open files on remote server:\n\n"
116 "\nFileId Opened by Perms Locks Path \n"
117 "------ --------- ----- ----- ---- \n"));
118 ret = cli_NetFileEnum(cli, argv[0], NULL, file_fn);
120 if (ret == -1)
121 d_printf(_("\nOperation not supported by server!\n\n"));
123 cli_shutdown(cli);
124 return ret;
127 int net_rap_file(struct net_context *c, int argc, const char **argv)
129 struct functable func[] = {
131 "close",
132 rap_file_close,
133 NET_TRANSPORT_RAP,
134 N_("Close specified file on server"),
135 N_("net rap file close\n"
136 " Close specified file on server")
139 "user",
140 rap_file_user,
141 NET_TRANSPORT_RAP,
142 N_("List all files opened by username"),
143 N_("net rap file user\n"
144 " List all files opened by username")
147 "info",
148 rap_file_info,
149 NET_TRANSPORT_RAP,
150 N_("Display info about an opened file"),
151 N_("net rap file info\n"
152 " Display info about an opened file")
154 {NULL, NULL, 0, NULL, NULL}
157 if (argc == 0) {
158 struct cli_state *cli;
159 int ret;
161 if (c->display_usage) {
162 d_printf(_("Usage:\n"));
163 d_printf(_("net rap file\n"
164 " List all open files on rempte "
165 "server\n"));
166 net_display_usage_from_functable(func);
167 return 0;
170 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
171 return -1;
173 /* list open files */
175 d_printf(_("\nEnumerating open files on remote server:\n\n"
176 "\nFileId Opened by Perms Locks Path\n"
177 "------ --------- ----- ----- ----\n"));
178 ret = cli_NetFileEnum(cli, NULL, NULL, file_fn);
180 if (ret == -1)
181 d_printf(_("\nOperation not supported by server!\n\n"));
183 cli_shutdown(cli);
184 return ret;
187 return net_run_function(c, argc, argv, "net rap file", func);
190 int net_rap_share_usage(struct net_context *c, int argc, const char **argv)
192 return net_share_usage(c, argc, argv);
195 static void long_share_fn(const char *share_name, uint32 type,
196 const char *comment, void *state)
198 d_printf("%-12s %-8.8s %-50s\n",
199 share_name, net_share_type_str(type), comment);
202 static void share_fn(const char *share_name, uint32 type,
203 const char *comment, void *state)
205 d_printf("%s\n", share_name);
208 static int rap_share_delete(struct net_context *c, int argc, const char **argv)
210 struct cli_state *cli;
211 int ret;
213 if (argc == 0 || c->display_usage) {
214 return net_rap_share_usage(c, argc, argv);
217 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
218 return -1;
220 ret = cli_NetShareDelete(cli, argv[0]);
221 cli_shutdown(cli);
222 return ret;
225 static int rap_share_add(struct net_context *c, int argc, const char **argv)
227 struct cli_state *cli;
228 int ret;
230 struct rap_share_info_2 sinfo;
231 char *p;
232 char *sharename;
234 if (argc == 0 || c->display_usage) {
235 return net_rap_share_usage(c, argc, argv);
238 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
239 return -1;
241 sharename = SMB_STRDUP(argv[0]);
242 p = strchr(sharename, '=');
243 if (p == NULL) {
244 d_printf(_("Server path not specified\n"));
245 SAFE_FREE(sharename);
246 return net_rap_share_usage(c, argc, argv);
248 *p = 0;
249 strlcpy((char *)sinfo.share_name, sharename, sizeof(sinfo.share_name));
250 sinfo.reserved1 = '\0';
251 sinfo.share_type = 0;
252 sinfo.comment = c->opt_comment ? smb_xstrdup(c->opt_comment) : "";
253 sinfo.perms = 0;
254 sinfo.maximum_users = c->opt_maxusers;
255 sinfo.active_users = 0;
256 sinfo.path = p+1;
257 memset(sinfo.password, '\0', sizeof(sinfo.password));
258 sinfo.reserved2 = '\0';
260 ret = cli_NetShareAdd(cli, &sinfo);
261 cli_shutdown(cli);
262 SAFE_FREE(sharename);
263 return ret;
267 int net_rap_share(struct net_context *c, int argc, const char **argv)
269 struct functable func[] = {
271 "delete",
272 rap_share_delete,
273 NET_TRANSPORT_RAP,
274 N_("Delete a share from server"),
275 N_("net rap share delete\n"
276 " Delete a share from server")
279 "close",
280 rap_share_delete,
281 NET_TRANSPORT_RAP,
282 N_("Delete a share from server"),
283 N_("net rap share close\n"
284 " Delete a share from server\n"
285 " Alias for net rap share delete")
288 "add",
289 rap_share_add,
290 NET_TRANSPORT_RAP,
291 N_("Add a share to server"),
292 N_("net rap share add\n"
293 " Add a share to server")
295 {NULL, NULL, 0, NULL, NULL}
298 if (argc == 0) {
299 struct cli_state *cli;
300 int ret;
302 if (c->display_usage) {
303 d_printf(_("Usage:\n"));
304 d_printf(_("net rap share\n"
305 " List all shares on remote server\n"));
306 net_display_usage_from_functable(func);
307 return 0;
310 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
311 return -1;
313 if (c->opt_long_list_entries) {
314 d_printf(_(
315 "\nEnumerating shared resources (exports) on remote server:\n\n"
316 "\nShare name Type Description\n"
317 "---------- ---- -----------\n"));
318 ret = cli_RNetShareEnum(cli, long_share_fn, NULL);
319 } else {
320 ret = cli_RNetShareEnum(cli, share_fn, NULL);
322 cli_shutdown(cli);
323 return ret;
326 return net_run_function(c, argc, argv, "net rap share", func);
329 int net_rap_session_usage(struct net_context *c, int argc, const char **argv)
331 d_printf(_(
332 "\nnet rap session [misc. options] [targets]"
333 "\n\tenumerates all active SMB/CIFS sessions on target server\n"));
334 d_printf(_(
335 "\nnet rap session DELETE <client_name> [misc. options] [targets] \n"
336 "\tor"
337 "\nnet rap session CLOSE <client_name> [misc. options] [targets]"
338 "\n\tDeletes (closes) a session from specified client to server\n"));
339 d_printf(_(
340 "\nnet rap session INFO <client_name>"
341 "\n\tEnumerates all open files in specified session\n"));
343 net_common_flags_usage(c, argc, argv);
344 return -1;
347 static void list_sessions_func(char *wsname, char *username, uint16 conns,
348 uint16 opens, uint16 users, uint32 sess_time,
349 uint32 idle_time, uint32 user_flags, char *clitype)
351 int hrs = idle_time / 3600;
352 int min = (idle_time / 60) % 60;
353 int sec = idle_time % 60;
355 d_printf("\\\\%-18.18s %-20.20s %-18.18s %5d %2.2d:%2.2d:%2.2d\n",
356 wsname, username, clitype, opens, hrs, min, sec);
359 static void display_session_func(const char *wsname, const char *username,
360 uint16 conns, uint16 opens, uint16 users,
361 uint32 sess_time, uint32 idle_time,
362 uint32 user_flags, const char *clitype)
364 int ihrs = idle_time / 3600;
365 int imin = (idle_time / 60) % 60;
366 int isec = idle_time % 60;
367 int shrs = sess_time / 3600;
368 int smin = (sess_time / 60) % 60;
369 int ssec = sess_time % 60;
370 d_printf(_("User name %-20.20s\n"
371 "Computer %-20.20s\n"
372 "Guest logon %-20.20s\n"
373 "Client Type %-40.40s\n"
374 "Sess time %2.2d:%2.2d:%2.2d\n"
375 "Idle time %2.2d:%2.2d:%2.2d\n"),
376 username, wsname,
377 (user_flags&0x0)?_("yes"):_("no"), clitype,
378 shrs, smin, ssec, ihrs, imin, isec);
381 static void display_conns_func(uint16 conn_id, uint16 conn_type, uint16 opens,
382 uint16 users, uint32 conn_time,
383 const char *username, const char *netname)
385 d_printf("%-14.14s %-8.8s %5d\n",
386 netname, net_share_type_str(conn_type), opens);
389 static int rap_session_info(struct net_context *c, int argc, const char **argv)
391 const char *sessname;
392 struct cli_state *cli;
393 int ret;
395 if (argc == 0 || c->display_usage)
396 return net_rap_session_usage(c, argc, argv);
398 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
399 return -1;
401 sessname = argv[0];
403 ret = cli_NetSessionGetInfo(cli, sessname, display_session_func);
404 if (ret < 0) {
405 cli_shutdown(cli);
406 return ret;
409 d_printf(_("Share name Type # Opens\n-------------------------"
410 "-----------------------------------------------------\n"));
411 ret = cli_NetConnectionEnum(cli, sessname, display_conns_func);
412 cli_shutdown(cli);
413 return ret;
416 static int rap_session_delete(struct net_context *c, int argc, const char **argv)
418 struct cli_state *cli;
419 int ret;
421 if (argc == 0 || c->display_usage)
422 return net_rap_session_usage(c, argc, argv);
424 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
425 return -1;
427 ret = cli_NetSessionDel(cli, argv[0]);
428 cli_shutdown(cli);
429 return ret;
432 int net_rap_session(struct net_context *c, int argc, const char **argv)
434 struct functable func[] = {
436 "info",
437 rap_session_info,
438 NET_TRANSPORT_RAP,
439 N_("Display information about session"),
440 N_("net rap session info\n"
441 " Display information about session")
444 "delete",
445 rap_session_delete,
446 NET_TRANSPORT_RAP,
447 N_("Close specified session"),
448 N_("net rap session delete\n"
449 " Close specified session\n"
450 " Alias for net rap session close")
453 "close",
454 rap_session_delete,
455 NET_TRANSPORT_RAP,
456 N_("Close specified session"),
457 N_("net rap session close\n"
458 " Close specified session")
460 {NULL, NULL, 0, NULL, NULL}
463 if (argc == 0) {
464 struct cli_state *cli;
465 int ret;
467 if (c->display_usage) {
468 d_printf(_("Usage:\n"));
469 d_printf(_("net rap session\n"
470 " List all open sessions on remote "
471 "server\n"));
472 net_display_usage_from_functable(func);
473 return 0;
476 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
477 return -1;
479 d_printf(_("Computer User name "
480 "Client Type Opens Idle time\n"
481 "------------------------------------------"
482 "------------------------------------\n"));
483 ret = cli_NetSessionEnum(cli, list_sessions_func);
485 cli_shutdown(cli);
486 return ret;
489 return net_run_function(c, argc, argv, "net rap session", func);
492 /****************************************************************************
493 list a server name
494 ****************************************************************************/
495 static void display_server_func(const char *name, uint32 m,
496 const char *comment, void * reserved)
498 d_printf("\t%-16.16s %s\n", name, comment);
501 static int net_rap_server_name(struct net_context *c, int argc, const char *argv[])
503 struct cli_state *cli;
504 char *name;
506 if (c->display_usage) {
507 d_printf("%s\n%s",
508 _("Usage:"),
509 _("net rap server name\n"
510 " Get the name of the server\n"));
511 return 0;
514 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
515 return -1;
517 if (!cli_get_server_name(NULL, cli, &name)) {
518 d_fprintf(stderr, _("cli_get_server_name failed\n"));
519 cli_shutdown(cli);
520 return -1;
523 d_printf(_("Server name = %s\n"), name);
525 TALLOC_FREE(name);
526 cli_shutdown(cli);
527 return 0;
530 static int net_rap_server_domain(struct net_context *c, int argc,
531 const char **argv)
533 struct cli_state *cli;
534 int ret;
536 if (c->display_usage) {
537 d_printf("%s\n%s",
538 _("Usage:"),
539 _("net rap server domain\n"
540 " Enumerate servers in this domain/workgroup\n"));
541 return 0;
544 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
545 return -1;
547 d_printf(_("\nEnumerating servers in this domain or workgroup: \n\n"
548 "\tServer name Server description\n"
549 "\t------------- ----------------------------\n"));
551 ret = cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_ALL,
552 display_server_func,NULL);
553 cli_shutdown(cli);
554 return ret;
557 int net_rap_server(struct net_context *c, int argc, const char **argv)
559 struct functable func[] = {
561 "name",
562 net_rap_server_name,
563 NET_TRANSPORT_RAP,
564 N_("Get the name of the server"),
565 N_("net rap server name\n"
566 " Get the name of the server")
569 "domain",
570 net_rap_server_domain,
571 NET_TRANSPORT_RAP,
572 N_("Get the servers in this domain/workgroup"),
573 N_("net rap server domain\n"
574 " Get the servers in this domain/workgroup")
576 {NULL, NULL, 0, NULL, NULL}
579 /* smb4k uses 'net [rap|rpc] server domain' to query servers in a domain */
580 /* Fall through for 'domain', any other forms will cause to show usage message */
581 return net_run_function(c, argc, argv, "net rap server", func);
585 int net_rap_domain_usage(struct net_context *c, int argc, const char **argv)
587 d_printf(_("net rap domain [misc. options] [target]\n\tlists the"
588 " domains or workgroups visible on the current network\n"));
590 net_common_flags_usage(c, argc, argv);
591 return -1;
594 int net_rap_domain(struct net_context *c, int argc, const char **argv)
596 struct cli_state *cli;
597 int ret;
599 if (c->display_usage)
600 return net_rap_domain_usage(c, argc, argv);
602 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
603 return -1;
605 d_printf(_("\nEnumerating domains:\n\n"
606 "\tDomain name Server name of Browse Master\n"
607 "\t------------- ----------------------------\n"));
609 ret = cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_DOMAIN_ENUM,
610 display_server_func,NULL);
611 cli_shutdown(cli);
612 return ret;
615 int net_rap_printq_usage(struct net_context *c, int argc, const char **argv)
617 d_printf(_(
618 "net rap printq [misc. options] [targets]\n"
619 "\tor\n"
620 "net rap printq info [<queue_name>] [misc. options] [targets]\n"
621 "\tlists the specified queue and jobs on the target server.\n"
622 "\tIf the queue name is not specified, all queues are listed.\n\n"));
623 d_printf(_(
624 "net rap printq delete [<queue name>] [misc. options] [targets]\n"
625 "\tdeletes the specified job number on the target server, or the\n"
626 "\tprinter queue if no job number is specified\n"));
628 net_common_flags_usage(c, argc, argv);
630 return -1;
633 static void enum_queue(const char *queuename, uint16 pri, uint16 start,
634 uint16 until, const char *sep, const char *pproc,
635 const char *dest, const char *qparms,
636 const char *qcomment, uint16 status, uint16 jobcount)
638 d_printf(_("%-17.17s Queue %5d jobs "),
639 queuename, jobcount);
641 switch (status) {
642 case 0:
643 d_printf(_("*Printer Active*\n"));
644 break;
645 case 1:
646 d_printf(_("*Printer Paused*\n"));
647 break;
648 case 2:
649 d_printf(_("*Printer error*\n"));
650 break;
651 case 3:
652 d_printf(_("*Delete Pending*\n"));
653 break;
654 default:
655 d_printf(_("**UNKNOWN STATUS**\n"));
659 static void enum_jobs(uint16 jobid, const char *ownername,
660 const char *notifyname, const char *datatype,
661 const char *jparms, uint16 pos, uint16 status,
662 const char *jstatus, unsigned int submitted, unsigned int jobsize,
663 const char *comment)
665 d_printf(" %-23.23s %5d %9d ",
666 ownername, jobid, jobsize);
667 switch (status) {
668 case 0:
669 d_printf(_("Waiting\n"));
670 break;
671 case 1:
672 d_printf(_("Held in queue\n"));
673 break;
674 case 2:
675 d_printf(_("Spooling\n"));
676 break;
677 case 3:
678 d_printf(_("Printing\n"));
679 break;
680 default:
681 d_printf(_("**UNKNOWN STATUS**\n"));
685 #define PRINTQ_ENUM_DISPLAY \
686 _("Print queues at \\\\%s\n\n"\
687 "Name Job # Size Status\n\n"\
688 "------------------------------------------------------------------"\
689 "-------------\n")
691 static int rap_printq_info(struct net_context *c, int argc, const char **argv)
693 struct cli_state *cli;
694 int ret;
696 if (argc == 0 || c->display_usage)
697 return net_rap_printq_usage(c, argc, argv);
699 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
700 return -1;
702 d_printf(PRINTQ_ENUM_DISPLAY, cli->desthost); /* list header */
703 ret = cli_NetPrintQGetInfo(cli, argv[0], enum_queue, enum_jobs);
704 cli_shutdown(cli);
705 return ret;
708 static int rap_printq_delete(struct net_context *c, int argc, const char **argv)
710 struct cli_state *cli;
711 int ret;
713 if (argc == 0 || c->display_usage)
714 return net_rap_printq_usage(c, argc, argv);
716 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
717 return -1;
719 ret = cli_printjob_del(cli, atoi(argv[0]));
720 cli_shutdown(cli);
721 return ret;
724 int net_rap_printq(struct net_context *c, int argc, const char **argv)
726 struct cli_state *cli;
727 int ret;
729 struct functable func[] = {
731 "info",
732 rap_printq_info,
733 NET_TRANSPORT_RAP,
734 N_("Display info about print queues and jobs"),
735 N_("net rap printq info [queue]\n"
736 " Display info about print jobs in queue.\n"
737 " If queue is not specified, all queues are "
738 "listed")
741 "delete",
742 rap_printq_delete,
743 NET_TRANSPORT_RAP,
744 N_("Delete print job(s)"),
745 N_("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 struct 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((char *)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 ? c->opt_comment : "");
832 userinfo.priv = 1;
833 userinfo.home_dir = NULL;
834 userinfo.logon_script = NULL;
835 userinfo.passwrd[0] = '\0';
837 ret = cli_NetUserAdd(cli, &userinfo);
839 cli_shutdown(cli);
840 return ret;
843 static int rap_user_info(struct net_context *c, int argc, const char **argv)
845 struct cli_state *cli;
846 int ret;
847 if (argc == 0 || c->display_usage) {
848 return net_rap_user_usage(c, argc, argv);
851 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
852 return -1;
854 ret = cli_NetUserGetGroups(cli, argv[0], group_member_fn, NULL);
855 cli_shutdown(cli);
856 return ret;
859 int net_rap_user(struct net_context *c, int argc, const char **argv)
861 int ret = -1;
862 struct functable func[] = {
864 "add",
865 rap_user_add,
866 NET_TRANSPORT_RAP,
867 N_("Add specified user"),
868 N_("net rap user add\n"
869 " Add specified user")
872 "info",
873 rap_user_info,
874 NET_TRANSPORT_RAP,
875 N_("List domain groups of specified user"),
876 N_("net rap user info\n"
877 " List domain groups of specified user")
881 "delete",
882 rap_user_delete,
883 NET_TRANSPORT_RAP,
884 N_("Remove specified user"),
885 N_("net rap user delete\n"
886 " Remove specified user")
888 {NULL, NULL, 0, NULL, NULL}
891 if (argc == 0) {
892 struct cli_state *cli;
893 if (c->display_usage) {
894 d_printf(_("Usage:\n"));
895 d_printf(_("net rap user\n"
896 " List all users\n"));
897 net_display_usage_from_functable(func);
898 return 0;
901 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
902 goto done;
903 if (c->opt_long_list_entries) {
904 d_printf(_("\nUser name Comment"
905 "\n-----------------------------\n"));
906 ret = cli_RNetUserEnum(cli, long_user_fn, NULL);
907 cli_shutdown(cli);
908 goto done;
910 ret = cli_RNetUserEnum0(cli, user_fn, NULL);
911 cli_shutdown(cli);
912 goto done;
915 ret = net_run_function(c, argc, argv, "net rap user", func);
916 done:
917 if (ret != 0) {
918 DEBUG(1, (_("Net user returned: %d\n"), ret));
920 return ret;
924 int net_rap_group_usage(struct net_context *c, int argc, const char **argv)
926 return net_group_usage(c, argc, argv);
929 static void long_group_fn(const char *group_name, const char *comment,
930 void *state)
932 d_printf("%-21.21s %s\n", group_name, comment);
935 static void group_fn(const char *group_name, void *state)
937 d_printf("%-21.21s\n", group_name);
940 static int rap_group_delete(struct net_context *c, int argc, const char **argv)
942 struct cli_state *cli;
943 int ret;
944 if (argc == 0 || c->display_usage) {
945 return net_rap_group_usage(c, argc, argv);
948 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
949 return -1;
951 ret = cli_NetGroupDelete(cli, argv[0]);
952 cli_shutdown(cli);
953 return ret;
956 static int rap_group_add(struct net_context *c, int argc, const char **argv)
958 struct cli_state *cli;
959 int ret;
960 struct rap_group_info_1 grinfo;
962 if (argc == 0 || c->display_usage) {
963 return net_rap_group_usage(c, argc, argv);
966 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
967 return -1;
969 /* BB check for length 21 or smaller explicitly ? BB */
970 safe_strcpy((char *)grinfo.group_name, argv[0], sizeof(grinfo.group_name)-1);
971 grinfo.reserved1 = '\0';
972 grinfo.comment = smb_xstrdup(c->opt_comment ? c->opt_comment : "");
974 ret = cli_NetGroupAdd(cli, &grinfo);
975 cli_shutdown(cli);
976 return ret;
979 int net_rap_group(struct net_context *c, int argc, const char **argv)
981 struct functable func[] = {
983 "add",
984 rap_group_add,
985 NET_TRANSPORT_RAP,
986 N_("Add specified group"),
987 N_("net rap group add\n"
988 " Add specified group")
991 "delete",
992 rap_group_delete,
993 NET_TRANSPORT_RAP,
994 N_("Delete specified group"),
995 N_("net rap group delete\n"
996 " Delete specified group")
998 {NULL, NULL, 0, NULL, NULL}
1001 if (argc == 0) {
1002 struct cli_state *cli;
1003 int ret;
1004 if (c->display_usage) {
1005 d_printf(_("Usage:\n"));
1006 d_printf(_("net rap group\n"
1007 " List all groups\n"));
1008 net_display_usage_from_functable(func);
1009 return 0;
1012 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1013 return -1;
1014 if (c->opt_long_list_entries) {
1015 d_printf(_("Group name Comment\n"
1016 "-----------------------------\n"));
1017 ret = cli_RNetGroupEnum(cli, long_group_fn, NULL);
1018 cli_shutdown(cli);
1019 return ret;
1021 ret = cli_RNetGroupEnum0(cli, group_fn, NULL);
1022 cli_shutdown(cli);
1023 return ret;
1026 return net_run_function(c, argc, argv, "net rap group", func);
1029 int net_rap_groupmember_usage(struct net_context *c, int argc, const char **argv)
1031 d_printf(_(
1032 "net rap groupmember LIST <group> [misc. options] [targets]"
1033 "\n\t Enumerate users in a group\n"
1034 "\nnet rap groupmember DELETE <group> <user> [misc. options] "
1035 "[targets]\n\t Delete specified user from specified group\n"
1036 "\nnet rap groupmember ADD <group> <user> [misc. options] [targets]"
1037 "\n\t Add specified user to specified group\n"));
1039 net_common_flags_usage(c, argc, argv);
1040 return -1;
1044 static int rap_groupmember_add(struct net_context *c, int argc, const char **argv)
1046 struct cli_state *cli;
1047 int ret;
1048 if (argc != 2 || c->display_usage) {
1049 return net_rap_groupmember_usage(c, argc, argv);
1052 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1053 return -1;
1055 ret = cli_NetGroupAddUser(cli, argv[0], argv[1]);
1056 cli_shutdown(cli);
1057 return ret;
1060 static int rap_groupmember_delete(struct net_context *c, int argc, const char **argv)
1062 struct cli_state *cli;
1063 int ret;
1064 if (argc != 2 || c->display_usage) {
1065 return net_rap_groupmember_usage(c, argc, argv);
1068 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1069 return -1;
1071 ret = cli_NetGroupDelUser(cli, argv[0], argv[1]);
1072 cli_shutdown(cli);
1073 return ret;
1076 static int rap_groupmember_list(struct net_context *c, int argc, const char **argv)
1078 struct cli_state *cli;
1079 int ret;
1080 if (argc == 0 || c->display_usage) {
1081 return net_rap_groupmember_usage(c, argc, argv);
1084 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1085 return -1;
1087 ret = cli_NetGroupGetUsers(cli, argv[0], group_member_fn, NULL );
1088 cli_shutdown(cli);
1089 return ret;
1092 int net_rap_groupmember(struct net_context *c, int argc, const char **argv)
1094 struct functable func[] = {
1096 "add",
1097 rap_groupmember_add,
1098 NET_TRANSPORT_RAP,
1099 N_("Add specified user to group"),
1100 N_("net rap groupmember add\n"
1101 " Add specified user to group")
1104 "list",
1105 rap_groupmember_list,
1106 NET_TRANSPORT_RAP,
1107 N_("List users in group"),
1108 N_("net rap groupmember list\n"
1109 " List users in group")
1112 "delete",
1113 rap_groupmember_delete,
1114 NET_TRANSPORT_RAP,
1115 N_("Remove user from group"),
1116 N_("net rap groupmember delete\n"
1117 " Remove user from group")
1119 {NULL, NULL, 0, NULL, NULL}
1122 return net_run_function(c, argc, argv, "net rap groupmember", func);
1125 int net_rap_validate_usage(struct net_context *c, int argc, const char **argv)
1127 d_printf(_("net rap validate <username> [password]\n"
1128 "\tValidate user and password to check whether they"
1129 " can access target server or domain\n"));
1131 net_common_flags_usage(c, argc, argv);
1132 return -1;
1135 int net_rap_validate(struct net_context *c, int argc, const char **argv)
1137 return errmsg_not_implemented();
1140 int net_rap_service_usage(struct net_context *c, int argc, const char **argv)
1142 d_printf(_("net rap service [misc. options] [targets] \n"
1143 "\tlists all running service daemons on target server\n"));
1144 d_printf(_("\nnet rap service START <name> [service startup arguments]"
1145 " [misc. options] [targets]"
1146 "\n\tStart named service on remote server\n"));
1147 d_printf(_("\nnet rap service STOP <name> [misc. options] [targets]\n"
1148 "\n\tStop named service on remote server\n"));
1150 net_common_flags_usage(c, argc, argv);
1151 return -1;
1154 static int rap_service_start(struct net_context *c, int argc, const char **argv)
1156 return errmsg_not_implemented();
1159 static int rap_service_stop(struct net_context *c, int argc, const char **argv)
1161 return errmsg_not_implemented();
1164 static void service_fn(const char *service_name, const char *dummy,
1165 void *state)
1167 d_printf("%-21.21s\n", service_name);
1170 int net_rap_service(struct net_context *c, int argc, const char **argv)
1172 struct functable func[] = {
1174 "start",
1175 rap_service_start,
1176 NET_TRANSPORT_RAP,
1177 N_("Start service on remote server"),
1178 N_("net rap service start\n"
1179 " Start service on remote server")
1182 "stop",
1183 rap_service_stop,
1184 NET_TRANSPORT_RAP,
1185 N_("Stop named serve on remote server"),
1186 N_("net rap service stop\n"
1187 " Stop named serve on remote server")
1189 {NULL, NULL, 0, NULL, NULL}
1192 if (argc == 0) {
1193 struct cli_state *cli;
1194 int ret;
1195 if (c->display_usage) {
1196 d_printf(_("Usage:\n"));
1197 d_printf(_("net rap service\n"
1198 " List services on remote server\n"));
1199 net_display_usage_from_functable(func);
1200 return 0;
1203 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1204 return -1;
1206 if (c->opt_long_list_entries) {
1207 d_printf(_("Service name Comment\n"
1208 "-----------------------------\n"));
1209 ret = cli_RNetServiceEnum(cli, long_group_fn, NULL);
1211 ret = cli_RNetServiceEnum(cli, service_fn, NULL);
1212 cli_shutdown(cli);
1213 return ret;
1216 return net_run_function(c, argc, argv, "net rap service", func);
1219 int net_rap_password_usage(struct net_context *c, int argc, const char **argv)
1221 d_printf(_(
1222 "net rap password <user> <oldpwo> <newpw> [misc. options] [target]\n"
1223 "\tchanges the password for the specified user at target\n"));
1225 return -1;
1229 int net_rap_password(struct net_context *c, int argc, const char **argv)
1231 struct cli_state *cli;
1232 int ret;
1234 if (argc < 3 || c->display_usage)
1235 return net_rap_password_usage(c, argc, argv);
1237 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
1238 return -1;
1240 /* BB Add check for password lengths? */
1241 ret = cli_oem_change_password(cli, argv[0], argv[2], argv[1]);
1242 cli_shutdown(cli);
1243 return ret;
1246 int net_rap_admin_usage(struct net_context *c, int argc, const char **argv)
1248 d_printf(_(
1249 "net rap admin <remote command> [cmd args [env]] [misc. options] [targets]"
1250 "\n\texecutes a remote command on an os/2 target server\n"));
1252 return -1;
1256 int net_rap_admin(struct net_context *c, int argc, const char **argv)
1258 return errmsg_not_implemented();
1261 /* Entry-point for all the RAP functions. */
1263 int net_rap(struct net_context *c, int argc, const char **argv)
1265 struct functable func[] = {
1267 "file",
1268 net_rap_file,
1269 NET_TRANSPORT_RAP,
1270 N_("List open files"),
1271 N_("net rap file\n"
1272 " List open files")
1275 "share",
1276 net_rap_share,
1277 NET_TRANSPORT_RAP,
1278 N_("List shares exported by server"),
1279 N_("net rap share\n"
1280 " List shares exported by server")
1283 "session",
1284 net_rap_session,
1285 NET_TRANSPORT_RAP,
1286 N_("List open sessions"),
1287 N_("net rap session\n"
1288 " List open sessions")
1291 "server",
1292 net_rap_server,
1293 NET_TRANSPORT_RAP,
1294 N_("List servers in workgroup"),
1295 N_("net rap server\n"
1296 " List servers in domain/workgroup")
1299 "domain",
1300 net_rap_domain,
1301 NET_TRANSPORT_RAP,
1302 N_("List domains in network"),
1303 N_("net rap domain\n"
1304 " List domains in network")
1307 "printq",
1308 net_rap_printq,
1309 NET_TRANSPORT_RAP,
1310 N_("List printer queues on server"),
1311 N_("net rap printq\n"
1312 " List printer queues on server")
1315 "user",
1316 net_rap_user,
1317 NET_TRANSPORT_RAP,
1318 N_("List users"),
1319 N_("net rap user\n"
1320 " List users")
1323 "group",
1324 net_rap_group,
1325 NET_TRANSPORT_RAP,
1326 N_("List user groups"),
1327 N_("net rap group\n"
1328 " List user groups")
1331 "validate",
1332 net_rap_validate,
1333 NET_TRANSPORT_RAP,
1334 N_("Check username/password"),
1335 N_("net rap validate\n"
1336 " Check username/password")
1339 "groupmember",
1340 net_rap_groupmember,
1341 NET_TRANSPORT_RAP,
1342 N_("List/modify group memberships"),
1343 N_("net rap groupmember\n"
1344 " List/modify group memberships")
1347 "admin",
1348 net_rap_admin,
1349 NET_TRANSPORT_RAP,
1350 N_("Execute commands on remote OS/2"),
1351 N_("net rap admin\n"
1352 " Execute commands on remote OS/2")
1355 "service",
1356 net_rap_service,
1357 NET_TRANSPORT_RAP,
1358 N_("Start/stop remote service"),
1359 N_("net rap service\n"
1360 " Start/stop remote service")
1363 "password",
1364 net_rap_password,
1365 NET_TRANSPORT_RAP,
1366 N_("Change user password"),
1367 N_("net rap password\n"
1368 " Change user password")
1370 {NULL, NULL, 0, NULL, NULL}
1373 return net_run_function(c, argc, argv, "net rap", func);