librpc: Shorten dcerpc_binding_handle_call a bit
[Samba/gebeck_regimport.git] / source3 / lib / netapi / examples / user / user_chgpwd.c
blob8b37ec2a99471a578884d275cfb136627e20ca6b
1 /*
2 * Unix SMB/CIFS implementation.
3 * NetUserChangePassword query
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>
21 #include <inttypes.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
26 #include <netapi.h>
28 #include "common.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 *old_password = NULL;
37 const char *new_password = NULL;
39 poptContext pc;
40 int opt;
42 struct poptOption long_options[] = {
43 POPT_AUTOHELP
44 POPT_COMMON_LIBNETAPI_EXAMPLES
45 POPT_TABLEEND
48 status = libnetapi_init(&ctx);
49 if (status != 0) {
50 return status;
53 pc = poptGetContext("user_chgpwd", argc, argv, long_options, 0);
55 poptSetOtherOptionHelp(pc, "hostname username old_password new_password");
56 while((opt = poptGetNextOpt(pc)) != -1) {
59 if (!poptPeekArg(pc)) {
60 poptPrintHelp(pc, stderr, 0);
61 goto out;
63 hostname = poptGetArg(pc);
65 if (!poptPeekArg(pc)) {
66 poptPrintHelp(pc, stderr, 0);
67 goto out;
69 username = poptGetArg(pc);
71 if (!poptPeekArg(pc)) {
72 poptPrintHelp(pc, stderr, 0);
73 goto out;
75 old_password = poptGetArg(pc);
77 if (!poptPeekArg(pc)) {
78 poptPrintHelp(pc, stderr, 0);
79 goto out;
81 new_password = poptGetArg(pc);
83 /* NetUserChangePassword */
85 status = NetUserChangePassword(hostname,
86 username,
87 old_password,
88 new_password);
89 if (status != 0) {
90 printf("NetUserChangePassword failed with: %s\n",
91 libnetapi_get_error_string(ctx, status));
94 out:
95 libnetapi_free(ctx);
96 poptFreeContext(pc);
98 return status;