1/*
2   Samba Unix/Linux SMB client library
3   net help commands
4   Copyright (C) 2002 Jim McDonough (jmcd@us.ibm.com)
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2 of the License, or
9   (at your option) any later version.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software
18   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include "includes.h"
22#include "utils/net.h"
23
24int net_common_methods_usage(int argc, const char**argv)
25{
26	d_printf("Valid methods: (auto-detected if not specified)\n");
27	d_printf("\tads\t\t\t\tActive Directory (LDAP/Kerberos)\n");
28	d_printf("\trpc\t\t\t\tDCE-RPC\n");
29	d_printf("\trap\t\t\t\tRAP (older systems)\n");
30	d_printf("\n");
31	return 0;
32}
33
34int net_common_flags_usage(int argc, const char **argv)
35{
36	d_printf("Valid targets: choose one (none defaults to localhost)\n");
37	d_printf("\t-S or --server=<server>\t\tserver name\n");
38	d_printf("\t-I or --ipaddress=<ipaddr>\taddress of target server\n");
39	d_printf("\t-w or --workgroup=<wg>\t\ttarget workgroup or domain\n");
40
41	d_printf("\n");
42	d_printf("Valid miscellaneous options are:\n"); /* misc options */
43	d_printf("\t-p or --port=<port>\t\tconnection port on target\n");
44	d_printf("\t-W or --myworkgroup=<wg>\tclient workgroup\n");
45	d_printf("\t-d or --debuglevel=<level>\tdebug level (0-10)\n");
46	d_printf("\t-n or --myname=<name>\t\tclient name\n");
47	d_printf("\t-U or --user=<name>\t\tuser name\n");
48	d_printf("\t-s or --configfile=<path>\tpathname of smb.conf file\n");
49	d_printf("\t-l or --long\t\t\tDisplay full information\n");
50	d_printf("\t-V or --version\t\t\tPrint samba version information\n");
51	d_printf("\t-P or --machine-pass\t\tAuthenticate as machine account\n");
52	return -1;
53}
54
55static int help_usage(int argc, const char **argv)
56{
57	d_printf(
58"\n"\
59"Usage: net help <function>\n"\
60"\n"\
61"Valid functions are:\n"\
62"  RPC RAP ADS FILE SHARE SESSION SERVER DOMAIN PRINTQ USER GROUP VALIDATE\n"\
63"  GROUPMEMBER ADMIN SERVICE PASSWORD TIME LOOKUP GETLOCALSID SETLOCALSID\n"\
64"  CHANGESCRETPW\n");
65	return -1;
66}
67
68int net_help_user(int argc, const char **argv)
69{
70	d_printf("\nnet [<method>] user [misc. options] [targets]"\
71		 "\n\tList users\n\n");
72	d_printf("net [<method>] user DELETE <name> [misc. options] [targets]"\
73		 "\n\tDelete specified user\n");
74	d_printf("\nnet [<method>] user INFO <name> [misc. options] [targets]"\
75		 "\n\tList the domain groups of the specified user\n");
76	d_printf("\nnet [<method>] user ADD <name> [password] [-c container] "\
77		 "[-F user flags] [misc. options]"\
78		 " [targets]\n\tAdd specified user\n");
79	d_printf("\nnet [<method>] user RENAME <oldusername> <newusername>"\
80		 " [targets]\n\tRename specified user\n\n");
81
82
83	net_common_methods_usage(argc, argv);
84	net_common_flags_usage(argc, argv);
85	d_printf("\t-C or --comment=<comment>\tdescriptive comment (for add only)\n");
86	d_printf("\t-c or --container=<container>\tLDAP container, defaults to cn=Users (for add in ADS only)\n");
87	return -1;
88}
89
90int net_help_group(int argc, const char **argv)
91{
92	d_printf("net [<method>] group [misc. options] [targets]"\
93		 "\n\tList user groups\n\n");
94	d_printf("net rpc group LIST [global|local|builtin]* [misc. options]"\
95		 "\n\tList specific user groups\n\n");
96	d_printf("net [<method>] group DELETE <name> "\
97		 "[misc. options] [targets]"\
98		 "\n\tDelete specified group\n");
99	d_printf("\nnet [<method>] group ADD <name> [-C comment] [-c container]"\
100		 " [misc. options] [targets]\n\tCreate specified group\n");
101	d_printf("\nnet rpc group MEMBERS <name>\n\tList Group Members\n\n");
102	d_printf("\nnet rpc group ADDMEM <group> <member>\n\tAdd Group Members\n\n");
103	d_printf("\nnet rpc group DELMEM <group> <member>\n\tDelete Group Members\n\n");
104	net_common_methods_usage(argc, argv);
105	net_common_flags_usage(argc, argv);
106	d_printf("\t-C or --comment=<comment>\tdescriptive comment (for add only)\n");
107	d_printf("\t-c or --container=<container>\tLDAP container, defaults to cn=Users (for add in ADS only)\n");
108	d_printf("\t-L or --localgroup\t\tWhen adding groups, create a local group (alias)\n");
109	return -1;
110}
111
112int net_help_join(int argc, const char **argv)
113{
114	d_printf("\nnet [<method>] join [misc. options]\n"
115		 "\tjoins this server to a domain\n");
116	d_printf("Valid methods: (auto-detected if not specified)\n");
117	d_printf("\tads\t\t\t\tActive Directory (LDAP/Kerberos)\n");
118	d_printf("\trpc\t\t\t\tDCE-RPC\n");
119	net_common_flags_usage(argc, argv);
120	return -1;
121}
122
123int net_help_share(int argc, const char **argv)
124{
125	d_printf(
126	 "\nnet [<method>] share [misc. options] [targets] \n"
127	 "\tenumerates all exported resources (network shares) "
128	 "on target server\n\n"
129	 "net [<method>] share ADD <name=serverpath> [misc. options] [targets]"
130	"\n\tadds a share from a server (makes the export active)\n\n"
131	"net [<method>] share DELETE <sharename> [misc. options] [targets]"
132	"\n\tdeletes a share from a server (makes the export inactive)\n\n"
133	"net [<method>] share ALLOWEDUSERS [<filename>] "
134	"[misc. options] [targets]"
135	"\n\tshows a list of all shares together with all users allowed to"
136	"\n\taccess them. This needs the output of 'net usersidlist' on"
137	"\n\tstdin or in <filename>.\n\n"
138	 "net [<method>] share MIGRATE FILES <sharename> [misc. options] [targets]"
139	 "\n\tMigrates files from remote to local server\n\n"
140	 "net [<method>] share MIGRATE SHARES <sharename> [misc. options] [targets]"
141	 "\n\tMigrates shares from remote to local server\n\n"
142/*	 "net [<method>] share MIGRATE SECURITY <sharename> [misc. options] [targets]"
143	 "\n\tMigrates share-ACLs from remote to local server\n\n" */
144	 "net [<method>] share MIGRATE ALL <sharename> [misc. options] [targets]"
145	 "\n\tMigrates shares (including directories, files) from remote\n"
146	 "\tto local server\n\n"
147	);
148	net_common_methods_usage(argc, argv);
149	net_common_flags_usage(argc, argv);
150	d_printf(
151	 "\t-C or --comment=<comment>\tdescriptive comment (for add only)\n"
152	 "\t-M or --maxusers=<num>\t\tmax users allowed for share\n"
153	 "\t      --acls\t\t\tcopies ACLs as well\n"
154	 "\t      --attrs\t\t\tcopies DOS Attributes as well\n"
155	 "\t      --timestamps\t\tpreserve timestamps while copying files\n"
156	 "\t      --destination\t\tmigration target server (default: localhost)\n"
157	 "\t-e or --exclude\t\t\tlist of shares to be excluded from mirroring\n"
158	 "\t-v or --verbose\t\t\tgive verbose output\n");
159	return -1;
160}
161
162int net_help_file(int argc, const char **argv)
163{
164	d_printf("net [<method>] file [misc. options] [targets]\n"\
165		 "\tlists all open files on file server\n\n");
166	d_printf("net [<method>] file USER <username> "\
167		 "[misc. options] [targets]"\
168		 "\n\tlists all files opened by username on file server\n\n");
169	d_printf("net [<method>] file CLOSE <id> [misc. options] [targets]\n"\
170		 "\tcloses specified file on target server\n\n");
171	d_printf("net [rap] file INFO <id> [misc. options] [targets]\n"\
172		 "\tdisplays information about the specified open file\n");
173
174	net_common_methods_usage(argc, argv);
175	net_common_flags_usage(argc, argv);
176	return -1;
177}
178
179int net_help_printer(int argc, const char **argv)
180{
181	d_printf("net rpc printer LIST [printer] [misc. options] [targets]\n"\
182		 "\tlists all printers on print-server\n\n");
183	d_printf("net rpc printer DRIVER [printer] [misc. options] [targets]\n"\
184		 "\tlists all printer-drivers on print-server\n\n");
185	d_printf("net rpc printer PUBLISH action [printer] [misc. options] [targets]\n"\
186		 "\tpublishes printer settings in Active Directory\n"
187		 "\taction can be one of PUBLISH, UPDATE, UNPUBLISH or LIST\n\n");
188	d_printf("net rpc printer MIGRATE PRINTERS [printer] [misc. options] [targets]"\
189		 "\n\tmigrates printers from remote to local server\n\n");
190	d_printf("net rpc printer MIGRATE SETTINGS [printer] [misc. options] [targets]"\
191		 "\n\tmigrates printer-settings from remote to local server\n\n");
192	d_printf("net rpc printer MIGRATE DRIVERS [printer] [misc. options] [targets]"\
193		 "\n\tmigrates printer-drivers from remote to local server\n\n");
194	d_printf("net rpc printer MIGRATE FORMS [printer] [misc. options] [targets]"\
195		 "\n\tmigrates printer-forms from remote to local server\n\n");
196	d_printf("net rpc printer MIGRATE SECURITY [printer] [misc. options] [targets]"\
197		 "\n\tmigrates printer-ACLs from remote to local server\n\n");
198	d_printf("net rpc printer MIGRATE ALL [printer] [misc. options] [targets]"\
199		 "\n\tmigrates drivers, forms, queues, settings and acls from\n"\
200		 "\tremote to local print-server\n\n");
201	net_common_methods_usage(argc, argv);
202	net_common_flags_usage(argc, argv);
203	d_printf(
204	 "\t-v or --verbose\t\t\tgive verbose output\n"
205	 "\t      --destination\t\tmigration target server (default: localhost)\n");
206
207	return -1;
208}
209
210
211int net_help_status(int argc, const char **argv)
212{
213	d_printf("  net status sessions [parseable] "
214		 "Show list of open sessions\n");
215	d_printf("  net status shares [parseable]   "
216		 "Show list of open shares\n");
217	return -1;
218}
219
220static int net_usage(int argc, const char **argv)
221{
222	d_printf("  net time\t\tto view or set time information\n"\
223		 "  net lookup\t\tto lookup host name or ip address\n"\
224		 "  net user\t\tto manage users\n"\
225		 "  net group\t\tto manage groups\n"\
226		 "  net groupmap\t\tto manage group mappings\n"\
227		 "  net join\t\tto join a domain\n"\
228		 "  net cache\t\tto operate on cache tdb file\n"\
229		 "  net getlocalsid [NAME]\tto get the SID for local name\n"\
230		 "  net setlocalsid SID\tto set the local domain SID\n"\
231		 "  net changesecretpw\tto change the machine password in the local secrets database only\n"\
232		 "                    \tthis requires the -f flag as a safety barrier\n"\
233		 "  net status\t\tShow server status\n"\
234		"  net usersidlist\tto get a list of all users with their SIDs\n"
235		 "\n"\
236		 "  net ads <command>\tto run ADS commands\n"\
237		 "  net rap <command>\tto run RAP (pre-RPC) commands\n"\
238		 "  net rpc <command>\tto run RPC commands\n"\
239		 "\n"\
240		 "Type \"net help <option>\" to get more information on that option\n");
241	net_common_flags_usage(argc, argv);
242	return -1;
243}
244
245/*
246  handle "net help *" subcommands
247*/
248int net_help(int argc, const char **argv)
249{
250	struct functable func[] = {
251		{"ADS", net_ads_help},
252		{"RAP", net_rap_help},
253		{"RPC", net_rpc_help},
254
255		{"FILE", net_help_file},
256		{"SHARE", net_help_share},
257		{"SESSION", net_rap_session_usage},
258		{"SERVER", net_rap_server_usage},
259		{"DOMAIN", net_rap_domain_usage},
260		{"PRINTQ", net_rap_printq_usage},
261		{"USER", net_help_user},
262		{"GROUP", net_help_group},
263		{"GROUPMAP", net_help_groupmap},
264		{"JOIN", net_help_join},
265		{"VALIDATE", net_rap_validate_usage},
266		{"GROUPMEMBER", net_rap_groupmember_usage},
267		{"ADMIN", net_rap_admin_usage},
268		{"SERVICE", net_rap_service_usage},
269		{"PASSWORD", net_rap_password_usage},
270		{"TIME", net_time_usage},
271		{"LOOKUP", net_lookup_usage},
272		{"USERSIDLIST", net_usersidlist_usage},
273#ifdef WITH_FAKE_KASERVER
274		{"AFS", net_help_afs},
275#endif
276
277		{"HELP", help_usage},
278		{NULL, NULL}};
279
280	return net_run_function(argc, argv, func, net_usage);
281}
282