/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- main
1 /*
2 * Unix SMB/CIFS implementation.
3 * NetFileEnum 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 *basepath = NULL;
36 const char *username = NULL;
37 uint32_t level = 3;
38 uint8_t *buffer = NULL;
39 uint32_t entries_read = 0;
40 uint32_t total_entries = 0;
41 uint32_t resume_handle = 0;
42 int i;
43
44 struct FILE_INFO_2 *i2 = NULL;
45 struct FILE_INFO_3 *i3 = NULL;
46
47 poptContext pc;
48 int opt;
49
50 struct poptOption long_options[] = {
51 POPT_AUTOHELP
52 POPT_COMMON_LIBNETAPI_EXAMPLES
53 POPT_TABLEEND
54 };
55
56 status = libnetapi_init(&ctx);
57 if (status != 0) {
58 return status;
59 }
60
61 pc = poptGetContext("file_enum", argc, argv, long_options, 0);
62
63 poptSetOtherOptionHelp(pc, "hostname basepath username level");
64 while((opt = poptGetNextOpt(pc)) != -1) {
65 }
66
67 if (!poptPeekArg(pc)) {
68 poptPrintHelp(pc, stderr, 0);
69 goto out;
70 }
71 hostname = poptGetArg(pc);
72
73 if (!poptPeekArg(pc)) {
74 poptPrintHelp(pc, stderr, 0);
75 goto out;
76 }
77 basepath = poptGetArg(pc);
78
79 if (!poptPeekArg(pc)) {
80 poptPrintHelp(pc, stderr, 0);
81 goto out;
82 }
83 username = poptGetArg(pc);
84
85 if (poptPeekArg(pc)) {
86 level = atoi(poptGetArg(pc));
87 }
88
89 /* NetFileEnum */
90
91 do {
92
93 status = NetFileEnum(hostname,
94 basepath,
95 username,
96 level,
97 &buffer,
98 (uint32_t)-1,
99 &entries_read,
100 &total_entries,
101 &resume_handle);
102 if (status == 0 || status == ERROR_MORE_DATA) {
103 printf("total entries: %d\n", total_entries);
104 switch (level) {
105 case 2:
106 i2 = (struct FILE_INFO_2 *)buffer;
107 break;
108 case 3:
109 i3 = (struct FILE_INFO_3 *)buffer;
110 break;
111 default:
112 break;
113 }
114 for (i=0; i<entries_read; i++) {
115 switch (level) {
116 case 2:
117 printf("file_id: %d\n", i2->fi2_id);
118 i2++;
119 break;
120 case 3:
121 printf("file_id: %d\n", i3->fi3_id);
122 printf("permissions: %d\n", i3->fi3_permissions);
123 printf("num_locks: %d\n", i3->fi3_num_locks);
124 printf("pathname: %s\n", i3->fi3_pathname);
125 printf("username: %s\n", i3->fi3_username);
126 i3++;
127 break;
128 default:
129 break;
130 }
131 }
132 NetApiBufferFree(buffer);
133 }
134 } while (status == ERROR_MORE_DATA);
135
136 if (status != 0) {
137 printf("NetFileEnum failed with: %s\n",
138 libnetapi_get_error_string(ctx, status));
139 goto out;
140 }
141 out:
142 libnetapi_free(ctx);
143 poptFreeContext(pc);
144
145 return status;
146 }