s4:auth/kerberos: make use of samba_tevent_context_init()
[Samba/gebeck_regimport.git] / source3 / lib / netapi / tests / netfile.c
blobbee3c2ed5eb26a5f9031ef70143368cb5f877942
1 /*
2 * Unix SMB/CIFS implementation.
3 * NetFile testsuite
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 static NET_API_STATUS test_netfileenum(const char *hostname,
31 uint32_t level)
33 NET_API_STATUS status;
34 uint32_t entries_read = 0;
35 uint32_t total_entries = 0;
36 uint32_t resume_handle = 0;
37 uint8_t *buffer = NULL;
38 int i;
40 struct FILE_INFO_2 *i2 = NULL;
41 struct FILE_INFO_3 *i3 = NULL;
43 printf("testing NetFileEnum level %d\n", level);
45 do {
46 status = NetFileEnum(hostname,
47 NULL,
48 NULL,
49 level,
50 &buffer,
51 (uint32_t)-1,
52 &entries_read,
53 &total_entries,
54 &resume_handle);
55 if (status == 0 || status == ERROR_MORE_DATA) {
56 switch (level) {
57 case 2:
58 i2 = (struct FILE_INFO_2 *)buffer;
59 break;
60 case 3:
61 i3 = (struct FILE_INFO_3 *)buffer;
62 break;
63 default:
64 return -1;
67 for (i=0; i<entries_read; i++) {
69 switch (level) {
70 case 2:
71 case 3:
72 break;
73 default:
74 break;
77 switch (level) {
78 case 2:
79 i2++;
80 break;
81 case 3:
82 i3++;
83 break;
86 NetApiBufferFree(buffer);
88 } while (status == ERROR_MORE_DATA);
90 if (status) {
91 return status;
94 return 0;
97 NET_API_STATUS netapitest_file(struct libnetapi_ctx *ctx,
98 const char *hostname)
100 NET_API_STATUS status = 0;
101 uint32_t enum_levels[] = { 2, 3 };
102 int i;
104 printf("NetFile tests\n");
106 /* test enum */
108 for (i=0; i<ARRAY_SIZE(enum_levels); i++) {
110 status = test_netfileenum(hostname, enum_levels[i]);
111 if (status) {
112 NETAPI_STATUS(ctx, status, "NetFileEnum");
113 goto out;
117 /* basic queries */
118 #if 0
120 uint32_t levels[] = { 2, 3 };
121 for (i=0; i<ARRAY_SIZE(levels); i++) {
122 uint8_t *buffer = NULL;
124 printf("testing NetFileGetInfo level %d\n", levels[i]);
126 status = NetFileGetInfo(hostname, fid, levels[i], &buffer);
127 if (status && status != 124) {
128 NETAPI_STATUS(ctx, status, "NetFileGetInfo");
129 goto out;
133 #endif
135 status = 0;
137 printf("NetFile tests succeeded\n");
138 out:
139 if (status != 0) {
140 printf("NetFile testsuite failed with: %s\n",
141 libnetapi_get_error_string(ctx, status));
144 return status;