/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- main
1 /*
2 * Unix SMB/CIFS implementation.
3 * NetUserAdd query
4 * Copyright (C) Guenther Deschner 2008
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 3 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, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <sys/types.h>
21 #include <inttypes.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include <netapi.h>
27
28 #include "common.h"
29
30 int main(int argc, const char **argv)
/* [<][>][^][v][top][bottom][index][help] */
31 {
32 NET_API_STATUS status;
33 struct libnetapi_ctx *ctx = NULL;
34 const char *hostname = NULL;
35 const char *username = NULL;
36 const char *password = NULL;
37 struct USER_INFO_1 info1;
38 uint32_t parm_error = 0;
39
40 poptContext pc;
41 int opt;
42
43 struct poptOption long_options[] = {
44 POPT_AUTOHELP
45 POPT_COMMON_LIBNETAPI_EXAMPLES
46 POPT_TABLEEND
47 };
48
49 status = libnetapi_init(&ctx);
50 if (status != 0) {
51 return status;
52 }
53
54 pc = poptGetContext("user_add", argc, argv, long_options, 0);
55
56 poptSetOtherOptionHelp(pc, "hostname username password");
57 while((opt = poptGetNextOpt(pc)) != -1) {
58 }
59
60 if (!poptPeekArg(pc)) {
61 poptPrintHelp(pc, stderr, 0);
62 goto out;
63 }
64 hostname = poptGetArg(pc);
65
66 if (!poptPeekArg(pc)) {
67 poptPrintHelp(pc, stderr, 0);
68 goto out;
69 }
70 username = poptGetArg(pc);
71
72 if (!poptPeekArg(pc)) {
73 poptPrintHelp(pc, stderr, 0);
74 goto out;
75 }
76 password = poptGetArg(pc);
77
78 /* NetUserAdd */
79
80 info1.usri1_name = username;
81 info1.usri1_password = password;
82 info1.usri1_password_age = 0;
83 info1.usri1_priv = 0;
84 info1.usri1_home_dir = NULL;
85 info1.usri1_comment = "User created using Samba NetApi Example code";
86 info1.usri1_flags = 0;
87 info1.usri1_script_path = NULL;
88
89 status = NetUserAdd(hostname,
90 1,
91 (uint8_t *)&info1,
92 &parm_error);
93 if (status != 0) {
94 printf("NetUserAdd failed with: %s\n",
95 libnetapi_get_error_string(ctx, status));
96 }
97
98 out:
99 libnetapi_free(ctx);
100 poptFreeContext(pc);
101
102 return status;
103 }