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)
8 Copyright (C) 2004 Stefan Metzmacher (metze@samba.org)
10 Largely rewritten by metze in August 2004
12 Originally written by Steve and Jim. Largely rewritten by tridge in
15 Reworked again by abartlet in December 2001
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 2 of the License, or
20 (at your option) any later version.
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 /*****************************************************/
34 /* Distributed SMB/CIFS Server Management Utility */
36 /* The intent was to make the syntax similar */
37 /* to the NET utility (first developed in DOS */
38 /* with additional interesting & useful functions */
39 /* added in later SMB server network operating */
42 /*****************************************************/
45 #include "lib/cmdline/popt_common.h"
48 run a function from a function table. If not found then
49 call the specified usage function
51 int net_run_function(struct net_context *ctx,
52 int argc, const char **argv,
53 const struct net_functable *functable,
54 int (*usage_fn)(struct net_context *ctx, int argc, const char **argv))
59 d_printf("Usage: \n");
60 return usage_fn(ctx, argc, argv);
63 for (i=0; functable[i].name; i++) {
64 if (StrCaseCmp(argv[0], functable[i].name) == 0)
65 return functable[i].fn(ctx, argc-1, argv+1);
68 d_printf("No command: %s\n", argv[0]);
69 return usage_fn(ctx, argc, argv);
73 run a usage function from a function table. If not found then fail
75 int net_run_usage(struct net_context *ctx,
76 int argc, const char **argv,
77 const struct net_functable *functable)
82 d_printf("net_run_usage: TODO (argc < 1)\n");
86 for (i=0; functable[i].name; i++) {
87 if (StrCaseCmp(argv[0], functable[i].name) == 0)
88 if (functable[i].usage) {
89 return functable[i].usage(ctx, argc-1, argv+1);
93 d_printf("No usage for command: %s\n", argv[0]);
99 run a usage function from a function table. If not found then fail
101 int net_run_help(struct net_context *ctx,
102 int argc, const char **argv,
103 const struct net_functable *functable)
108 d_printf("net_run_help: TODO (argc < 1)\n");
112 for (i=0; functable[i].name; i++) {
113 if (StrCaseCmp(argv[0], functable[i].name) == 0)
114 if (functable[i].help) {
115 return functable[i].help(ctx, argc-1, argv+1);
119 d_printf("No help for command: %s\n", argv[0]);
124 static int net_help(struct net_context *ctx, int argc, const char **argv)
126 d_printf("net_help: TODO\n");
130 static int net_help_usage(struct net_context *ctx, int argc, const char **argv)
132 d_printf("net_help_usage: TODO\n");
136 /* main function table */
137 static const struct net_functable const net_functable[] = {
138 {"password", net_password, net_password_usage, net_password_help},
139 {"time", net_time, net_time_usage, net_time_help},
141 {"help", net_help, net_help_usage, net_help},
145 static int net_usage(struct net_context *ctx, int argc, const char **argv)
147 return net_run_usage(ctx, argc, argv, net_functable);
150 /****************************************************************************
152 ****************************************************************************/
153 static int binary_net(int argc, const char **argv)
158 const char **argv_new;
160 struct net_context *ctx;
162 struct poptOption long_options[] = {
165 POPT_COMMON_CONNECTION
166 POPT_COMMON_CREDENTIALS
171 setup_logging("net", DEBUG_STDOUT);
173 #ifdef HAVE_SETBUFFER
174 setbuffer(stdout, NULL, 0);
177 pc = poptGetContext("net", argc, (const char **) argv, long_options,
178 POPT_CONTEXT_KEEP_FIRST);
180 while((opt = poptGetNextOpt(pc)) != -1) {
183 d_printf("Invalid option %s: %s\n",
184 poptBadOption(pc, 0), poptStrerror(opt));
185 net_help(ctx, argc, argv);
190 lp_load(dyn_CONFIGFILE,True,False,False);
193 argv_new = (const char **)poptGetArgs(pc);
196 for (i=0; i<argc; i++) {
197 if (argv_new[i] == NULL) {
204 d_printf("Usage: TODO\n");
208 mem_ctx = talloc_init("net_context");
209 ctx = talloc_p(mem_ctx, struct net_context);
211 d_printf("talloc_init(net_context) failed\n");
216 ctx->mem_ctx = mem_ctx;
217 ctx->user.account_name = talloc_strdup(ctx->mem_ctx, cmdline_get_username());
218 ctx->user.domain_name = talloc_strdup(ctx->mem_ctx, cmdline_get_userdomain());
219 ctx->user.password = talloc_strdup(ctx->mem_ctx, cmdline_get_userpassword());
221 rc = net_run_function(ctx, argc_new-1, argv_new+1, net_functable, net_usage);
224 DEBUG(0,("return code = %d\n", rc));
227 talloc_destroy(mem_ctx);
231 int main(int argc, const char **argv)
233 return binary_net(argc, argv);