r5425: Convert function tables to new structure (with description)
[bbaumbach/samba-autobuild/.git] / source4 / utils / net / net_user.c
1 /* 
2    Samba Unix/Linux SMB client library 
3    Distributed SMB/CIFS Server Management Utility 
4
5    Copyright (C) Rafal Szczesniak <mimir@samba.org>  2005
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "utils/net/net.h"
24 #include "libnet/libnet.h"
25 #include "librpc/gen_ndr/ndr_samr.h"
26
27 static int net_user_add(struct net_context *ctx, int argc, const char **argv)
28 {
29         NTSTATUS status;
30         struct libnet_context *lnet_ctx;
31         union libnet_CreateUser r;
32         char *user_name;
33
34         /* command line argument preparation */
35         switch (argc) {
36         case 0:
37                 return net_user_usage(ctx, argc, argv);
38                 break;
39         case 1:
40                 user_name = talloc_strdup(ctx->mem_ctx, argv[0]);
41                 break;
42         default:
43                 return net_user_usage(ctx, argc, argv);
44         }
45
46         /* libnet context init and its params */
47         lnet_ctx = libnet_context_init();
48         if (!lnet_ctx) return -1;
49
50         lnet_ctx->user.domain_name   = ctx->user.domain_name;
51         lnet_ctx->user.account_name  = ctx->user.account_name;
52         lnet_ctx->user.password      = ctx->user.password;
53
54         /* calling CreateUser function */
55         r.generic.level              = LIBNET_CREATE_USER_GENERIC;
56         r.generic.in.user_name       = user_name;
57         r.generic.in.domain_name     = lnet_ctx->user.domain_name;
58
59         status = libnet_CreateUser(lnet_ctx, ctx->mem_ctx, &r);
60         if (!NT_STATUS_IS_OK(status)) {
61                 DEBUG(0, ("Failed to add user account: %s\n",
62                           r.generic.out.error_string));
63                 return -1;
64         }
65         
66         libnet_context_destroy(&lnet_ctx);
67         return 0;
68 }
69
70
71 static const struct net_functable net_user_functable[] = {
72         { "add", "create new user account\n", net_user_add, net_user_usage },
73         { NULL, NULL }
74 };
75
76
77 int net_user(struct net_context *ctx, int argc, const char **argv)
78 {
79         return net_run_function(ctx, argc, argv, net_user_functable, net_user_usage);
80 }
81
82
83 int net_user_usage(struct net_context *ctx, int argc, const char **argv)
84 {
85         d_printf("net user <command> [options]\n");
86         return 0;
87 }