samba-3.5.8 for ARM
[tomato.git] / release / src-rt-6.x.4708 / router / samba-3.5.8 / source3 / lib / netapi / examples / join / rename_machine.c
bloba21f9198d879fe0078af51292308419d1ce386fe
1 /*
2 * Unix SMB/CIFS implementation.
3 * NetRenameMachineInDomain 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 <string.h>
21 #include <stdio.h>
22 #include <sys/types.h>
23 #include <inttypes.h>
25 #include <netapi.h>
27 #include "common.h"
29 int main(int argc, const char **argv)
31 NET_API_STATUS status;
32 const char *host_name = NULL;
33 const char *new_machine_name = NULL;
34 uint32_t rename_opt = 0;
35 struct libnetapi_ctx *ctx = NULL;
37 poptContext pc;
38 int opt;
40 struct poptOption long_options[] = {
41 POPT_AUTOHELP
42 POPT_COMMON_LIBNETAPI_EXAMPLES
43 POPT_TABLEEND
46 status = libnetapi_init(&ctx);
47 if (status != 0) {
48 return status;
51 pc = poptGetContext("rename_machine", argc, argv, long_options, 0);
53 poptSetOtherOptionHelp(pc, "hostname newmachinename");
54 while((opt = poptGetNextOpt(pc)) != -1) {
57 if (!poptPeekArg(pc)) {
58 poptPrintHelp(pc, stderr, 0);
59 goto out;
61 host_name = poptGetArg(pc);
63 if (!poptPeekArg(pc)) {
64 poptPrintHelp(pc, stderr, 0);
65 goto out;
67 new_machine_name = poptGetArg(pc);
69 /* NetRenameMachineInDomain */
71 status = NetRenameMachineInDomain(host_name,
72 new_machine_name,
73 ctx->username,
74 ctx->password,
75 rename_opt);
76 if (status != 0) {
77 printf("failed with: %s\n",
78 libnetapi_get_error_string(ctx, status));
81 out:
82 libnetapi_free(ctx);
83 poptFreeContext(pc);
85 return status;