/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- main
1 /*
2 * Unix SMB/CIFS implementation.
3 * NetShareAdd 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 *sharename = NULL;
36 const char *path = NULL;
37 uint32_t level = 0;
38 uint32_t parm_err = 0;
39
40 struct SHARE_INFO_2 i2;
41
42 poptContext pc;
43 int opt;
44
45 struct poptOption long_options[] = {
46 POPT_AUTOHELP
47 POPT_COMMON_LIBNETAPI_EXAMPLES
48 POPT_TABLEEND
49 };
50
51 status = libnetapi_init(&ctx);
52 if (status != 0) {
53 return status;
54 }
55
56 pc = poptGetContext("share_add", argc, argv, long_options, 0);
57
58 poptSetOtherOptionHelp(pc, "hostname sharename path");
59 while((opt = poptGetNextOpt(pc)) != -1) {
60 }
61
62 if (!poptPeekArg(pc)) {
63 poptPrintHelp(pc, stderr, 0);
64 goto out;
65 }
66 hostname = poptGetArg(pc);
67
68 if (!poptPeekArg(pc)) {
69 poptPrintHelp(pc, stderr, 0);
70 goto out;
71 }
72 sharename = poptGetArg(pc);
73
74 if (!poptPeekArg(pc)) {
75 poptPrintHelp(pc, stderr, 0);
76 goto out;
77 }
78 path = poptGetArg(pc);
79
80 if (poptPeekArg(pc)) {
81 level = atoi(poptGetArg(pc));
82 }
83
84 /* NetShareAdd */
85
86 i2.shi2_netname = sharename;
87 i2.shi2_type = 0;
88 i2.shi2_remark = "Test share created via NetApi";
89 i2.shi2_permissions = 0;
90 i2.shi2_max_uses = (uint32_t)-1;
91 i2.shi2_current_uses = 0;
92 i2.shi2_path = path;
93 i2.shi2_passwd = NULL;
94
95 status = NetShareAdd(hostname,
96 2,
97 (uint8_t *)&i2,
98 &parm_err);
99 if (status != 0) {
100 printf("NetShareAdd failed with: %s\n",
101 libnetapi_get_error_string(ctx, status));
102 goto out;
103 }
104
105 out:
106 libnetapi_free(ctx);
107 poptFreeContext(pc);
108
109 return status;
110 }