| 1 | /*
|
|---|
| 2 | * Unix SMB/CIFS implementation.
|
|---|
| 3 | * NetShareGetInfo 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)
|
|---|
| 31 | {
|
|---|
| 32 | NET_API_STATUS status;
|
|---|
| 33 | struct libnetapi_ctx *ctx = NULL;
|
|---|
| 34 | const char *hostname = NULL;
|
|---|
| 35 | const char *sharename = NULL;
|
|---|
| 36 | uint32_t level = 2;
|
|---|
| 37 | uint8_t *buffer = NULL;
|
|---|
| 38 |
|
|---|
| 39 | struct SHARE_INFO_0 *i0 = NULL;
|
|---|
| 40 | struct SHARE_INFO_1 *i1 = NULL;
|
|---|
| 41 | struct SHARE_INFO_2 *i2 = NULL;
|
|---|
| 42 | struct SHARE_INFO_501 *i501 = NULL;
|
|---|
| 43 | struct SHARE_INFO_1005 *i1005 = NULL;
|
|---|
| 44 |
|
|---|
| 45 | poptContext pc;
|
|---|
| 46 | int opt;
|
|---|
| 47 |
|
|---|
| 48 | struct poptOption long_options[] = {
|
|---|
| 49 | POPT_AUTOHELP
|
|---|
| 50 | POPT_COMMON_LIBNETAPI_EXAMPLES
|
|---|
| 51 | POPT_TABLEEND
|
|---|
| 52 | };
|
|---|
| 53 |
|
|---|
| 54 | status = libnetapi_init(&ctx);
|
|---|
| 55 | if (status != 0) {
|
|---|
| 56 | return status;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | pc = poptGetContext("share_getinfo", argc, argv, long_options, 0);
|
|---|
| 60 |
|
|---|
| 61 | poptSetOtherOptionHelp(pc, "hostname sharename level");
|
|---|
| 62 | while((opt = poptGetNextOpt(pc)) != -1) {
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | if (!poptPeekArg(pc)) {
|
|---|
| 66 | poptPrintHelp(pc, stderr, 0);
|
|---|
| 67 | goto out;
|
|---|
| 68 | }
|
|---|
| 69 | hostname = poptGetArg(pc);
|
|---|
| 70 |
|
|---|
| 71 | if (!poptPeekArg(pc)) {
|
|---|
| 72 | poptPrintHelp(pc, stderr, 0);
|
|---|
| 73 | goto out;
|
|---|
| 74 | }
|
|---|
| 75 | sharename = poptGetArg(pc);
|
|---|
| 76 |
|
|---|
| 77 | if (poptPeekArg(pc)) {
|
|---|
| 78 | level = atoi(poptGetArg(pc));
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | /* NetShareGetInfo */
|
|---|
| 82 |
|
|---|
| 83 | status = NetShareGetInfo(hostname,
|
|---|
| 84 | sharename,
|
|---|
| 85 | level,
|
|---|
| 86 | &buffer);
|
|---|
| 87 | if (status != 0) {
|
|---|
| 88 | printf("NetShareGetInfo failed with: %s\n",
|
|---|
| 89 | libnetapi_get_error_string(ctx, status));
|
|---|
| 90 | goto out;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | switch (level) {
|
|---|
| 94 | case 0:
|
|---|
| 95 | i0 = (struct SHARE_INFO_0 *)buffer;
|
|---|
| 96 | break;
|
|---|
| 97 | case 1:
|
|---|
| 98 | i1 = (struct SHARE_INFO_1 *)buffer;
|
|---|
| 99 | break;
|
|---|
| 100 | case 2:
|
|---|
| 101 | i2 = (struct SHARE_INFO_2 *)buffer;
|
|---|
| 102 | break;
|
|---|
| 103 | case 501:
|
|---|
| 104 | i501 = (struct SHARE_INFO_501 *)buffer;
|
|---|
| 105 | break;
|
|---|
| 106 | case 1005:
|
|---|
| 107 | i1005 = (struct SHARE_INFO_1005 *)buffer;
|
|---|
| 108 | break;
|
|---|
| 109 |
|
|---|
| 110 | default:
|
|---|
| 111 | break;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | switch (level) {
|
|---|
| 115 | case 0:
|
|---|
| 116 | printf("netname: %s\n", i0->shi0_netname);
|
|---|
| 117 | break;
|
|---|
| 118 | case 1:
|
|---|
| 119 | printf("netname: %s\n", i1->shi1_netname);
|
|---|
| 120 | printf("type: %d\n", i1->shi1_type);
|
|---|
| 121 | printf("remark: %s\n", i1->shi1_remark);
|
|---|
| 122 | break;
|
|---|
| 123 | case 2:
|
|---|
| 124 | printf("netname: %s\n", i2->shi2_netname);
|
|---|
| 125 | printf("type: %d\n", i2->shi2_type);
|
|---|
| 126 | printf("remark: %s\n", i2->shi2_remark);
|
|---|
| 127 | printf("permissions: %d\n", i2->shi2_permissions);
|
|---|
| 128 | printf("max users: %d\n", i2->shi2_max_uses);
|
|---|
| 129 | printf("current users: %d\n", i2->shi2_current_uses);
|
|---|
| 130 | printf("path: %s\n", i2->shi2_path);
|
|---|
| 131 | printf("password: %s\n", i2->shi2_passwd);
|
|---|
| 132 | break;
|
|---|
| 133 | case 501:
|
|---|
| 134 | printf("netname: %s\n", i501->shi501_netname);
|
|---|
| 135 | printf("type: %d\n", i501->shi501_type);
|
|---|
| 136 | printf("remark: %s\n", i501->shi501_remark);
|
|---|
| 137 | printf("flags: %d\n", i501->shi501_flags);
|
|---|
| 138 | break;
|
|---|
| 139 | case 1005:
|
|---|
| 140 | printf("flags: %d\n", i1005->shi1005_flags);
|
|---|
| 141 | break;
|
|---|
| 142 | default:
|
|---|
| 143 | break;
|
|---|
| 144 | }
|
|---|
| 145 | NetApiBufferFree(buffer);
|
|---|
| 146 |
|
|---|
| 147 | out:
|
|---|
| 148 | libnetapi_free(ctx);
|
|---|
| 149 | poptFreeContext(pc);
|
|---|
| 150 |
|
|---|
| 151 | return status;
|
|---|
| 152 | }
|
|---|