Add 'net idmap restore'. This restores a broken idmap file
[nivanova/samba-autobuild/.git] / source3 / utils / net_help.c
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
24 int 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
34 int 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>\t\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>\t\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\tPrint samba version information\n");
51         d_printf("\t-P or --machine-pass\t\tAuthenticate as machine account\n");
52         return -1;
53 }
54
55 static 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         return -1;
65 }
66
67 int net_help_user(int argc, const char **argv)
68 {
69         d_printf("\nnet [<method>] user [misc. options] [targets]"\
70                  "\n\tList users\n\n");
71         d_printf("net [<method>] user DELETE <name> [misc. options] [targets]"\
72                  "\n\tDelete specified user\n");
73         d_printf("\nnet [<method>] user INFO <name> [misc. options] [targets]"\
74                  "\n\tList the domain groups of the specified user\n");
75         d_printf("\nnet [<method>] user ADD <name> [password] [-c container] "\
76                  "[-F user flags] [misc. options]"\
77                  " [targets]\n\tAdd specified user\n");
78
79         net_common_methods_usage(argc, argv);
80         net_common_flags_usage(argc, argv);
81         d_printf("\t-C or --comment=<comment>\tdescriptive comment (for add only)\n");
82         d_printf("\t-c or --container=<container>\tLDAP container, defaults to cn=Users (for add in ADS only)\n");
83         return -1;
84 }
85
86 int net_help_group(int argc, const char **argv)
87 {
88         d_printf("net [<method>] group [misc. options] [targets]"\
89                  "\n\tList user groups\n\n");
90         d_printf("net [<method>] group DELETE <name> "\
91                  "[misc. options] [targets]"\
92                  "\n\tDelete specified group\n");
93         d_printf("\nnet [<method>] group ADD <name> [-C comment] [-c container]"\
94                  " [misc. options] [targets]\n\tCreate specified group\n");
95         net_common_methods_usage(argc, argv);
96         net_common_flags_usage(argc, argv);
97         d_printf("\t-C or --comment=<comment>\tdescriptive comment (for add only)\n");
98         d_printf("\t-c or --container=<container>\tLDAP container, defaults to cn=Users (for add in ADS only)\n");
99         return -1;
100 }
101
102 int net_help_groupmap(int argc, const char **argv)
103 {
104         if (getuid() != 0) {
105                 d_printf("You must be root to edit group mappings.\nExiting...\n");
106                 return -1;
107         }
108         
109         d_printf("net groupmap add"\
110                 "\n  Create a new group mapping\n");
111         d_printf("net groupmap modify"\
112                 "\n  Update a group mapping\n");
113         d_printf("net groupmap delete"\
114                 "\n  Remove a group mapping\n");
115         d_printf("net groupmap list"\
116                 "\n  List current group map\n");
117         
118         return -1;
119 }
120
121 int net_help_idmap(int argc, const char **argv)
122 {
123         d_printf("net idmap dump filename"\
124                  "\n  Dump current id mapping\n");
125
126         d_printf("net idmap restore"\
127                  "\n  Restore entries from stdin to current local idmap\n");
128
129         return -1;
130 }
131
132 int net_help_join(int argc, const char **argv)
133 {
134         d_printf("\nnet [<method>] join [misc. options]\n"
135                  "\tjoins this server to a domain\n");
136         d_printf("Valid methods: (auto-detected if not specified)\n");
137         d_printf("\tads\t\t\t\tActive Directory (LDAP/Kerberos)\n");
138         d_printf("\trpc\t\t\t\tDCE-RPC\n");
139         net_common_flags_usage(argc, argv);
140         return -1;
141 }
142
143 int net_help_share(int argc, const char **argv)
144 {
145         d_printf(
146          "\nnet [<method>] share [misc. options] [targets] \n"
147          "\tenumerates all exported resources (network shares) "
148          "on target server\n\n"
149          "net [<method>] share ADD <name=serverpath> [misc. options] [targets]"
150          "\n\tAdds a share from a server (makes the export active)\n\n"
151          "net [<method>] share DELETE <sharename> [misc. options] [targets]\n"
152          "\n\tDeletes a share from a server (makes the export inactive)\n");
153         net_common_methods_usage(argc, argv);
154         net_common_flags_usage(argc, argv);
155         d_printf(
156          "\t-C or --comment=<comment>\tdescriptive comment (for add only)\n"
157          "\t-M or --maxusers=<num>\t\tmax users allowed for share\n");
158         return -1;
159 }
160
161 int net_help_file(int argc, const char **argv)
162 {
163         d_printf("net [<method>] file [misc. options] [targets]\n"\
164                  "\tlists all open files on file server\n\n");
165         d_printf("net [<method>] file USER <username> "\
166                  "[misc. options] [targets]"\
167                  "\n\tlists all files opened by username on file server\n\n");
168         d_printf("net [<method>] file CLOSE <id> [misc. options] [targets]\n"\
169                  "\tcloses specified file on target server\n\n");
170         d_printf("net [rap] file INFO <id> [misc. options] [targets]\n"\
171                  "\tdisplays information about the specified open file\n");
172
173         net_common_methods_usage(argc, argv);
174         net_common_flags_usage(argc, argv);
175         return -1;
176 }
177
178 static int net_usage(int argc, const char **argv)
179 {
180         d_printf("  net time\t\tto view or set time information\n"\
181                  "  net lookup\t\tto lookup host name or ip address\n"\
182                  "  net user\t\tto manage users\n"\
183                  "  net group\t\tto manage groups\n"\
184                  "  net groupmap\t\tto manage group mappings\n"\
185                  "  net join\t\tto join a domain\n"\
186                  "  net cache\t\tto operate on cache tdb file\n"\
187                  "  net getlocalsid [NAME]\tto get the SID for local name\n"\
188                  "  net setlocalsid SID\tto set the local domain SID\n"\
189                  "\n"\
190                  "  net ads <command>\tto run ADS commands\n"\
191                  "  net rap <command>\tto run RAP (pre-RPC) commands\n"\
192                  "  net rpc <command>\tto run RPC commands\n"\
193                  "\n"\
194                  "Type \"net help <option>\" to get more information on that option\n");
195         net_common_flags_usage(argc, argv);
196         return -1;
197 }
198
199 /*
200   handle "net help *" subcommands
201 */
202 int net_help(int argc, const char **argv)
203 {
204         struct functable func[] = {
205                 {"ADS", net_ads_help},  
206                 {"RAP", net_rap_help},
207                 {"RPC", net_rpc_help},
208
209                 {"FILE", net_help_file},
210                 {"SHARE", net_help_share},
211                 {"SESSION", net_rap_session_usage},
212                 {"SERVER", net_rap_server_usage},
213                 {"DOMAIN", net_rap_domain_usage},
214                 {"PRINTQ", net_rap_printq_usage},
215                 {"USER", net_help_user},
216                 {"GROUP", net_help_group},
217                 {"GROUPMAP", net_help_groupmap},
218                 {"JOIN", net_help_join},
219                 {"VALIDATE", net_rap_validate_usage},
220                 {"GROUPMEMBER", net_rap_groupmember_usage},
221                 {"ADMIN", net_rap_admin_usage},
222                 {"SERVICE", net_rap_service_usage},
223                 {"PASSWORD", net_rap_password_usage},
224                 {"TIME", net_time_usage},
225                 {"LOOKUP", net_lookup_usage},
226
227                 {"HELP", help_usage},
228                 {NULL, NULL}};
229
230         return net_run_function(argc, argv, func, net_usage);
231 }