1 /* NFSv4.1 client for Windows
2 * Copyright � 2012 The Regents of the University of Michigan
3 *
4 * Olga Kornievskaia <aglo@umich.edu>
5 * Casey Bodley <cbodley@umich.edu>
6 *
7 * This library is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2.1 of the License, or (at
10 * your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful, but
13 * without any warranty; without even the implied warranty of merchantability
14 * or fitness for a particular purpose. See the GNU Lesser General Public
15 * License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 */
21
22 #include <windows.h>
23 #include <stdio.h>
24
25 #include "daemon_debug.h"
26 #include "from_kernel.h"
27 #include "nfs41_driver.h"
28 #include "nfs41_ops.h"
29 #include "service.h"
30 #include "rpc/rpc.h"
31 #include "rpc/auth_sspi.h"
32
33 static int g_debug_level = DEFAULT_DEBUG_LEVEL;
34
set_debug_level(int level)35 void set_debug_level(int level) { g_debug_level = level; }
36
37 FILE *dlog_file, *elog_file;
38
39 #ifndef STANDALONE_NFSD
open_log_files()40 void open_log_files()
41 {
42 const char dfile[] = "nfsddbg.log";
43 const char efile[] = "nfsderr.log";
44 const char mode[] = "w";
45 if (g_debug_level > 0) {
46 dlog_file = fopen(dfile, mode);
47 if (dlog_file == NULL) {
48 ReportStatusToSCMgr(SERVICE_STOPPED, GetLastError(), 0);
49 exit (GetLastError());
50 }
51 }
52 elog_file = fopen(efile, mode);
53 if (elog_file == NULL) {
54 ReportStatusToSCMgr(SERVICE_STOPPED, GetLastError(), 0);
55 exit (GetLastError());
56 }
57 }
58
close_log_files()59 void close_log_files()
60 {
61 if (dlog_file) fclose(dlog_file);
62 if (elog_file) fclose(elog_file);
63 }
64 #else
open_log_files()65 void open_log_files()
66 {
67 dlog_file = stdout;
68 elog_file = stderr;
69 }
70 #endif
71
dprintf(int level,LPCSTR format,...)72 void dprintf(int level, LPCSTR format, ...)
73 {
74 if (level <= g_debug_level) {
75 va_list args;
76 va_start(args, format);
77 fprintf(dlog_file, "%04x: ", GetCurrentThreadId());
78 vfprintf(dlog_file, format, args);
79 #ifndef STANDALONE_NFSD
80 fflush(dlog_file);
81 #endif
82 va_end(args);
83 }
84 }
85
eprintf(LPCSTR format,...)86 void eprintf(LPCSTR format, ...)
87 {
88 va_list args;
89 va_start(args, format);
90 fprintf(elog_file, "%04x: ", GetCurrentThreadId());
91 vfprintf(elog_file, format, args);
92 #ifndef STANDALONE_NFSD
93 fflush(elog_file);
94 #endif
95 va_end(args);
96 }
97
print_hexbuf(int level,unsigned char * title,unsigned char * buf,int len)98 void print_hexbuf(int level, unsigned char *title, unsigned char *buf, int len)
99 {
100 int j, k;
101 if (level > g_debug_level) return;
102 fprintf(dlog_file, "%s", title);
103 for(j = 0, k = 0; j < len; j++, k++) {
104 fprintf(dlog_file, "%02x '%c' ", buf[j], isascii(buf[j])? buf[j]:' ');
105 if (((k+1) % 10 == 0 && k > 0)) {
106 fprintf(dlog_file, "\n");
107 }
108 }
109 fprintf(dlog_file, "\n");
110 }
111
print_hexbuf_no_asci(int level,unsigned char * title,unsigned char * buf,int len)112 void print_hexbuf_no_asci(int level, unsigned char *title, unsigned char *buf, int len)
113 {
114 int j, k;
115 if (level > g_debug_level) return;
116 fprintf(dlog_file, "%s", title);
117 for(j = 0, k = 0; j < len; j++, k++) {
118 fprintf(dlog_file, "%02x ", buf[j]);
119 if (((k+1) % 10 == 0 && k > 0)) {
120 fprintf(dlog_file, "\n");
121 }
122 }
123 fprintf(dlog_file, "\n");
124 }
125
print_create_attributes(int level,DWORD create_opts)126 void print_create_attributes(int level, DWORD create_opts) {
127 if (level > g_debug_level) return;
128 fprintf(dlog_file, "create attributes: ");
129 if (create_opts & FILE_DIRECTORY_FILE)
130 fprintf(dlog_file, "DIRECTORY_FILE ");
131 if (create_opts & FILE_NON_DIRECTORY_FILE)
132 fprintf(dlog_file, "NON_DIRECTORY_FILE ");
133 if (create_opts & FILE_WRITE_THROUGH)
134 fprintf(dlog_file, "WRITE_THROUGH ");
135 if (create_opts & FILE_SEQUENTIAL_ONLY)
136 fprintf(dlog_file, "SEQUENTIAL_ONLY ");
137 if (create_opts & FILE_RANDOM_ACCESS)
138 fprintf(dlog_file, "RANDOM_ACCESS ");
139 if (create_opts & FILE_NO_INTERMEDIATE_BUFFERING)
140 fprintf(dlog_file, "NO_INTERMEDIATE_BUFFERING ");
141 if (create_opts & FILE_SYNCHRONOUS_IO_ALERT)
142 fprintf(dlog_file, "SYNCHRONOUS_IO_ALERT ");
143 if (create_opts & FILE_SYNCHRONOUS_IO_NONALERT)
144 fprintf(dlog_file, "SYNCHRONOUS_IO_NONALERT ");
145 if (create_opts & FILE_CREATE_TREE_CONNECTION)
146 fprintf(dlog_file, "CREATE_TREE_CONNECTION ");
147 if (create_opts & FILE_COMPLETE_IF_OPLOCKED)
148 fprintf(dlog_file, "COMPLETE_IF_OPLOCKED ");
149 if (create_opts & FILE_NO_EA_KNOWLEDGE)
150 fprintf(dlog_file, "NO_EA_KNOWLEDGE ");
151 if (create_opts & FILE_OPEN_REPARSE_POINT)
152 fprintf(dlog_file, "OPEN_REPARSE_POINT ");
153 if (create_opts & FILE_DELETE_ON_CLOSE)
154 fprintf(dlog_file, "DELETE_ON_CLOSE ");
155 if (create_opts & FILE_OPEN_BY_FILE_ID)
156 fprintf(dlog_file, "OPEN_BY_FILE_ID ");
157 if (create_opts & FILE_OPEN_FOR_BACKUP_INTENT)
158 fprintf(dlog_file, "OPEN_FOR_BACKUP_INTENT ");
159 if (create_opts & FILE_RESERVE_OPFILTER)
160 fprintf(dlog_file, "RESERVE_OPFILTER");
161 fprintf(dlog_file, "\n");
162 }
163
print_disposition(int level,DWORD disposition)164 void print_disposition(int level, DWORD disposition) {
165 if (level > g_debug_level) return;
166 fprintf(dlog_file, "userland disposition = ");
167 if (disposition == FILE_SUPERSEDE)
168 fprintf(dlog_file, "FILE_SUPERSEDE\n");
169 else if (disposition == FILE_CREATE)
170 fprintf(dlog_file, "FILE_CREATE\n");
171 else if (disposition == FILE_OPEN)
172 fprintf(dlog_file, "FILE_OPEN\n");
173 else if (disposition == FILE_OPEN_IF)
174 fprintf(dlog_file, "FILE_OPEN_IF\n");
175 else if (disposition == FILE_OVERWRITE)
176 fprintf(dlog_file, "FILE_OVERWRITE\n");
177 else if (disposition == FILE_OVERWRITE_IF)
178 fprintf(dlog_file, "FILE_OVERWRITE_IF\n");
179 }
180
print_access_mask(int level,DWORD access_mask)181 void print_access_mask(int level, DWORD access_mask) {
182 if (level > g_debug_level) return;
183 fprintf(dlog_file, "access mask: ");
184 if (access_mask & FILE_READ_DATA)
185 fprintf(dlog_file, "READ ");
186 if (access_mask & STANDARD_RIGHTS_READ)
187 fprintf(dlog_file, "READ_ACL ");
188 if (access_mask & FILE_READ_ATTRIBUTES)
189 fprintf(dlog_file, "READ_ATTR ");
190 if (access_mask & FILE_READ_EA)
191 fprintf(dlog_file, "READ_EA ");
192 if (access_mask & FILE_WRITE_DATA)
193 fprintf(dlog_file, "WRITE ");
194 if (access_mask & STANDARD_RIGHTS_WRITE)
195 fprintf(dlog_file, "WRITE_ACL ");
196 if (access_mask & FILE_WRITE_ATTRIBUTES)
197 fprintf(dlog_file, "WRITE_ATTR ");
198 if (access_mask & FILE_WRITE_EA)
199 fprintf(dlog_file, "WRITE_EA ");
200 if (access_mask & FILE_APPEND_DATA)
201 fprintf(dlog_file, "APPEND ");
202 if (access_mask & FILE_EXECUTE)
203 fprintf(dlog_file, "EXECUTE ");
204 if (access_mask & FILE_LIST_DIRECTORY)
205 fprintf(dlog_file, "LIST ");
206 if (access_mask & FILE_TRAVERSE)
207 fprintf(dlog_file, "TRAVERSE ");
208 if (access_mask & SYNCHRONIZE)
209 fprintf(dlog_file, "SYNC ");
210 if (access_mask & FILE_DELETE_CHILD)
211 fprintf(dlog_file, "DELETE_CHILD");
212 fprintf(dlog_file, "\n");
213 }
214
print_share_mode(int level,DWORD mode)215 void print_share_mode(int level, DWORD mode)
216 {
217 if (level > g_debug_level) return;
218 fprintf(dlog_file, "share mode: ");
219 if (mode & FILE_SHARE_READ)
220 fprintf(dlog_file, "READ ");
221 if (mode & FILE_SHARE_WRITE)
222 fprintf(dlog_file, "WRITE ");
223 if (mode & FILE_SHARE_DELETE)
224 fprintf(dlog_file, "DELETE");
225 fprintf(dlog_file, "\n");
226 }
227
print_file_id_both_dir_info(int level,FILE_ID_BOTH_DIR_INFO * pboth_dir_info)228 void print_file_id_both_dir_info(int level, FILE_ID_BOTH_DIR_INFO *pboth_dir_info)
229 {
230 if (level > g_debug_level) return;
231 fprintf(dlog_file, "FILE_ID_BOTH_DIR_INFO %p %d\n",
232 pboth_dir_info, sizeof(unsigned char *));
233 fprintf(dlog_file, "\tNextEntryOffset=%ld %d %d\n",
234 pboth_dir_info->NextEntryOffset,
235 sizeof(pboth_dir_info->NextEntryOffset), sizeof(DWORD));
236 fprintf(dlog_file, "\tFileIndex=%ld %d\n", pboth_dir_info->FileIndex,
237 sizeof(pboth_dir_info->FileIndex));
238 fprintf(dlog_file, "\tCreationTime=0x%x %d\n",
239 pboth_dir_info->CreationTime.QuadPart,
240 sizeof(pboth_dir_info->CreationTime));
241 fprintf(dlog_file, "\tLastAccessTime=0x%x %d\n",
242 pboth_dir_info->LastAccessTime.QuadPart,
243 sizeof(pboth_dir_info->LastAccessTime));
244 fprintf(dlog_file, "\tLastWriteTime=0x%x %d\n",
245 pboth_dir_info->LastWriteTime.QuadPart,
246 sizeof(pboth_dir_info->LastWriteTime));
247 fprintf(dlog_file, "\tChangeTime=0x%x %d\n",
248 pboth_dir_info->ChangeTime.QuadPart,
249 sizeof(pboth_dir_info->ChangeTime));
250 fprintf(dlog_file, "\tEndOfFile=0x%x %d\n",
251 pboth_dir_info->EndOfFile.QuadPart,
252 sizeof(pboth_dir_info->EndOfFile));
253 fprintf(dlog_file, "\tAllocationSize=0x%x %d\n",
254 pboth_dir_info->AllocationSize.QuadPart,
255 sizeof(pboth_dir_info->AllocationSize));
256 fprintf(dlog_file, "\tFileAttributes=%ld %d\n",
257 pboth_dir_info->FileAttributes,
258 sizeof(pboth_dir_info->FileAttributes));
259 fprintf(dlog_file, "\tFileNameLength=%ld %d\n",
260 pboth_dir_info->FileNameLength,
261 sizeof(pboth_dir_info->FileNameLength));
262 fprintf(dlog_file, "\tEaSize=%ld %d\n",
263 pboth_dir_info->EaSize, sizeof(pboth_dir_info->EaSize));
264 fprintf(dlog_file, "\tShortNameLength=%d %d\n",
265 pboth_dir_info->ShortNameLength,
266 sizeof(pboth_dir_info->ShortNameLength));
267 fprintf(dlog_file, "\tShortName='%S' %d\n", pboth_dir_info->ShortName,
268 sizeof(pboth_dir_info->ShortName));
269 fprintf(dlog_file, "\tFileId=0x%x %d\n", pboth_dir_info->FileId.QuadPart,
270 sizeof(pboth_dir_info->FileId));
271 fprintf(dlog_file, "\tFileName='%S' %p\n", pboth_dir_info->FileName,
272 pboth_dir_info->FileName);
273 }
274
print_opcode(int level,DWORD opcode)275 void print_opcode(int level, DWORD opcode)
276 {
277 dprintf(level, (LPCSTR)opcode2string(opcode));
278 }
279
opcode2string(DWORD opcode)280 const char* opcode2string(DWORD opcode)
281 {
282 switch(opcode) {
283 case NFS41_SHUTDOWN: return "NFS41_SHUTDOWN";
284 case NFS41_MOUNT: return "NFS41_MOUNT";
285 case NFS41_UNMOUNT: return "NFS41_UNMOUNT";
286 case NFS41_OPEN: return "NFS41_OPEN";
287 case NFS41_CLOSE: return "NFS41_CLOSE";
288 case NFS41_READ: return "NFS41_READ";
289 case NFS41_WRITE: return "NFS41_WRITE";
290 case NFS41_LOCK: return "NFS41_LOCK";
291 case NFS41_UNLOCK: return "NFS41_UNLOCK";
292 case NFS41_DIR_QUERY: return "NFS41_DIR_QUERY";
293 case NFS41_FILE_QUERY: return "NFS41_FILE_QUERY";
294 case NFS41_FILE_SET: return "NFS41_FILE_SET";
295 case NFS41_EA_SET: return "NFS41_EA_SET";
296 case NFS41_EA_GET: return "NFS41_EA_GET";
297 case NFS41_SYMLINK: return "NFS41_SYMLINK";
298 case NFS41_VOLUME_QUERY: return "NFS41_VOLUME_QUERY";
299 case NFS41_ACL_QUERY: return "NFS41_ACL_QUERY";
300 case NFS41_ACL_SET: return "NFS41_ACL_SET";
301 default: return "UNKNOWN";
302 }
303 }
304
nfs_opnum_to_string(int opnum)305 const char* nfs_opnum_to_string(int opnum)
306 {
307 switch (opnum)
308 {
309 case OP_ACCESS: return "ACCESS";
310 case OP_CLOSE: return "CLOSE";
311 case OP_COMMIT: return "COMMIT";
312 case OP_CREATE: return "CREATE";
313 case OP_DELEGPURGE: return "DELEGPURGE";
314 case OP_DELEGRETURN: return "DELEGRETURN";
315 case OP_GETATTR: return "GETATTR";
316 case OP_GETFH: return "GETFH";
317 case OP_LINK: return "LINK";
318 case OP_LOCK: return "LOCK";
319 case OP_LOCKT: return "LOCKT";
320 case OP_LOCKU: return "LOCKU";
321 case OP_LOOKUP: return "LOOKUP";
322 case OP_LOOKUPP: return "LOOKUPP";
323 case OP_NVERIFY: return "NVERIFY";
324 case OP_OPEN: return "OPEN";
325 case OP_OPENATTR: return "OPENATTR";
326 case OP_OPEN_CONFIRM: return "OPEN_CONFIRM";
327 case OP_OPEN_DOWNGRADE: return "OPEN_DOWNGRADE";
328 case OP_PUTFH: return "PUTFH";
329 case OP_PUTPUBFH: return "PUTPUBFH";
330 case OP_PUTROOTFH: return "PUTROOTFH";
331 case OP_READ: return "READ";
332 case OP_READDIR: return "READDIR";
333 case OP_READLINK: return "READLINK";
334 case OP_REMOVE: return "REMOVE";
335 case OP_RENAME: return "RENAME";
336 case OP_RENEW: return "RENEW";
337 case OP_RESTOREFH: return "RESTOREFH";
338 case OP_SAVEFH: return "SAVEFH";
339 case OP_SECINFO: return "SECINFO";
340 case OP_SETATTR: return "SETATTR";
341 case OP_SETCLIENTID: return "SETCLIENTID";
342 case OP_SETCLIENTID_CONFIRM: return "SETCLIENTID_CONFIRM";
343 case OP_VERIFY: return "VERIFY";
344 case OP_WRITE: return "WRITE";
345 case OP_RELEASE_LOCKOWNER: return "RELEASE_LOCKOWNER";
346 case OP_BACKCHANNEL_CTL: return "BACKCHANNEL_CTL";
347 case OP_BIND_CONN_TO_SESSION: return "BIND_CONN_TO_SESSION";
348 case OP_EXCHANGE_ID: return "EXCHANGE_ID";
349 case OP_CREATE_SESSION: return "CREATE_SESSION";
350 case OP_DESTROY_SESSION: return "DESTROY_SESSION";
351 case OP_FREE_STATEID: return "FREE_STATEID";
352 case OP_GET_DIR_DELEGATION: return "GET_DIR_DELEGATION";
353 case OP_GETDEVICEINFO: return "GETDEVICEINFO";
354 case OP_GETDEVICELIST: return "GETDEVICELIST";
355 case OP_LAYOUTCOMMIT: return "LAYOUTCOMMIT";
356 case OP_LAYOUTGET: return "LAYOUTGET";
357 case OP_LAYOUTRETURN: return "LAYOUTRETURN";
358 case OP_SECINFO_NO_NAME: return "SECINFO_NO_NAME";
359 case OP_SEQUENCE: return "SEQUENCE";
360 case OP_SET_SSV: return "SET_SSV";
361 case OP_TEST_STATEID: return "TEST_STATEID";
362 case OP_WANT_DELEGATION: return "WANT_DELEGATION";
363 case OP_DESTROY_CLIENTID: return "DESTROY_CLIENTID";
364 case OP_RECLAIM_COMPLETE: return "RECLAIM_COMPLETE";
365 case OP_ILLEGAL: return "ILLEGAL";
366 default: return "invalid nfs opnum";
367 }
368 }
369
nfs_error_string(int status)370 const char* nfs_error_string(int status)
371 {
372 switch (status)
373 {
374 case NFS4_OK: return "NFS4_OK";
375 case NFS4ERR_PERM: return "NFS4ERR_PERM";
376 case NFS4ERR_NOENT: return "NFS4ERR_NOENT";
377 case NFS4ERR_IO: return "NFS4ERR_IO";
378 case NFS4ERR_NXIO: return "NFS4ERR_NXIO";
379 case NFS4ERR_ACCESS: return "NFS4ERR_ACCESS";
380 case NFS4ERR_EXIST: return "NFS4ERR_EXIST";
381 case NFS4ERR_XDEV: return "NFS4ERR_XDEV";
382 case NFS4ERR_NOTDIR: return "NFS4ERR_NOTDIR";
383 case NFS4ERR_ISDIR: return "NFS4ERR_ISDIR";
384 case NFS4ERR_INVAL: return "NFS4ERR_INVAL";
385 case NFS4ERR_FBIG: return "NFS4ERR_FBIG";
386 case NFS4ERR_NOSPC: return "NFS4ERR_NOSPC";
387 case NFS4ERR_ROFS: return "NFS4ERR_ROFS";
388 case NFS4ERR_MLINK: return "NFS4ERR_MLINK";
389 case NFS4ERR_NAMETOOLONG: return "NFS4ERR_NAMETOOLONG";
390 case NFS4ERR_NOTEMPTY: return "NFS4ERR_NOTEMPTY";
391 case NFS4ERR_DQUOT: return "NFS4ERR_DQUOT";
392 case NFS4ERR_STALE: return "NFS4ERR_STALE";
393 case NFS4ERR_BADHANDLE: return "NFS4ERR_BADHANDLE";
394 case NFS4ERR_BAD_COOKIE: return "NFS4ERR_BAD_COOKIE";
395 case NFS4ERR_NOTSUPP: return "NFS4ERR_NOTSUPP";
396 case NFS4ERR_TOOSMALL: return "NFS4ERR_TOOSMALL";
397 case NFS4ERR_SERVERFAULT: return "NFS4ERR_SERVERFAULT";
398 case NFS4ERR_BADTYPE: return "NFS4ERR_BADTYPE";
399 case NFS4ERR_DELAY: return "NFS4ERR_DELAY";
400 case NFS4ERR_SAME: return "NFS4ERR_SAME";
401 case NFS4ERR_DENIED: return "NFS4ERR_DENIED";
402 case NFS4ERR_EXPIRED: return "NFS4ERR_EXPIRED";
403 case NFS4ERR_LOCKED: return "NFS4ERR_LOCKED";
404 case NFS4ERR_GRACE: return "NFS4ERR_GRACE";
405 case NFS4ERR_FHEXPIRED: return "NFS4ERR_FHEXPIRED";
406 case NFS4ERR_SHARE_DENIED: return "NFS4ERR_SHARE_DENIED";
407 case NFS4ERR_WRONGSEC: return "NFS4ERR_WRONGSEC";
408 case NFS4ERR_CLID_INUSE: return "NFS4ERR_CLID_INUSE";
409 case NFS4ERR_RESOURCE: return "NFS4ERR_RESOURCE";
410 case NFS4ERR_MOVED: return "NFS4ERR_MOVED";
411 case NFS4ERR_NOFILEHANDLE: return "NFS4ERR_NOFILEHANDLE";
412 case NFS4ERR_MINOR_VERS_MISMATCH: return "NFS4ERR_MINOR_VERS_MISMATCH";
413 case NFS4ERR_STALE_CLIENTID: return "NFS4ERR_STALE_CLIENTID";
414 case NFS4ERR_STALE_STATEID: return "NFS4ERR_STALE_STATEID";
415 case NFS4ERR_OLD_STATEID: return "NFS4ERR_OLD_STATEID";
416 case NFS4ERR_BAD_STATEID: return "NFS4ERR_BAD_STATEID";
417 case NFS4ERR_BAD_SEQID: return "NFS4ERR_BAD_SEQID";
418 case NFS4ERR_NOT_SAME: return "NFS4ERR_NOT_SAME";
419 case NFS4ERR_LOCK_RANGE: return "NFS4ERR_LOCK_RANGE";
420 case NFS4ERR_SYMLINK: return "NFS4ERR_SYMLINK";
421 case NFS4ERR_RESTOREFH: return "NFS4ERR_RESTOREFH";
422 case NFS4ERR_LEASE_MOVED: return "NFS4ERR_LEASE_MOVED";
423 case NFS4ERR_ATTRNOTSUPP: return "NFS4ERR_ATTRNOTSUPP";
424 case NFS4ERR_NO_GRACE: return "NFS4ERR_NO_GRACE";
425 case NFS4ERR_RECLAIM_BAD: return "NFS4ERR_RECLAIM_BAD";
426 case NFS4ERR_RECLAIM_CONFLICT: return "NFS4ERR_RECLAIM_CONFLICT";
427 case NFS4ERR_BADXDR: return "NFS4ERR_BADXDR";
428 case NFS4ERR_LOCKS_HELD: return "NFS4ERR_LOCKS_HELD";
429 case NFS4ERR_OPENMODE: return "NFS4ERR_OPENMODE";
430 case NFS4ERR_BADOWNER: return "NFS4ERR_BADOWNER";
431 case NFS4ERR_BADCHAR: return "NFS4ERR_BADCHAR";
432 case NFS4ERR_BADNAME: return "NFS4ERR_BADNAME";
433 case NFS4ERR_BAD_RANGE: return "NFS4ERR_BAD_RANGE";
434 case NFS4ERR_LOCK_NOTSUPP: return "NFS4ERR_LOCK_NOTSUPP";
435 case NFS4ERR_OP_ILLEGAL: return "NFS4ERR_OP_ILLEGAL";
436 case NFS4ERR_DEADLOCK: return "NFS4ERR_DEADLOCK";
437 case NFS4ERR_FILE_OPEN: return "NFS4ERR_FILE_OPEN";
438 case NFS4ERR_ADMIN_REVOKED: return "NFS4ERR_ADMIN_REVOKED";
439 case NFS4ERR_CB_PATH_DOWN: return "NFS4ERR_CB_PATH_DOWN";
440 case NFS4ERR_BADIOMODE: return "NFS4ERR_BADIOMODE";
441 case NFS4ERR_BADLAYOUT: return "NFS4ERR_BADLAYOUT";
442 case NFS4ERR_BAD_SESSION_DIGEST: return "NFS4ERR_BAD_SESSION_DIGEST";
443 case NFS4ERR_BADSESSION: return "NFS4ERR_BADSESSION";
444 case NFS4ERR_BADSLOT: return "NFS4ERR_BADSLOT";
445 case NFS4ERR_COMPLETE_ALREADY: return "NFS4ERR_COMPLETE_ALREADY";
446 case NFS4ERR_CONN_NOT_BOUND_TO_SESSION: return "NFS4ERR_CONN_NOT_BOUND_TO_SESSION";
447 case NFS4ERR_DELEG_ALREADY_WANTED: return "NFS4ERR_DELEG_ALREADY_WANTED";
448 case NFS4ERR_BACK_CHAN_BUSY: return "NFS4ERR_BACK_CHAN_BUSY";
449 case NFS4ERR_LAYOUTTRYLATER: return "NFS4ERR_LAYOUTTRYLATER";
450 case NFS4ERR_LAYOUTUNAVAILABLE: return "NFS4ERR_LAYOUTUNAVAILABLE";
451 case NFS4ERR_NOMATCHING_LAYOUT: return "NFS4ERR_NOMATCHING_LAYOUT";
452 case NFS4ERR_RECALLCONFLICT: return "NFS4ERR_RECALLCONFLICT";
453 case NFS4ERR_UNKNOWN_LAYOUTTYPE: return "NFS4ERR_UNKNOWN_LAYOUTTYPE";
454 case NFS4ERR_SEQ_MISORDERED: return "NFS4ERR_SEQ_MISORDERED";
455 case NFS4ERR_SEQUENCE_POS: return "NFS4ERR_SEQUENCE_POS";
456 case NFS4ERR_REQ_TOO_BIG: return "NFS4ERR_REQ_TOO_BIG";
457 case NFS4ERR_REP_TOO_BIG: return "NFS4ERR_REP_TOO_BIG";
458 case NFS4ERR_REP_TOO_BIG_TO_CACHE: return "NFS4ERR_REP_TOO_BIG_TO_CACHE";
459 case NFS4ERR_RETRY_UNCACHED_REP: return "NFS4ERR_RETRY_UNCACHED_REP";
460 case NFS4ERR_UNSAFE_COMPOUND: return "NFS4ERR_UNSAFE_COMPOUND";
461 case NFS4ERR_TOO_MANY_OPS: return "NFS4ERR_TOO_MANY_OPS";
462 case NFS4ERR_OP_NOT_IN_SESSION: return "NFS4ERR_OP_NOT_IN_SESSION";
463 case NFS4ERR_HASH_ALG_UNSUPP: return "NFS4ERR_HASH_ALG_UNSUPP";
464 case NFS4ERR_CLIENTID_BUSY: return "NFS4ERR_CLIENTID_BUSY";
465 case NFS4ERR_PNFS_IO_HOLE: return "NFS4ERR_PNFS_IO_HOLE";
466 case NFS4ERR_SEQ_FALSE_RETRY: return "NFS4ERR_SEQ_FALSE_RETRY";
467 case NFS4ERR_BAD_HIGH_SLOT: return "NFS4ERR_BAD_HIGH_SLOT";
468 case NFS4ERR_DEADSESSION: return "NFS4ERR_DEADSESSION";
469 case NFS4ERR_ENCR_ALG_UNSUPP: return "NFS4ERR_ENCR_ALG_UNSUPP";
470 case NFS4ERR_PNFS_NO_LAYOUT: return "NFS4ERR_PNFS_NO_LAYOUT";
471 case NFS4ERR_NOT_ONLY_OP: return "NFS4ERR_NOT_ONLY_OP";
472 case NFS4ERR_WRONG_CRED: return "NFS4ERR_WRONG_CRED";
473 case NFS4ERR_WRONG_TYPE: return "NFS4ERR_WRONG_TYPE";
474 case NFS4ERR_DIRDELEG_UNAVAIL: return "NFS4ERR_DIRDELEG_UNAVAIL";
475 case NFS4ERR_REJECT_DELEG: return "NFS4ERR_REJECT_DELEG";
476 case NFS4ERR_RETURNCONFLICT: return "NFS4ERR_RETURNCONFLICT";
477 case NFS4ERR_DELEG_REVOKED: return "NFS4ERR_DELEG_REVOKED";
478 default: return "invalid nfs error code";
479 }
480 }
481
rpc_error_string(int status)482 const char* rpc_error_string(int status)
483 {
484 switch (status)
485 {
486 case RPC_CANTENCODEARGS: return "RPC_CANTENCODEARGS";
487 case RPC_CANTDECODERES: return "RPC_CANTDECODERES";
488 case RPC_CANTSEND: return "RPC_CANTSEND";
489 case RPC_CANTRECV: return "RPC_CANTRECV";
490 case RPC_TIMEDOUT: return "RPC_TIMEDOUT";
491 case RPC_INTR: return "RPC_INTR";
492 case RPC_UDERROR: return "RPC_UDERROR";
493 case RPC_VERSMISMATCH: return "RPC_VERSMISMATCH";
494 case RPC_AUTHERROR: return "RPC_AUTHERROR";
495 case RPC_PROGUNAVAIL: return "RPC_PROGUNAVAIL";
496 case RPC_PROGVERSMISMATCH: return "RPC_PROGVERSMISMATCH";
497 case RPC_PROCUNAVAIL: return "RPC_PROCUNAVAIL";
498 case RPC_CANTDECODEARGS: return "RPC_CANTDECODEARGS";
499 case RPC_SYSTEMERROR: return "RPC_SYSTEMERROR";
500 default: return "invalid rpc error code";
501 }
502 }
503
gssauth_string(int type)504 const char* gssauth_string(int type) {
505 switch(type) {
506 case RPCSEC_SSPI_SVC_NONE: return "RPCSEC_SSPI_SVC_NONE";
507 case RPCSEC_SSPI_SVC_INTEGRITY: return "RPCSEC_SSPI_SVC_INTEGRITY";
508 case RPCSEC_SSPI_SVC_PRIVACY: return "RPCSEC_SSPI_SVC_PRIVACY";
509 default: return "invalid gss auth type";
510 }
511 }
512
print_condwait_status(int level,int status)513 void print_condwait_status(int level, int status)
514 {
515 if (level > g_debug_level) return;
516 switch(status) {
517 case WAIT_ABANDONED: fprintf(dlog_file, "WAIT_ABANDONED\n"); break;
518 case WAIT_OBJECT_0: fprintf(dlog_file, "WAIT_OBJECT_0\n"); break;
519 case WAIT_TIMEOUT: fprintf(dlog_file, "WAIT_TIMEOUT\n"); break;
520 case WAIT_FAILED: fprintf(dlog_file, "WAIT_FAILED %d\n", GetLastError());
521 default: fprintf(dlog_file, "unknown status =%d\n", status);
522 }
523 }
524
print_sr_status_flags(int level,int flags)525 void print_sr_status_flags(int level, int flags)
526 {
527 if (level > g_debug_level) return;
528 fprintf(dlog_file, "%04x: sr_status_flags: ", GetCurrentThreadId());
529 if (flags & SEQ4_STATUS_CB_PATH_DOWN)
530 fprintf(dlog_file, "SEQ4_STATUS_CB_PATH_DOWN ");
531 if (flags & SEQ4_STATUS_CB_GSS_CONTEXTS_EXPIRING)
532 fprintf(dlog_file, "SEQ4_STATUS_CB_GSS_CONTEXTS_EXPIRING ");
533 if (flags & SEQ4_STATUS_CB_GSS_CONTEXTS_EXPIRED)
534 fprintf(dlog_file, "SEQ4_STATUS_CB_GSS_CONTEXTS_EXPIRED ");
535 if (flags & SEQ4_STATUS_EXPIRED_ALL_STATE_REVOKED)
536 fprintf(dlog_file, "SEQ4_STATUS_EXPIRED_ALL_STATE_REVOKED ");
537 if (flags & SEQ4_STATUS_EXPIRED_SOME_STATE_REVOKED)
538 fprintf(dlog_file, "SEQ4_STATUS_EXPIRED_SOME_STATE_REVOKED ");
539 if (flags & SEQ4_STATUS_ADMIN_STATE_REVOKED)
540 fprintf(dlog_file, "SEQ4_STATUS_ADMIN_STATE_REVOKED ");
541 if (flags & SEQ4_STATUS_RECALLABLE_STATE_REVOKED)
542 fprintf(dlog_file, "SEQ4_STATUS_RECALLABLE_STATE_REVOKED ");
543 if (flags & SEQ4_STATUS_LEASE_MOVED)
544 fprintf(dlog_file, "SEQ4_STATUS_LEASE_MOVED ");
545 if (flags & SEQ4_STATUS_RESTART_RECLAIM_NEEDED)
546 fprintf(dlog_file, "SEQ4_STATUS_RESTART_RECLAIM_NEEDED ");
547 if (flags & SEQ4_STATUS_CB_PATH_DOWN_SESSION)
548 fprintf(dlog_file, "SEQ4_STATUS_CB_PATH_DOWN_SESSION ");
549 if (flags & SEQ4_STATUS_BACKCHANNEL_FAULT)
550 fprintf(dlog_file, "SEQ4_STATUS_BACKCHANNEL_FAULT ");
551 if (flags & SEQ4_STATUS_DEVID_CHANGED)
552 fprintf(dlog_file, "SEQ4_STATUS_DEVID_CHANGED ");
553 if (flags & SEQ4_STATUS_DEVID_DELETED)
554 fprintf(dlog_file, "SEQ4_STATUS_DEVID_DELETED ");
555 fprintf(dlog_file, "\n");
556 }
557
secflavorop2name(DWORD sec_flavor)558 const char* secflavorop2name(DWORD sec_flavor)
559 {
560 switch(sec_flavor) {
561 case RPCSEC_AUTH_SYS: return "AUTH_SYS";
562 case RPCSEC_AUTHGSS_KRB5: return "AUTHGSS_KRB5";
563 case RPCSEC_AUTHGSS_KRB5I: return "AUTHGSS_KRB5I";
564 case RPCSEC_AUTHGSS_KRB5P: return "AUTHGSS_KRB5P";
565 }
566
567 return "UNKNOWN FLAVOR";
568 }
569
print_windows_access_mask(int on,ACCESS_MASK m)570 void print_windows_access_mask(int on, ACCESS_MASK m)
571 {
572 if (!on) return;
573 dprintf(1, "--> print_windows_access_mask: %x\n", m);
574 if (m & GENERIC_READ)
575 dprintf(1, "\tGENERIC_READ\n");
576 if (m & GENERIC_WRITE)
577 dprintf(1, "\tGENERIC_WRITE\n");
578 if (m & GENERIC_EXECUTE)
579 dprintf(1, "\tGENERIC_EXECUTE\n");
580 if (m & GENERIC_ALL)
581 dprintf(1, "\tGENERIC_ALL\n");
582 if (m & MAXIMUM_ALLOWED)
583 dprintf(1, "\tMAXIMUM_ALLOWED\n");
584 if (m & ACCESS_SYSTEM_SECURITY)
585 dprintf(1, "\tACCESS_SYSTEM_SECURITY\n");
586 if ((m & SPECIFIC_RIGHTS_ALL) == SPECIFIC_RIGHTS_ALL)
587 dprintf(1, "\tSPECIFIC_RIGHTS_ALL\n");
588 if ((m & STANDARD_RIGHTS_ALL) == STANDARD_RIGHTS_ALL)
589 dprintf(1, "\tSTANDARD_RIGHTS_ALL\n");
590 if ((m & STANDARD_RIGHTS_REQUIRED) == STANDARD_RIGHTS_REQUIRED)
591 dprintf(1, "\tSTANDARD_RIGHTS_REQUIRED\n");
592 if (m & SYNCHRONIZE)
593 dprintf(1, "\tSYNCHRONIZE\n");
594 if (m & WRITE_OWNER)
595 dprintf(1, "\tWRITE_OWNER\n");
596 if (m & WRITE_DAC)
597 dprintf(1, "\tWRITE_DAC\n");
598 if (m & READ_CONTROL)
599 dprintf(1, "\tREAD_CONTROL\n");
600 if (m & DELETE)
601 dprintf(1, "\tDELETE\n");
602 if (m & FILE_READ_DATA)
603 dprintf(1, "\tFILE_READ_DATA\n");
604 if (m & FILE_LIST_DIRECTORY)
605 dprintf(1, "\tFILE_LIST_DIRECTORY\n");
606 if (m & FILE_WRITE_DATA)
607 dprintf(1, "\tFILE_WRITE_DATA\n");
608 if (m & FILE_ADD_FILE)
609 dprintf(1, "\tFILE_ADD_FILE\n");
610 if (m & FILE_APPEND_DATA)
611 dprintf(1, "\tFILE_APPEND_DATA\n");
612 if (m & FILE_ADD_SUBDIRECTORY)
613 dprintf(1, "\tFILE_ADD_SUBDIRECTORY\n");
614 if (m & FILE_CREATE_PIPE_INSTANCE)
615 dprintf(1, "\tFILE_CREATE_PIPE_INSTANCE\n");
616 if (m & FILE_READ_EA)
617 dprintf(1, "\tFILE_READ_EA\n");
618 if (m & FILE_WRITE_EA)
619 dprintf(1, "\tFILE_WRITE_EA\n");
620 if (m & FILE_EXECUTE)
621 dprintf(1, "\tFILE_EXECUTE\n");
622 if (m & FILE_TRAVERSE)
623 dprintf(1, "\tFILE_TRAVERSE\n");
624 if (m & FILE_DELETE_CHILD)
625 dprintf(1, "\tFILE_DELETE_CHILD\n");
626 if (m & FILE_READ_ATTRIBUTES)
627 dprintf(1, "\tFILE_READ_ATTRIBUTES\n");
628 if (m & FILE_WRITE_ATTRIBUTES)
629 dprintf(1, "\tFILE_WRITE_ATTRIBUTES\n");
630 if ((m & FILE_ALL_ACCESS) == FILE_ALL_ACCESS)
631 dprintf(1, "\tFILE_ALL_ACCESS\n");
632 if ((m & FILE_GENERIC_READ) == FILE_GENERIC_READ)
633 dprintf(1, "\tFILE_GENERIC_READ\n");
634 if ((m & FILE_GENERIC_WRITE) == FILE_GENERIC_WRITE)
635 dprintf(1, "\tFILE_GENERIC_WRITE\n");
636 if ((m & FILE_GENERIC_EXECUTE) == FILE_GENERIC_EXECUTE)
637 dprintf(1, "\tFILE_GENERIC_EXECUTE\n");
638 }
639
print_nfs_access_mask(int on,int m)640 void print_nfs_access_mask(int on, int m)
641 {
642 if (!on) return;
643 dprintf(1, "--> print_nfs_access_mask: %x\n", m);
644 if (m & ACE4_READ_DATA)
645 dprintf(1, "\tACE4_READ_DATA\n");
646 if (m & ACE4_LIST_DIRECTORY)
647 dprintf(1, "\tACE4_LIST_DIRECTORY\n");
648 if (m & ACE4_WRITE_DATA)
649 dprintf(1, "\tACE4_WRITE_DATA\n");
650 if (m & ACE4_ADD_FILE)
651 dprintf(1, "\tACE4_ADD_FILE\n");
652 if (m & ACE4_APPEND_DATA)
653 dprintf(1, "\tACE4_APPEND_DATA\n");
654 if (m & ACE4_ADD_SUBDIRECTORY)
655 dprintf(1, "\tACE4_ADD_SUBDIRECTORY\n");
656 if (m & ACE4_READ_NAMED_ATTRS)
657 dprintf(1, "\tACE4_READ_NAMED_ATTRS\n");
658 if (m & ACE4_WRITE_NAMED_ATTRS)
659 dprintf(1, "\tACE4_WRITE_NAMED_ATTRS\n");
660 if (m & ACE4_EXECUTE)
661 dprintf(1, "\tACE4_EXECUTE\n");
662 if (m & ACE4_DELETE_CHILD)
663 dprintf(1, "\tACE4_DELETE_CHILD\n");
664 if (m & ACE4_READ_ATTRIBUTES)
665 dprintf(1, "\tACE4_READ_ATTRIBUTES\n");
666 if (m & ACE4_WRITE_ATTRIBUTES)
667 dprintf(1, "\tACE4_WRITE_ATTRIBUTES\n");
668 if (m & ACE4_DELETE)
669 dprintf(1, "\tACE4_DELETE\n");
670 if (m & ACE4_READ_ACL)
671 dprintf(1, "\tACE4_READ_ACL\n");
672 if (m & ACE4_WRITE_ACL)
673 dprintf(1, "\tACE4_WRITE_ACL\n");
674 if (m & ACE4_WRITE_OWNER)
675 dprintf(1, "\tACE4_WRITE_OWNER\n");
676 if (m & ACE4_SYNCHRONIZE)
677 dprintf(1, "\tACE4_SYNCHRONIZE\n");
678 }
679