2
* Unix SMB/CIFS implementation.
4
* Copyright (C) Guenther Deschner 2008
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.
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.
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/>.
20
#include <sys/types.h>
30
int main(int argc, const char **argv)
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;
43
struct poptOption long_options[] = {
45
POPT_COMMON_LIBNETAPI_EXAMPLES
49
status = libnetapi_init(&ctx);
54
pc = poptGetContext("user_add", argc, argv, long_options, 0);
56
poptSetOtherOptionHelp(pc, "hostname username password");
57
while((opt = poptGetNextOpt(pc)) != -1) {
60
if (!poptPeekArg(pc)) {
61
poptPrintHelp(pc, stderr, 0);
64
hostname = poptGetArg(pc);
66
if (!poptPeekArg(pc)) {
67
poptPrintHelp(pc, stderr, 0);
70
username = poptGetArg(pc);
72
if (!poptPeekArg(pc)) {
73
poptPrintHelp(pc, stderr, 0);
76
password = poptGetArg(pc);
80
info1.usri1_name = username;
81
info1.usri1_password = password;
82
info1.usri1_password_age = 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;
89
status = NetUserAdd(hostname,
94
printf("NetUserAdd failed with: %s\n",
95
libnetapi_get_error_string(ctx, status));