1/* 2 * Unix SMB/CIFS implementation. 3 * NetFile testsuite 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 30static NET_API_STATUS test_netfileenum(const char *hostname, 31 uint32_t level) 32{ 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; 39 40 struct FILE_INFO_2 *i2 = NULL; 41 struct FILE_INFO_3 *i3 = NULL; 42 43 printf("testing NetFileEnum level %d\n", level); 44 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; 65 } 66 67 for (i=0; i<entries_read; i++) { 68 69 switch (level) { 70 case 2: 71 case 3: 72 break; 73 default: 74 break; 75 } 76 77 switch (level) { 78 case 2: 79 i2++; 80 break; 81 case 3: 82 i3++; 83 break; 84 } 85 } 86 NetApiBufferFree(buffer); 87 } 88 } while (status == ERROR_MORE_DATA); 89 90 if (status) { 91 return status; 92 } 93 94 return 0; 95} 96 97NET_API_STATUS netapitest_file(struct libnetapi_ctx *ctx, 98 const char *hostname) 99{ 100 NET_API_STATUS status = 0; 101 uint32_t enum_levels[] = { 2, 3 }; 102 int i; 103 104 printf("NetFile tests\n"); 105 106 /* test enum */ 107 108 for (i=0; i<ARRAY_SIZE(enum_levels); i++) { 109 110 status = test_netfileenum(hostname, enum_levels[i]); 111 if (status) { 112 NETAPI_STATUS(ctx, status, "NetFileEnum"); 113 goto out; 114 } 115 } 116 117 /* basic queries */ 118#if 0 119 { 120 uint32_t levels[] = { 2, 3 }; 121 for (i=0; i<ARRAY_SIZE(levels); i++) { 122 uint8_t *buffer = NULL; 123 124 printf("testing NetFileGetInfo level %d\n", levels[i]); 125 126 status = NetFileGetInfo(hostname, fid, levels[i], &buffer); 127 if (status && status != 124) { 128 NETAPI_STATUS(ctx, status, "NetFileGetInfo"); 129 goto out; 130 } 131 } 132 } 133#endif 134 135 status = 0; 136 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)); 142 } 143 144 return status; 145} 146