/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- main
1 /*
2 * Unix SMB/CIFS implementation.
3 * NetShutdownInit query
4 * Copyright (C) Guenther Deschner 2009
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 *message = NULL;
36 uint32_t timeout = 30;
37
38 poptContext pc;
39 int opt;
40
41 struct poptOption long_options[] = {
42 POPT_AUTOHELP
43 POPT_COMMON_LIBNETAPI_EXAMPLES
44 POPT_TABLEEND
45 };
46
47 status = libnetapi_init(&ctx);
48 if (status != 0) {
49 return status;
50 }
51
52 pc = poptGetContext("shutdown_init", argc, argv, long_options, 0);
53
54 poptSetOtherOptionHelp(pc, "hostname message timeout");
55 while((opt = poptGetNextOpt(pc)) != -1) {
56 }
57
58 if (!poptPeekArg(pc)) {
59 poptPrintHelp(pc, stderr, 0);
60 goto out;
61 }
62 hostname = poptGetArg(pc);
63
64 if (!poptPeekArg(pc)) {
65 poptPrintHelp(pc, stderr, 0);
66 goto out;
67 }
68 message = poptGetArg(pc);
69
70 if (!poptPeekArg(pc)) {
71 poptPrintHelp(pc, stderr, 0);
72 goto out;
73 }
74 timeout = atoi(poptGetArg(pc));
75
76 /* NetShutdownInit */
77
78 status = NetShutdownInit(hostname,
79 message,
80 timeout,
81 1, /* close apps */
82 1); /* reboot */
83 if (status != 0) {
84 printf("NetShutdownInit failed with: %s\n",
85 libnetapi_get_error_string(ctx, status));
86 goto out;
87 }
88
89 out:
90 libnetapi_free(ctx);
91 poptFreeContext(pc);
92
93 return status;
94 }