samba-3.5.8 for ARM
[tomato.git] / release / src-rt-6.x.4708 / router / samba-3.5.8 / source3 / lib / netapi / examples / share / share_setinfo.c
blobf4748f4122307f5604aa6453ae415e97b3f17bb9
1 /*
2 * Unix SMB/CIFS implementation.
3 * NetShareSetInfo 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 *sharename = NULL;
36 const char *comment = "NetApi generated Share comment";
37 uint32_t level = 1004;
38 uint8_t *buffer = NULL;
39 uint32_t parm_err = 0;
41 struct SHARE_INFO_1004 i1004;
43 poptContext pc;
44 int opt;
46 struct poptOption long_options[] = {
47 POPT_AUTOHELP
48 POPT_COMMON_LIBNETAPI_EXAMPLES
49 POPT_TABLEEND
52 status = libnetapi_init(&ctx);
53 if (status != 0) {
54 return status;
57 pc = poptGetContext("share_setinfo", argc, argv, long_options, 0);
59 poptSetOtherOptionHelp(pc, "hostname sharename comment");
60 while((opt = poptGetNextOpt(pc)) != -1) {
63 if (!poptPeekArg(pc)) {
64 poptPrintHelp(pc, stderr, 0);
65 goto out;
67 hostname = poptGetArg(pc);
69 if (!poptPeekArg(pc)) {
70 poptPrintHelp(pc, stderr, 0);
71 goto out;
73 sharename = poptGetArg(pc);
75 if (poptPeekArg(pc)) {
76 comment = poptGetArg(pc);
79 /* NetShareSetInfo */
80 switch (level) {
81 case 1004:
82 i1004.shi1004_remark = comment;
83 buffer = (uint8_t *)&i1004;
84 break;
85 default:
86 break;
89 status = NetShareSetInfo(hostname,
90 sharename,
91 level,
92 buffer,
93 &parm_err);
94 if (status != 0) {
95 printf("NetShareSetInfo failed with: %s\n",
96 libnetapi_get_error_string(ctx, status));
97 goto out;
100 out:
101 libnetapi_free(ctx);
102 poptFreeContext(pc);
104 return status;