windows-smb-ioctl-setacl-20080721
[openafs.git] / src / WINNT / afsd / smb_ioctl.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afs/param.h>
11 #include <afs/stds.h>
12
13 #include <windows.h>
14 #include <stdlib.h>
15 #include <malloc.h>
16 #include <string.h>
17 #include <stdio.h>
18 #include <time.h>
19 #include <strsafe.h>
20
21 #include <osi.h>
22
23 #include "afsd.h"
24
25 #include "smb.h"
26
27 #include "cm_rpc.h"
28 #include "afs/afsrpc.h"
29 #include "afs/auth.h"
30
31 smb_ioctlProc_t *smb_ioctlProcsp[SMB_IOCTL_MAXPROCS];
32
33 void 
34 smb_InitIoctl(void)
35 {
36     int i;
37     for (i=0; i<SMB_IOCTL_MAXPROCS; i++)
38         smb_ioctlProcsp[i] = NULL;
39
40     smb_ioctlProcsp[VIOCGETAL] = smb_IoctlGetACL;
41     smb_ioctlProcsp[VIOC_FILE_CELL_NAME] = smb_IoctlGetFileCellName;
42     smb_ioctlProcsp[VIOCSETAL] = smb_IoctlSetACL;
43     smb_ioctlProcsp[VIOC_FLUSHVOLUME] = smb_IoctlFlushVolume;
44     smb_ioctlProcsp[VIOCFLUSH] = smb_IoctlFlushFile;
45     smb_ioctlProcsp[VIOCSETVOLSTAT] = smb_IoctlSetVolumeStatus;
46     smb_ioctlProcsp[VIOCGETVOLSTAT] = smb_IoctlGetVolumeStatus;
47     smb_ioctlProcsp[VIOCWHEREIS] = smb_IoctlWhereIs;
48     smb_ioctlProcsp[VIOC_AFS_STAT_MT_PT] = smb_IoctlStatMountPoint;
49     smb_ioctlProcsp[VIOC_AFS_DELETE_MT_PT] = smb_IoctlDeleteMountPoint;
50     smb_ioctlProcsp[VIOCCKSERV] = smb_IoctlCheckServers;
51     smb_ioctlProcsp[VIOC_GAG] = smb_IoctlGag;
52     smb_ioctlProcsp[VIOCCKBACK] = smb_IoctlCheckVolumes;
53     smb_ioctlProcsp[VIOCSETCACHESIZE] = smb_IoctlSetCacheSize;
54     smb_ioctlProcsp[VIOCGETCACHEPARMS] = smb_IoctlGetCacheParms;
55     smb_ioctlProcsp[VIOCGETCELL] = smb_IoctlGetCell;
56     smb_ioctlProcsp[VIOCNEWCELL] = smb_IoctlNewCell;
57     smb_ioctlProcsp[VIOC_GET_WS_CELL] = smb_IoctlGetWsCell;
58     smb_ioctlProcsp[VIOC_AFS_SYSNAME] = smb_IoctlSysName;
59     smb_ioctlProcsp[VIOC_GETCELLSTATUS] = smb_IoctlGetCellStatus;
60     smb_ioctlProcsp[VIOC_SETCELLSTATUS] = smb_IoctlSetCellStatus;
61     smb_ioctlProcsp[VIOC_SETSPREFS] = smb_IoctlSetSPrefs;
62     smb_ioctlProcsp[VIOC_GETSPREFS] = smb_IoctlGetSPrefs;
63     smb_ioctlProcsp[VIOC_STOREBEHIND] = smb_IoctlStoreBehind;
64     smb_ioctlProcsp[VIOC_AFS_CREATE_MT_PT] = smb_IoctlCreateMountPoint;
65     smb_ioctlProcsp[VIOC_TRACECTL] = smb_IoctlTraceControl;
66     smb_ioctlProcsp[VIOCSETTOK] = smb_IoctlSetToken;
67     smb_ioctlProcsp[VIOCGETTOK] = smb_IoctlGetTokenIter;
68     smb_ioctlProcsp[VIOCNEWGETTOK] = smb_IoctlGetToken;
69     smb_ioctlProcsp[VIOCDELTOK] = smb_IoctlDelToken;
70     smb_ioctlProcsp[VIOCDELALLTOK] = smb_IoctlDelAllToken;
71     smb_ioctlProcsp[VIOC_SYMLINK] = smb_IoctlSymlink;
72     smb_ioctlProcsp[VIOC_LISTSYMLINK] = smb_IoctlListlink;
73     smb_ioctlProcsp[VIOC_DELSYMLINK] = smb_IoctlDeletelink;
74     smb_ioctlProcsp[VIOC_MAKESUBMOUNT] = smb_IoctlMakeSubmount;
75     smb_ioctlProcsp[VIOC_GETRXKCRYPT] = smb_IoctlGetRxkcrypt;
76     smb_ioctlProcsp[VIOC_SETRXKCRYPT] = smb_IoctlSetRxkcrypt;
77     smb_ioctlProcsp[VIOC_ISSYMLINK] = smb_IoctlIslink;
78     smb_ioctlProcsp[VIOC_TRACEMEMDUMP] = smb_IoctlMemoryDump;
79     smb_ioctlProcsp[VIOC_ISSYMLINK] = smb_IoctlIslink;
80     smb_ioctlProcsp[VIOC_FLUSHALL] = smb_IoctlFlushAllVolumes;
81     smb_ioctlProcsp[VIOCGETFID] = smb_IoctlGetFid;
82     smb_ioctlProcsp[VIOCGETOWNER] = smb_IoctlGetOwner;
83     smb_ioctlProcsp[VIOC_RXSTAT_PROC] = smb_IoctlRxStatProcess;
84     smb_ioctlProcsp[VIOC_RXSTAT_PEER] = smb_IoctlRxStatPeer;
85     smb_ioctlProcsp[VIOC_UUIDCTL] = smb_IoctlUUIDControl;
86     smb_ioctlProcsp[VIOC_PATH_AVAILABILITY] = smb_IoctlPathAvailability;
87     smb_ioctlProcsp[VIOC_GETFILETYPE] = smb_IoctlGetFileType;
88     smb_ioctlProcsp[VIOC_VOLSTAT_TEST] = smb_IoctlVolStatTest;
89     smb_ioctlProcsp[VIOC_UNICODECTL] = smb_IoctlUnicodeControl;
90 }       
91
92 /* called to make a fid structure into an IOCTL fid structure */
93 void 
94 smb_SetupIoctlFid(smb_fid_t *fidp, cm_space_t *prefix)
95 {
96     smb_ioctl_t *iop;
97     cm_space_t *copyPrefix;
98
99     lock_ObtainMutex(&fidp->mx);
100     fidp->flags |= SMB_FID_IOCTL;
101     fidp->scp = &cm_data.fakeSCache;
102     cm_HoldSCache(fidp->scp);
103     if (fidp->ioctlp == NULL) {
104         iop = malloc(sizeof(*iop));
105         memset(iop, 0, sizeof(*iop));
106         fidp->ioctlp = iop;
107         iop->fidp = fidp;
108     }
109     if (prefix) {
110         copyPrefix = cm_GetSpace();
111         StringCbCopy(copyPrefix->data, CM_UTILS_SPACESIZE, prefix->data);
112         fidp->ioctlp->prefix = copyPrefix;
113     }
114     lock_ReleaseMutex(&fidp->mx);
115 }
116
117 /* called when we receive a read call, does the send of the received data if
118  * this is the first read call.  This is the function that actually makes the
119  * call to the ioctl code.
120  */
121 afs_int32
122 smb_IoctlPrepareRead(struct smb_fid *fidp, smb_ioctl_t *ioctlp, cm_user_t *userp)
123 {
124     afs_int32 opcode;
125     smb_ioctlProc_t *procp = NULL;
126     afs_int32 code;
127
128     if (ioctlp->ioctl.flags & CM_IOCTLFLAG_DATAIN) {
129         ioctlp->ioctl.flags &= ~CM_IOCTLFLAG_DATAIN;
130
131         /* do the call now, or fail if we didn't get an opcode, or
132          * enough of an opcode.
133          */
134         if (ioctlp->ioctl.inCopied < sizeof(afs_int32)) 
135             return CM_ERROR_INVAL;
136         memcpy(&opcode, ioctlp->ioctl.inDatap, sizeof(afs_int32));
137         ioctlp->ioctl.inDatap += sizeof(afs_int32);
138
139         osi_Log1(afsd_logp, "Ioctl opcode 0x%x", opcode);
140
141         /* check for opcode out of bounds */
142         if (opcode < 0 || opcode >= SMB_IOCTL_MAXPROCS)
143             return CM_ERROR_TOOBIG;
144
145         /* check for no such proc */
146         procp = smb_ioctlProcsp[opcode];
147         if (procp == NULL) 
148             return CM_ERROR_BADOP;
149
150         /* otherwise, make the call */
151         ioctlp->ioctl.outDatap += sizeof(afs_int32); /* reserve room for return code */
152         code = (*procp)(ioctlp, userp);
153
154         osi_Log1(afsd_logp, "Ioctl return code 0x%x", code);
155
156         /* copy in return code */
157         memcpy(ioctlp->ioctl.outAllocp, &code, sizeof(afs_int32));
158     }
159     return 0;
160 }
161
162 /* called when we receive a write call.  If this is the first write call after
163  * a series of reads (or the very first call), then we start a new call.
164  * We also ensure that things are properly initialized for the start of a call.
165  */
166 void 
167 smb_IoctlPrepareWrite(smb_fid_t *fidp, smb_ioctl_t *ioctlp)
168 {
169     /* make sure the buffer(s) are allocated */
170     if (!ioctlp->ioctl.inAllocp) 
171         ioctlp->ioctl.inAllocp = malloc(SMB_IOCTL_MAXDATA);
172     if (!ioctlp->ioctl.outAllocp)
173         ioctlp->ioctl.outAllocp = malloc(SMB_IOCTL_MAXDATA);
174
175     /* Fixes fs la problem.  We do a StrToOEM later and if this data isn't initialized we get memory issues. */
176     (void) memset(ioctlp->ioctl.inAllocp, 0, SMB_IOCTL_MAXDATA);
177     (void) memset(ioctlp->ioctl.outAllocp, 0, SMB_IOCTL_MAXDATA);
178
179     /* and make sure that we've reset our state for the new incoming request */
180     if (!(ioctlp->ioctl.flags & CM_IOCTLFLAG_DATAIN)) {
181         ioctlp->ioctl.inCopied = 0;
182         ioctlp->ioctl.outCopied = 0;
183         ioctlp->ioctl.inDatap = ioctlp->ioctl.inAllocp;
184         ioctlp->ioctl.outDatap = ioctlp->ioctl.outAllocp;
185         ioctlp->ioctl.flags |= CM_IOCTLFLAG_DATAIN;
186     }
187 }       
188
189 /* called from smb_ReceiveCoreRead when we receive a read on the ioctl fid */
190 afs_int32
191 smb_IoctlRead(smb_fid_t *fidp, smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp)
192 {
193     smb_ioctl_t *iop;
194     long count;
195     afs_int32 leftToCopy;
196     char *op;
197     afs_int32 code;
198     cm_user_t *userp;
199
200     iop = fidp->ioctlp;
201     count = smb_GetSMBParm(inp, 1);
202     userp = smb_GetUserFromVCP(vcp, inp);
203
204     /* Identify tree */
205     code = smb_LookupTIDPath(vcp, ((smb_t *)inp)->tid, &iop->tidPathp);
206     if(code) {
207         cm_ReleaseUser(userp);
208         return CM_ERROR_NOSUCHPATH;
209     }
210
211     /* turn the connection around, if required */
212     code = smb_IoctlPrepareRead(fidp, iop, userp);
213
214     if (code) {
215         cm_ReleaseUser(userp);
216         return code;
217     }
218
219     leftToCopy = (afs_int32)((iop->ioctl.outDatap - iop->ioctl.outAllocp) - iop->ioctl.outCopied);
220     if (count > leftToCopy)
221         count = leftToCopy;
222
223     /* now set the parms for a read of count bytes */
224     smb_SetSMBParm(outp, 0, count);
225     smb_SetSMBParm(outp, 1, 0);
226     smb_SetSMBParm(outp, 2, 0);
227     smb_SetSMBParm(outp, 3, 0);
228     smb_SetSMBParm(outp, 4, 0);
229
230     smb_SetSMBDataLength(outp, count+3);
231
232     op = smb_GetSMBData(outp, NULL);
233     *op++ = 1;
234     *op++ = (char)(count & 0xff);
235     *op++ = (char)((count >> 8) & 0xff);
236
237     /* now copy the data into the response packet */
238     memcpy(op, iop->ioctl.outCopied + iop->ioctl.outAllocp, count);
239
240     /* and adjust the counters */
241     iop->ioctl.outCopied += count;
242
243     cm_ReleaseUser(userp);
244
245     return 0;
246 }
247
248 /* called from smb_ReceiveCoreWrite when we receive a write call on the IOCTL
249  * file descriptor.
250  */
251 afs_int32
252 smb_IoctlWrite(smb_fid_t *fidp, smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp)
253 {
254     smb_ioctl_t *iop;
255     long count;
256     afs_int32 code;
257     char *op;
258     int inDataBlockCount;
259
260     code = 0;
261     count = smb_GetSMBParm(inp, 1);
262     iop = fidp->ioctlp;
263         
264     smb_IoctlPrepareWrite(fidp, iop);
265
266     op = smb_GetSMBData(inp, NULL);
267     op = smb_ParseDataBlock(op, NULL, &inDataBlockCount);
268         
269     if (count + iop->ioctl.inCopied > SMB_IOCTL_MAXDATA) {
270         code = CM_ERROR_TOOBIG;
271         goto done;
272     }
273         
274     /* copy data */
275     memcpy(iop->ioctl.inDatap + iop->ioctl.inCopied, op, count);
276         
277     /* adjust counts */
278     iop->ioctl.inCopied += count;
279
280   done:
281     /* return # of bytes written */
282     if (code == 0) {
283         smb_SetSMBParm(outp, 0, count);
284         smb_SetSMBDataLength(outp, 0);
285     }
286
287     return code;
288 }       
289
290 /* called from smb_ReceiveV3WriteX when we receive a write call on the IOCTL
291  * file descriptor.
292  */
293 afs_int32
294 smb_IoctlV3Write(smb_fid_t *fidp, smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp)
295 {
296     smb_ioctl_t *iop;
297     long count;
298     afs_int32 code;
299     char *op;
300     int inDataBlockCount;
301
302     code = 0;
303     count = smb_GetSMBParm(inp, 10);
304     iop = fidp->ioctlp;
305
306     smb_IoctlPrepareWrite(fidp, iop);
307
308     op = inp->data + smb_GetSMBParm(inp, 11);
309     inDataBlockCount = count;
310
311     if (count + iop->ioctl.inCopied > SMB_IOCTL_MAXDATA) {
312         code = CM_ERROR_TOOBIG;
313         goto done;
314     }
315         
316     /* copy data */
317     memcpy(iop->ioctl.inDatap + iop->ioctl.inCopied, op, count);
318
319     /* adjust counts */
320     iop->ioctl.inCopied += count;
321
322   done:
323     /* return # of bytes written */
324     if (code == 0) {
325         smb_SetSMBParm(outp, 2, count);
326         smb_SetSMBParm(outp, 3, 0); /* reserved */
327         smb_SetSMBParm(outp, 4, 0); /* reserved */
328         smb_SetSMBParm(outp, 5, 0); /* reserved */
329         smb_SetSMBDataLength(outp, 0);
330     }
331
332     return code;
333 }       
334
335
336 /* called from V3 read to handle IOCTL descriptor reads */
337 afs_int32
338 smb_IoctlV3Read(smb_fid_t *fidp, smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp)
339 {
340     smb_ioctl_t *iop;
341     long count;
342     afs_int32 code;
343     long leftToCopy;
344     char *op;
345     cm_user_t *userp;
346     smb_user_t *uidp;
347
348     iop = fidp->ioctlp;
349     count = smb_GetSMBParm(inp, 5);
350         
351     uidp = smb_FindUID(vcp, ((smb_t *)inp)->uid, 0);
352     userp = smb_GetUserFromUID(uidp);
353     osi_assertx(userp != NULL, "null cm_user_t");
354     iop->uidp = uidp;
355     if (uidp && uidp->unp) {
356         osi_Log3(afsd_logp, "Ioctl uid %d user %x name %S",
357                   uidp->userID, userp,
358                   osi_LogSaveClientString(afsd_logp, uidp->unp->name));
359     } else {
360         if (uidp)
361             osi_Log2(afsd_logp, "Ioctl uid %d user %x no name",
362                      uidp->userID, userp);
363         else
364             osi_Log1(afsd_logp, "Ioctl no uid user %x no name",
365                      userp);
366     }
367
368     code = smb_LookupTIDPath(vcp, ((smb_t *)inp)->tid, &iop->tidPathp);
369     if (code) {
370         if (uidp)
371             smb_ReleaseUID(uidp);
372         cm_ReleaseUser(userp);
373         return CM_ERROR_NOSUCHPATH;
374     }
375
376     code = smb_IoctlPrepareRead(fidp, iop, userp);
377     if (uidp) {
378         iop->uidp = 0;
379         smb_ReleaseUID(uidp);
380     }
381     if (code) {
382         cm_ReleaseUser(userp);
383         return code;
384     }
385
386     leftToCopy = (long)((iop->ioctl.outDatap - iop->ioctl.outAllocp) - iop->ioctl.outCopied);
387     if (count > leftToCopy) 
388         count = leftToCopy;
389         
390     /* 0 and 1 are reserved for request chaining, were setup by our caller,
391      * and will be further filled in after we return.
392      */
393     smb_SetSMBParm(outp, 2, 0); /* remaining bytes, for pipes */
394     smb_SetSMBParm(outp, 3, 0); /* resvd */
395     smb_SetSMBParm(outp, 4, 0); /* resvd */
396     smb_SetSMBParm(outp, 5, count);     /* # of bytes we're going to read */
397     /* fill in #6 when we have all the parameters' space reserved */
398     smb_SetSMBParm(outp, 7, 0); /* resv'd */
399     smb_SetSMBParm(outp, 8, 0); /* resv'd */
400     smb_SetSMBParm(outp, 9, 0); /* resv'd */
401     smb_SetSMBParm(outp, 10, 0);        /* resv'd */
402     smb_SetSMBParm(outp, 11, 0);        /* reserved */
403
404     /* get op ptr after putting in the last parm, since otherwise we don't
405      * know where the data really is.
406      */
407     op = smb_GetSMBData(outp, NULL);
408         
409     /* now fill in offset from start of SMB header to first data byte (to op) */
410     smb_SetSMBParm(outp, 6, ((int) (op - outp->data)));
411
412     /* set the packet data length the count of the # of bytes */
413     smb_SetSMBDataLength(outp, count);
414         
415     /* now copy the data into the response packet */
416     memcpy(op, iop->ioctl.outCopied + iop->ioctl.outAllocp, count);
417
418     /* and adjust the counters */
419     iop->ioctl.outCopied += count;
420
421     /* and cleanup things */
422     cm_ReleaseUser(userp);
423
424     return 0;
425 }       
426
427 /* called from Read Raw to handle IOCTL descriptor reads */
428 afs_int32
429 smb_IoctlReadRaw(smb_fid_t *fidp, smb_vc_t *vcp, smb_packet_t *inp,
430                  smb_packet_t *outp)
431 {
432     smb_ioctl_t *iop;
433     long leftToCopy;
434     NCB *ncbp;
435     afs_int32 code;
436     cm_user_t *userp;
437     smb_user_t *uidp;
438
439     iop = fidp->ioctlp;
440
441     userp = smb_GetUserFromVCP(vcp, inp);
442
443     /* Log the user */
444     uidp = smb_FindUID(vcp, ((smb_t *)inp)->uid, 0);
445     if (uidp && uidp->unp) {
446         osi_Log3(afsd_logp, "Ioctl uid %d user %x name %s",
447                  uidp->userID, userp,
448                  osi_LogSaveClientString(afsd_logp, uidp->unp->name));
449     } else if (uidp) {
450         osi_Log2(afsd_logp, "Ioctl uid %d user %x no name",
451                  uidp->userID, userp);
452     } else {
453         osi_Log1(afsd_logp, "Ioctl no uid user %x no name",
454                   userp);
455     }
456     if (uidp) 
457         smb_ReleaseUID(uidp);
458
459     code = smb_LookupTIDPath(vcp, ((smb_t *)inp)->tid, &iop->tidPathp);
460     if (code) {
461         code = CM_ERROR_NOSUCHPATH;
462         goto done;
463     }
464
465     code = smb_IoctlPrepareRead(fidp, iop, userp);
466     if (code) {
467         goto done;
468     }
469
470     leftToCopy = (long)((iop->ioctl.outDatap - iop->ioctl.outAllocp) - iop->ioctl.outCopied);
471
472     ncbp = outp->ncbp;
473     memset((char *)ncbp, 0, sizeof(NCB));
474
475     ncbp->ncb_length = (unsigned short) leftToCopy;
476     ncbp->ncb_lsn = (unsigned char) vcp->lsn;
477     ncbp->ncb_command = NCBSEND;
478     /*ncbp->ncb_lana_num = smb_LANadapter;*/
479     ncbp->ncb_lana_num = vcp->lana;
480
481     ncbp->ncb_buffer = iop->ioctl.outCopied + iop->ioctl.outAllocp;
482     code = Netbios(ncbp);
483
484     if (code != 0)
485         osi_Log1(afsd_logp, "ReadRaw send failure code %d", code);
486
487   done:
488     cm_ReleaseUser(userp);
489
490     return code;
491 }
492
493 /* parse the passed-in file name and do a namei on it.  If we fail,
494  * return an error code, otherwise return the vnode located in *scpp.
495  */
496 #define CM_PARSE_FLAG_LITERAL 1
497
498 afs_int32
499 smb_ParseIoctlPath(smb_ioctl_t *ioctlp, cm_user_t *userp, cm_req_t *reqp,
500                    cm_scache_t **scpp, afs_uint32 flags)
501 {
502     long code;
503     cm_scache_t  *substRootp = NULL;
504     cm_scache_t  *iscp = NULL;
505     char      *inPath;
506     clientchar_t *relativePath = NULL;
507     clientchar_t *lastComponent = NULL;
508     afs_uint32 follow = (flags & CM_PARSE_FLAG_LITERAL ? CM_FLAG_NOMOUNTCHASE : CM_FLAG_FOLLOW);
509
510     inPath = ioctlp->ioctl.inDatap;
511     /* setup the next data value for the caller to use */
512     ioctlp->ioctl.inDatap += (long)strlen(ioctlp->ioctl.inDatap) + 1;
513
514     osi_Log1(afsd_logp, "cm_ParseIoctlPath %s", osi_LogSaveString(afsd_logp,inPath));
515
516     /* This is usually the file name, but for StatMountPoint it is the path. */
517     /* ioctlp->ioctl.inDatap can be either of the form:
518      *    \path\.
519      *    \path\file
520      *    \\netbios-name\submount\path\.
521      *    \\netbios-name\submount\path\file
522      */
523
524     /* We do not perform path name translation on the ioctl path data
525      * because these paths were not translated by Windows through the
526      * file system API.  Therefore, they are not OEM characters but
527      * whatever the display character set is.
528      */
529
530     // TranslateExtendedChars(relativePath);
531
532     /* This is usually nothing, but for StatMountPoint it is the file name. */
533     // TranslateExtendedChars(ioctlp->ioctl.inDatap);
534
535     /* If the string starts with our UTF-8 prefix (which is the
536        sequence [ESC,'%','G'] as used by ISO-2022 to designate UTF-8
537        strings), we assume that the provided path is UTF-8.  Otherwise
538        we have to convert the string to UTF-8, since that is what we
539        want to use everywhere else.*/
540
541     if (memcmp(inPath, utf8_prefix, utf8_prefix_size) == 0) {
542         /* String is UTF-8 */
543         inPath += utf8_prefix_size;
544         ioctlp->ioctl.flags |= CM_IOCTLFLAG_USEUTF8;
545
546         relativePath = cm_Utf8ToClientStringAlloc(inPath, -1, NULL);
547     } else {
548         int cch;
549
550         /* Not a UTF-8 string */
551         /* TODO: If this is an OEM string, we should convert it to
552            UTF-8. */
553         if (smb_StoreAnsiFilenames) {
554             cch = cm_AnsiToClientString(inPath, -1, NULL, 0);
555 #ifdef DEBUG
556             osi_assert(cch > 0);
557 #endif
558             relativePath = malloc(cch * sizeof(clientchar_t));
559             cm_AnsiToClientString(inPath, -1, relativePath, cch);
560         } else {
561             TranslateExtendedChars(inPath);
562
563             cch = cm_OemToClientString(inPath, -1, NULL, 0);
564 #ifdef DEBUG
565             osi_assert(cch > 0);
566 #endif
567             relativePath = malloc(cch * sizeof(clientchar_t));
568             cm_OemToClientString(inPath, -1, relativePath, cch);
569         }
570     }
571
572     if (relativePath[0] == relativePath[1] &&
573         relativePath[1] == '\\' && 
574         !cm_ClientStrCmpNI(cm_NetbiosNameC, relativePath+2,
575                            cm_ClientStrLen(cm_NetbiosNameC))) 
576     {
577         clientchar_t shareName[256];
578         clientchar_t *sharePath;
579         int shareFound, i;
580
581         /* We may have found a UNC path. 
582          * If the first component is the NetbiosName,
583          * then throw out the second component (the submount)
584          * since it had better expand into the value of ioctl->tidPathp
585          */
586         clientchar_t * p;
587         p = relativePath + 2 + cm_ClientStrLen(cm_NetbiosNameC) + 1;                    /* buffer overflow vuln.? */
588         if ( !cm_ClientStrCmpNI(_C("all"),  p,  3) )
589             p += 4;
590
591         for (i = 0; *p && *p != '\\'; i++,p++ ) {
592             shareName[i] = *p;
593         }
594         p++;                    /* skip past trailing slash */
595         shareName[i] = 0;       /* terminate string */
596
597         shareFound = smb_FindShare(ioctlp->fidp->vcp, ioctlp->uidp, shareName, &sharePath);
598         if ( shareFound ) {
599             /* we found a sharename, therefore use the resulting path */
600             code = cm_NameI(cm_data.rootSCachep, ioctlp->prefix->wdata,
601                             CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
602                             userp, sharePath, reqp, &substRootp);
603             free(sharePath);
604             if (code) {
605                 osi_Log1(afsd_logp,"cm_ParseIoctlPath [1] code 0x%x", code);
606                 if (relativePath)
607                     free(relativePath);
608                 return code;
609             }
610
611             lastComponent = cm_ClientStrRChr(p,  '\\');
612             if (lastComponent && (lastComponent - p) > 1 &&
613                 cm_ClientStrLen(lastComponent) > 1) {
614                 *lastComponent = '\0';
615                 lastComponent++;
616
617                 code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
618                                 userp, NULL, reqp, &iscp);
619                 if (code == 0)
620                     code = cm_NameI(iscp, lastComponent, CM_FLAG_CASEFOLD | follow,
621                                     userp, NULL, reqp, scpp);
622                 if (iscp)
623                     cm_ReleaseSCache(iscp);
624             } else {
625                 code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD,
626                                 userp, NULL, reqp, scpp);
627             }
628             cm_ReleaseSCache(substRootp);
629             if (code) {
630                 osi_Log1(afsd_logp,"cm_ParseIoctlPath [2] code 0x%x", code);
631                 if (relativePath)
632                     free(relativePath);
633                 return code;
634             }
635         } else {
636             /* otherwise, treat the name as a cellname mounted off the afs root.
637              * This requires that we reconstruct the shareName string with 
638              * leading and trailing slashes.
639              */
640             p = relativePath + 2 + cm_ClientStrLen(cm_NetbiosNameC) + 1;
641             if ( !cm_ClientStrCmpNI(_C("all"),  p,  3) )
642                 p += 4;
643
644             shareName[0] = '/';
645             for (i = 1; *p && *p != '\\'; i++,p++ ) {
646                 shareName[i] = *p;
647             }
648             p++;                    /* skip past trailing slash */
649             shareName[i++] = '/';       /* add trailing slash */
650             shareName[i] = 0;       /* terminate string */
651
652
653             code = cm_NameI(cm_data.rootSCachep, ioctlp->prefix->wdata,
654                             CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
655                             userp, shareName, reqp, &substRootp);
656             if (code) {
657                 osi_Log1(afsd_logp,"cm_ParseIoctlPath [3] code 0x%x", code);
658                 if (relativePath)
659                     free(relativePath);
660                 return code;
661             }
662
663             lastComponent = cm_ClientStrRChr(p,  '\\');
664             if (lastComponent && (lastComponent - p) > 1 &&
665                 cm_ClientStrLen(lastComponent) > 1) {
666                 *lastComponent = '\0';
667                 lastComponent++;
668
669                 code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
670                                 userp, NULL, reqp, &iscp);
671                 if (code == 0)
672                     code = cm_NameI(iscp, lastComponent, CM_FLAG_CASEFOLD | follow,
673                                     userp, NULL, reqp, scpp);
674                 if (iscp)
675                     cm_ReleaseSCache(iscp);
676             } else {
677                 code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD,
678                                 userp, NULL, reqp, scpp);
679             }
680
681             if (code) {
682                 cm_ReleaseSCache(substRootp);
683                 osi_Log1(afsd_logp,"cm_ParseIoctlPath code [4] 0x%x", code);
684                 if (relativePath)
685                     free(relativePath);
686                 return code;
687             }
688         }
689     } else {
690         code = cm_NameI(cm_data.rootSCachep, ioctlp->prefix->wdata,
691                          CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
692                          userp, ioctlp->tidPathp, reqp, &substRootp);
693         if (code) {
694             osi_Log1(afsd_logp,"cm_ParseIoctlPath [6] code 0x%x", code);
695             if (relativePath)
696                 free(relativePath);
697             return code;
698         }
699         
700         lastComponent = cm_ClientStrRChr(relativePath,  '\\');
701         if (lastComponent && (lastComponent - relativePath) > 1 &&
702             cm_ClientStrLen(lastComponent) > 1) {
703             *lastComponent = '\0';
704             lastComponent++;
705
706             code = cm_NameI(substRootp, relativePath, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
707                             userp, NULL, reqp, &iscp);
708             if (code == 0)
709                 code = cm_NameI(iscp, lastComponent, CM_FLAG_CASEFOLD | follow,
710                                 userp, NULL, reqp, scpp);
711             if (iscp)
712                 cm_ReleaseSCache(iscp);
713         } else {
714             code = cm_NameI(substRootp, relativePath, CM_FLAG_CASEFOLD | follow,
715                             userp, NULL, reqp, scpp);
716         }
717         if (code) {
718             cm_ReleaseSCache(substRootp);
719             osi_Log1(afsd_logp,"cm_ParseIoctlPath [7] code 0x%x", code);
720             if (relativePath)
721                 free(relativePath);
722             return code;
723         }
724     }
725
726     if (substRootp)
727         cm_ReleaseSCache(substRootp);
728
729     /* and return success */
730     osi_Log1(afsd_logp,"cm_ParseIoctlPath [8] code 0x%x", code);
731
732     if (relativePath)
733         free(relativePath);
734     return 0;
735 }
736
737
738
739 #define LEAF_SIZE 256
740 /* parse the passed-in file name and do a namei on its parent.  If we fail,
741  * return an error code, otherwise return the vnode located in *scpp.
742  */
743 afs_int32
744 smb_ParseIoctlParent(smb_ioctl_t *ioctlp, cm_user_t *userp, cm_req_t *reqp,
745                      cm_scache_t **scpp, clientchar_t *leafp)
746 {
747     long code;
748     clientchar_t tbuffer[1024];
749     clientchar_t *tp, *jp;
750     cm_scache_t *substRootp = NULL;
751     clientchar_t *inpathp = NULL;
752     char *inpathdatap;
753
754     inpathdatap = ioctlp->ioctl.inDatap;
755
756     /* If the string starts with our UTF-8 prefix (which is the
757        sequence [ESC,'%','G'] as used by ISO-2022 to designate UTF-8
758        strings), we assume that the provided path is UTF-8.  Otherwise
759        we have to convert the string to UTF-8, since that is what we
760        want to use everywhere else.*/
761
762     if (memcmp(inpathdatap, utf8_prefix, utf8_prefix_size) == 0) {
763
764         /* String is UTF-8 */
765         inpathdatap += utf8_prefix_size;
766         ioctlp->ioctl.flags |= CM_IOCTLFLAG_USEUTF8;
767
768         inpathp = cm_Utf8ToClientStringAlloc(inpathdatap, -1, NULL);
769     } else {
770         int cch;
771
772         /* Not a UTF-8 string */
773         /* TODO: If this is an OEM string, we should convert it to
774            UTF-8. */
775         if (smb_StoreAnsiFilenames) {
776             cch = cm_AnsiToClientString(inpathdatap, -1, NULL, 0);
777 #ifdef DEBUG
778             osi_assert(cch > 0);
779 #endif
780             inpathp = malloc(cch * sizeof(clientchar_t));
781             cm_AnsiToClientString(inpathdatap, -1, inpathp, cch);
782         } else {
783             TranslateExtendedChars(inpathdatap);
784
785             cch = cm_OemToClientString(inpathdatap, -1, NULL, 0);
786 #ifdef DEBUG
787             osi_assert(cch > 0);
788 #endif
789             inpathp = malloc(cch * sizeof(clientchar_t));
790             cm_OemToClientString(inpathdatap, -1, inpathp, cch);
791         }
792     }
793
794     cm_ClientStrCpy(tbuffer, lengthof(tbuffer), inpathp);
795     tp = cm_ClientStrRChr(tbuffer, '\\');
796     jp = cm_ClientStrRChr(tbuffer, '/');
797     if (!tp)
798         tp = jp;
799     else if (jp && (tp - tbuffer) < (jp - tbuffer))
800         tp = jp;
801     if (!tp) {
802         cm_ClientStrCpy(tbuffer, lengthof(tbuffer), _C("\\"));
803         if (leafp)
804             cm_ClientStrCpy(leafp, LEAF_SIZE, inpathp);
805     }
806     else {
807         *tp = 0;
808         if (leafp) 
809             cm_ClientStrCpy(leafp, LEAF_SIZE, tp+1);
810     }
811
812     free(inpathp);
813     inpathp = NULL;             /* We don't need this from this point on */
814
815     if (tbuffer[0] == tbuffer[1] &&
816         tbuffer[1] == '\\' && 
817         !cm_ClientStrCmpNI(cm_NetbiosNameC, tbuffer+2,
818                            cm_ClientStrLen(cm_NetbiosNameC))) 
819     {
820         clientchar_t shareName[256];
821         clientchar_t *sharePath;
822         int shareFound, i;
823
824         /* We may have found a UNC path. 
825          * If the first component is the NetbiosName,
826          * then throw out the second component (the submount)
827          * since it had better expand into the value of ioctl->tidPathp
828          */
829         clientchar_t * p;
830         p = tbuffer + 2 + cm_ClientStrLen(cm_NetbiosNameC) + 1;
831         if ( !cm_ClientStrCmpNI(_C("all"),  p,  3) )
832             p += 4;
833
834         for (i = 0; *p && *p != '\\'; i++,p++ ) {
835             shareName[i] = *p;
836         }
837         p++;                    /* skip past trailing slash */
838         shareName[i] = 0;       /* terminate string */
839
840         shareFound = smb_FindShare(ioctlp->fidp->vcp, ioctlp->uidp, shareName, &sharePath);
841         if ( shareFound ) {
842             /* we found a sharename, therefore use the resulting path */
843             code = cm_NameI(cm_data.rootSCachep, ioctlp->prefix->wdata,
844                             CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
845                             userp, sharePath, reqp, &substRootp);
846             free(sharePath);
847             if (code) return code;
848
849             code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
850                             userp, NULL, reqp, scpp);
851             cm_ReleaseSCache(substRootp);
852             if (code) return code;
853         } else {
854             /* otherwise, treat the name as a cellname mounted off the afs root.
855              * This requires that we reconstruct the shareName string with 
856              * leading and trailing slashes.
857              */
858             p = tbuffer + 2 + cm_ClientStrLen(cm_NetbiosNameC) + 1;
859             if ( !cm_ClientStrCmpNI(_C("all"),  p,  3) )
860                 p += 4;
861
862             shareName[0] = '/';
863             for (i = 1; *p && *p != '\\'; i++,p++ ) {
864                 shareName[i] = *p;
865             }
866             p++;                    /* skip past trailing slash */
867             shareName[i++] = '/';       /* add trailing slash */
868             shareName[i] = 0;       /* terminate string */
869
870             code = cm_NameI(cm_data.rootSCachep, ioctlp->prefix->wdata,
871                             CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
872                             userp, shareName, reqp, &substRootp);
873             if (code) return code;
874
875             code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
876                             userp, NULL, reqp, scpp);
877             cm_ReleaseSCache(substRootp);
878             if (code) return code;
879         }
880     } else {
881         code = cm_NameI(cm_data.rootSCachep, ioctlp->prefix->wdata,
882                         CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
883                         userp, ioctlp->tidPathp, reqp, &substRootp);
884         if (code) return code;
885
886         code = cm_NameI(substRootp, tbuffer, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
887                         userp, NULL, reqp, scpp);
888         cm_ReleaseSCache(substRootp);
889         if (code) return code;
890     }
891
892     /* # of bytes of path */
893     code = (long)strlen(ioctlp->ioctl.inDatap) + 1;
894     ioctlp->ioctl.inDatap += code;
895
896     /* and return success */
897     return 0;
898 }
899
900 afs_int32 
901 smb_IoctlSetToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
902 {
903     char *saveDataPtr;
904     char *tp;
905     int ticketLen;
906     char *ticket;
907     int ctSize;
908     struct ClearToken ct;
909     cm_cell_t *cellp;
910     cm_ucell_t *ucellp;
911     afs_uuid_t uuid;
912     int flags;
913     char sessionKey[8];
914     int release_userp = 0;
915     clientchar_t *uname = NULL;
916     clientchar_t *smbname = NULL;
917     clientchar_t *wdir = NULL;
918     afs_int32 code = 0;
919
920     saveDataPtr = ioctlp->ioctl.inDatap;
921
922     cm_SkipIoctlPath(&ioctlp->ioctl);
923
924     tp = ioctlp->ioctl.inDatap;
925
926     /* ticket length */
927     memcpy(&ticketLen, tp, sizeof(ticketLen));
928     tp += sizeof(ticketLen);
929     if (ticketLen < MINKTCTICKETLEN || ticketLen > MAXKTCTICKETLEN)
930         return CM_ERROR_INVAL;
931
932     /* remember ticket and skip over it for now */
933     ticket = tp;
934     tp += ticketLen;
935
936     /* clear token size */
937     memcpy(&ctSize, tp, sizeof(ctSize));
938     tp += sizeof(ctSize);
939     if (ctSize != sizeof(struct ClearToken))
940         return CM_ERROR_INVAL;
941
942     /* clear token */
943     memcpy(&ct, tp, ctSize);
944     tp += ctSize;
945     if (ct.AuthHandle == -1)
946         ct.AuthHandle = 999;    /* more rxvab compat stuff */
947
948     /* more stuff, if any */
949     if (ioctlp->ioctl.inCopied > tp - saveDataPtr) {
950         /* flags:  logon flag */
951         memcpy(&flags, tp, sizeof(int));
952         tp += sizeof(int);
953
954         /* cell name */
955         {
956             fschar_t * cellnamep;
957             clientchar_t * temp;
958
959             temp = cm_ParseIoctlStringAlloc(&ioctlp->ioctl, tp);
960             cellnamep = cm_ClientStringToFsStringAlloc(temp, -1, NULL);
961             cellp = cm_GetCell(cellnamep, CM_FLAG_CREATE | CM_FLAG_NOPROBE);
962             free(cellnamep);
963             free(temp);
964         }
965
966         if (!cellp) {
967             code = CM_ERROR_NOSUCHCELL;
968             goto done;
969         }
970         tp += strlen(tp) + 1;
971
972         /* user name */
973         uname = cm_ParseIoctlStringAlloc(&ioctlp->ioctl, tp);
974         tp += strlen(tp) + 1;
975
976         if (flags & PIOCTL_LOGON) {
977             /* SMB user name with which to associate tokens */
978             smbname = cm_ParseIoctlStringAlloc(&ioctlp->ioctl, tp);
979             osi_Log2(smb_logp,"cm_IoctlSetToken for user [%S] smbname [%S]",
980                      osi_LogSaveClientString(smb_logp,uname),
981                      osi_LogSaveClientString(smb_logp,smbname));
982             fprintf(stderr, "SMB name = %S\n", smbname);
983             tp += strlen(tp) + 1;
984         } else {
985             osi_Log1(smb_logp,"cm_IoctlSetToken for user [%S]",
986                      osi_LogSaveClientString(smb_logp, uname));
987         }
988
989         /* uuid */
990         memcpy(&uuid, tp, sizeof(uuid));
991         if (!cm_FindTokenEvent(uuid, sessionKey)) {
992             code = CM_ERROR_INVAL;
993             goto done;
994         }
995     } else {
996         cellp = cm_data.rootCellp;
997         osi_Log0(smb_logp,"cm_IoctlSetToken - no name specified");
998     }
999
1000     if (flags & PIOCTL_LOGON) {
1001         userp = smb_FindCMUserByName(smbname, ioctlp->fidp->vcp->rname,
1002                                      SMB_FLAG_CREATE|SMB_FLAG_AFSLOGON);
1003         release_userp = 1;
1004     }
1005
1006     /* store the token */
1007     lock_ObtainMutex(&userp->mx);
1008     ucellp = cm_GetUCell(userp, cellp);
1009     osi_Log1(smb_logp,"cm_IoctlSetToken ucellp %lx", ucellp);
1010     ucellp->ticketLen = ticketLen;
1011     if (ucellp->ticketp)
1012         free(ucellp->ticketp);  /* Discard old token if any */
1013     ucellp->ticketp = malloc(ticketLen);
1014     memcpy(ucellp->ticketp, ticket, ticketLen);
1015     /*
1016      * Get the session key from the RPC, rather than from the pioctl.
1017      */
1018     /*
1019     memcpy(&ucellp->sessionKey, ct.HandShakeKey, sizeof(ct.HandShakeKey));
1020     */
1021     memcpy(ucellp->sessionKey.data, sessionKey, sizeof(sessionKey));
1022     ucellp->kvno = ct.AuthHandle;
1023     ucellp->expirationTime = ct.EndTimestamp;
1024     ucellp->gen++;
1025 #ifdef QUERY_AFSID
1026     ucellp->uid = ANONYMOUSID;
1027 #endif
1028     if (uname) {
1029         cm_ClientStringToFsString(uname, -1, ucellp->userName, MAXKTCNAMELEN);
1030 #ifdef QUERY_AFSID
1031         cm_UsernameToId(uname, ucellp, &ucellp->uid);
1032 #endif
1033     }
1034     ucellp->flags |= CM_UCELLFLAG_RXKAD;
1035     lock_ReleaseMutex(&userp->mx);
1036
1037     if (flags & PIOCTL_LOGON) {
1038         ioctlp->ioctl.flags |= CM_IOCTLFLAG_LOGON;
1039     }
1040
1041     cm_ResetACLCache(userp);
1042
1043   done:
1044     if (release_userp)
1045         cm_ReleaseUser(userp);
1046
1047     if (uname)
1048         free(uname);
1049
1050     if (smbname)
1051         free(smbname);
1052
1053     return code;
1054 }
1055
1056
1057
1058 afs_int32
1059 smb_IoctlGetSMBName(smb_ioctl_t *ioctlp, cm_user_t *userp)
1060 {
1061     smb_user_t *uidp = ioctlp->uidp;
1062
1063     if (uidp && uidp->unp) {
1064         int cch;
1065
1066         cch = cm_ClientStringToUtf8(uidp->unp->name,
1067                                     cm_ClientStrLen(uidp->unp->name),
1068
1069                                     ioctlp->ioctl.outDatap,
1070                                     (SMB_IOCTL_MAXDATA -
1071                                      (ioctlp->ioctl.outDatap - ioctlp->ioctl.outAllocp))
1072                                     / sizeof(cm_utf8char_t));
1073
1074         ioctlp->ioctl.outDatap += cch * sizeof(cm_utf8char_t);
1075     }
1076
1077     return 0;
1078 }
1079
1080 afs_int32 
1081 smb_IoctlGetACL(smb_ioctl_t *ioctlp, cm_user_t *userp)
1082 {
1083     cm_scache_t *scp;
1084     afs_int32 code;
1085     cm_req_t req;
1086     cm_ioctlQueryOptions_t *optionsp;
1087     afs_uint32 flags = 0;
1088
1089     cm_InitReq(&req);
1090
1091     optionsp = cm_IoctlGetQueryOptions(&ioctlp->ioctl, userp);
1092     if (optionsp && CM_IOCTL_QOPTS_HAVE_LITERAL(optionsp))
1093         flags |= (optionsp->literal ? CM_PARSE_FLAG_LITERAL : 0);
1094
1095     if (optionsp && CM_IOCTL_QOPTS_HAVE_FID(optionsp)) {
1096         cm_fid_t fid;
1097         cm_SkipIoctlPath(&ioctlp->ioctl);
1098         cm_SetFid(&fid, optionsp->fid.cell, optionsp->fid.volume, 
1099                   optionsp->fid.vnode, optionsp->fid.unique);
1100         code = cm_GetSCache(&fid, &scp, userp, &req);
1101     } else {
1102         code = smb_ParseIoctlPath(ioctlp, userp, &req, &scp, flags);
1103     }
1104     if (code) 
1105         return code;
1106
1107     code = cm_IoctlGetACL(&ioctlp->ioctl, userp, scp, &req);
1108
1109     cm_ReleaseSCache(scp);
1110     return code;
1111 }
1112
1113 afs_int32 
1114 smb_IoctlSetACL(smb_ioctl_t *ioctlp, cm_user_t *userp)
1115 {
1116     cm_scache_t *scp;
1117     afs_int32 code;
1118     cm_req_t req;
1119     cm_ioctlQueryOptions_t *optionsp;
1120     afs_uint32 flags = 0;
1121
1122     cm_InitReq(&req);
1123
1124     code = smb_ParseIoctlPath(ioctlp, userp, &req, &scp, flags);
1125     if (code) 
1126         return code;
1127
1128     code = cm_IoctlSetACL(&ioctlp->ioctl, userp, scp, &req);
1129
1130     cm_ReleaseSCache(scp);
1131     return code;
1132 }
1133
1134 afs_int32
1135 smb_IoctlGetFileCellName(struct smb_ioctl *ioctlp, struct cm_user *userp)
1136 {
1137     afs_int32 code;
1138     cm_scache_t *scp;
1139     cm_req_t req;
1140     cm_ioctlQueryOptions_t *optionsp;
1141     afs_uint32 flags = 0;
1142
1143     cm_InitReq(&req);
1144
1145     optionsp = cm_IoctlGetQueryOptions(&ioctlp->ioctl, userp);
1146     if (optionsp && CM_IOCTL_QOPTS_HAVE_LITERAL(optionsp))
1147         flags |= (optionsp->literal ? CM_PARSE_FLAG_LITERAL : 0);
1148
1149     if (optionsp && CM_IOCTL_QOPTS_HAVE_FID(optionsp)) {
1150         cm_fid_t fid;
1151         cm_SkipIoctlPath(&ioctlp->ioctl);
1152         cm_SetFid(&fid, optionsp->fid.cell, optionsp->fid.volume, 
1153                   optionsp->fid.vnode, optionsp->fid.unique);
1154         code = cm_GetSCache(&fid, &scp, userp, &req);
1155     } else {
1156         code = smb_ParseIoctlPath(ioctlp, userp, &req, &scp, flags);
1157     }
1158     if (code) 
1159         return code;
1160
1161     code = cm_IoctlGetFileCellName(&ioctlp->ioctl, userp, scp, &req);
1162
1163     cm_ReleaseSCache(scp);
1164
1165     return code;
1166 }
1167
1168 afs_int32 
1169 smb_IoctlFlushAllVolumes(struct smb_ioctl *ioctlp, struct cm_user *userp)
1170 {
1171     cm_req_t req;
1172
1173     cm_InitReq(&req);
1174
1175     cm_SkipIoctlPath(&ioctlp->ioctl);   /* we don't care about the path */
1176
1177     return cm_IoctlFlushAllVolumes(&ioctlp->ioctl, userp, &req);
1178 }
1179
1180 afs_int32 
1181 smb_IoctlFlushVolume(struct smb_ioctl *ioctlp, struct cm_user *userp)
1182 {
1183     afs_int32 code;
1184     cm_scache_t *scp;
1185     cm_req_t req;
1186     cm_ioctlQueryOptions_t *optionsp;
1187     afs_uint32 flags = 0;
1188
1189     cm_InitReq(&req);
1190
1191     optionsp = cm_IoctlGetQueryOptions(&ioctlp->ioctl, userp);
1192     if (optionsp && CM_IOCTL_QOPTS_HAVE_LITERAL(optionsp))
1193         flags |= (optionsp->literal ? CM_PARSE_FLAG_LITERAL : 0);
1194
1195     if (optionsp && CM_IOCTL_QOPTS_HAVE_FID(optionsp)) {
1196         cm_fid_t fid;
1197         cm_SkipIoctlPath(&ioctlp->ioctl);
1198         cm_SetFid(&fid, optionsp->fid.cell, optionsp->fid.volume, 
1199                   optionsp->fid.vnode, optionsp->fid.unique);
1200         code = cm_GetSCache(&fid, &scp, userp, &req);
1201     } else {
1202         code = smb_ParseIoctlPath(ioctlp, userp, &req, &scp, flags);
1203     }
1204     if (code) 
1205         return code;
1206
1207     code = cm_IoctlFlushVolume(&ioctlp->ioctl, userp, scp, &req);
1208
1209     cm_ReleaseSCache(scp);
1210
1211     return code;
1212 }
1213
1214 afs_int32 
1215 smb_IoctlFlushFile(struct smb_ioctl *ioctlp, struct cm_user *userp)
1216 {
1217     afs_int32 code;
1218     cm_scache_t *scp;
1219     cm_req_t req;
1220     cm_ioctlQueryOptions_t *optionsp;
1221     afs_uint32 flags = 0;
1222
1223     cm_InitReq(&req);
1224
1225     optionsp = cm_IoctlGetQueryOptions(&ioctlp->ioctl, userp);
1226     if (optionsp && CM_IOCTL_QOPTS_HAVE_LITERAL(optionsp))
1227         flags |= (optionsp->literal ? CM_PARSE_FLAG_LITERAL : 0);
1228
1229     if (optionsp && CM_IOCTL_QOPTS_HAVE_FID(optionsp)) {
1230         cm_fid_t fid;
1231         cm_SkipIoctlPath(&ioctlp->ioctl);
1232         cm_SetFid(&fid, optionsp->fid.cell, optionsp->fid.volume,
1233                   optionsp->fid.vnode, optionsp->fid.unique);
1234         code = cm_GetSCache(&fid, &scp, userp, &req);
1235     } else {
1236         code = smb_ParseIoctlPath(ioctlp, userp, &req, &scp, flags);
1237     }
1238     if (code) 
1239         return code;
1240
1241     code = cm_IoctlFlushFile(&ioctlp->ioctl, userp, scp, &req);
1242
1243     cm_ReleaseSCache(scp);
1244     return code;
1245 }
1246
1247 afs_int32 
1248 smb_IoctlSetVolumeStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
1249 {
1250     afs_int32 code;
1251     cm_scache_t *scp;
1252     cm_req_t req;
1253
1254     cm_InitReq(&req);
1255
1256     code = smb_ParseIoctlPath(ioctlp, userp, &req, &scp, 0);
1257     if (code) return code;
1258
1259     code = cm_IoctlSetVolumeStatus(&ioctlp->ioctl, userp, scp, &req);
1260     cm_ReleaseSCache(scp);
1261
1262     return code;
1263 }
1264
1265 afs_int32 
1266 smb_IoctlGetVolumeStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
1267 {
1268     afs_int32 code;
1269     cm_scache_t *scp;
1270     cm_ioctlQueryOptions_t *optionsp;
1271     afs_uint32 flags = 0;
1272     cm_req_t req;
1273
1274     cm_InitReq(&req);
1275
1276     optionsp = cm_IoctlGetQueryOptions(&ioctlp->ioctl, userp);
1277     if (optionsp && CM_IOCTL_QOPTS_HAVE_LITERAL(optionsp))
1278         flags |= (optionsp->literal ? CM_PARSE_FLAG_LITERAL : 0);
1279
1280     if (optionsp && CM_IOCTL_QOPTS_HAVE_FID(optionsp)) {
1281         cm_fid_t fid;
1282         cm_SkipIoctlPath(&ioctlp->ioctl);
1283         cm_SetFid(&fid, optionsp->fid.cell, optionsp->fid.volume, 
1284                   optionsp->fid.vnode, optionsp->fid.unique);
1285         code = cm_GetSCache(&fid, &scp, userp, &req);
1286     } else {
1287         code = smb_ParseIoctlPath(ioctlp, userp, &req, &scp, flags);
1288     }
1289     if (code) 
1290         return code;
1291
1292     code = cm_IoctlGetVolumeStatus(&ioctlp->ioctl, userp, scp, &req);
1293
1294     cm_ReleaseSCache(scp);
1295
1296     return code;
1297 }
1298
1299 afs_int32 
1300 smb_IoctlGetFid(struct smb_ioctl *ioctlp, struct cm_user *userp)
1301 {
1302     afs_int32 code;
1303     cm_scache_t *scp;
1304     cm_req_t req;
1305     cm_ioctlQueryOptions_t * optionsp;
1306     afs_uint32 flags = 0;
1307
1308     cm_InitReq(&req);
1309
1310     optionsp = cm_IoctlGetQueryOptions(&ioctlp->ioctl, userp);
1311     if (optionsp && CM_IOCTL_QOPTS_HAVE_LITERAL(optionsp))
1312         flags |= (optionsp->literal ? CM_PARSE_FLAG_LITERAL : 0);
1313
1314     code = smb_ParseIoctlPath(ioctlp, userp, &req, &scp, flags);
1315     if (code) 
1316         return code;
1317
1318     code = cm_IoctlGetFid(&ioctlp->ioctl, userp, scp, &req);
1319
1320     cm_ReleaseSCache(scp);
1321
1322     return code;
1323 }
1324
1325 afs_int32 
1326 smb_IoctlGetFileType(struct smb_ioctl *ioctlp, struct cm_user *userp)
1327 {
1328     afs_int32 code;
1329     cm_scache_t *scp;
1330     cm_req_t req;
1331     cm_ioctlQueryOptions_t * optionsp;
1332     afs_uint32 flags = 0;
1333
1334     cm_InitReq(&req);
1335
1336     optionsp = cm_IoctlGetQueryOptions(&ioctlp->ioctl, userp);
1337     if (optionsp && CM_IOCTL_QOPTS_HAVE_LITERAL(optionsp))
1338         flags |= (optionsp->literal ? CM_PARSE_FLAG_LITERAL : 0);
1339
1340     if (optionsp && CM_IOCTL_QOPTS_HAVE_FID(optionsp)) {
1341         cm_fid_t fid;
1342         cm_SkipIoctlPath(&ioctlp->ioctl);
1343         cm_SetFid(&fid, optionsp->fid.cell, optionsp->fid.volume, 
1344                   optionsp->fid.vnode, optionsp->fid.unique);
1345         code = cm_GetSCache(&fid, &scp, userp, &req);
1346     } else {
1347         code = smb_ParseIoctlPath(ioctlp, userp, &req, &scp, flags);
1348     }
1349     if (code) 
1350         return code;
1351
1352     code = cm_IoctlGetFileType(&ioctlp->ioctl, userp, scp, &req);
1353
1354     cm_ReleaseSCache(scp);
1355
1356     return code;
1357 }
1358
1359 afs_int32 
1360 smb_IoctlGetOwner(struct smb_ioctl *ioctlp, struct cm_user *userp)
1361 {
1362     afs_int32 code;
1363     cm_scache_t *scp;
1364     cm_req_t req;
1365     cm_ioctlQueryOptions_t *optionsp;
1366     afs_uint32 flags = 0;
1367
1368     cm_InitReq(&req);
1369
1370     optionsp = cm_IoctlGetQueryOptions(&ioctlp->ioctl, userp);
1371     if (optionsp && CM_IOCTL_QOPTS_HAVE_LITERAL(optionsp))
1372         flags |= (optionsp->literal ? CM_PARSE_FLAG_LITERAL : 0);
1373
1374     if (optionsp && CM_IOCTL_QOPTS_HAVE_FID(optionsp)) {
1375         cm_fid_t fid;
1376         cm_SkipIoctlPath(&ioctlp->ioctl);
1377         cm_SetFid(&fid, optionsp->fid.cell, optionsp->fid.volume,
1378                   optionsp->fid.vnode, optionsp->fid.unique);
1379         code = cm_GetSCache(&fid, &scp, userp, &req);
1380     } else {
1381         code = smb_ParseIoctlPath(ioctlp, userp, &req, &scp, flags);
1382     }
1383     if (code) 
1384         return code;
1385
1386     code = cm_IoctlGetOwner(&ioctlp->ioctl, userp, scp, &req);
1387
1388     cm_ReleaseSCache(scp);
1389
1390     return code;
1391 }
1392
1393 afs_int32 
1394 smb_IoctlWhereIs(struct smb_ioctl *ioctlp, struct cm_user *userp)
1395 {
1396     afs_int32 code;
1397     cm_scache_t *scp;
1398     cm_req_t req;
1399     cm_ioctlQueryOptions_t *optionsp;
1400     afs_uint32 flags = 0;
1401
1402     cm_InitReq(&req);
1403
1404     optionsp = cm_IoctlGetQueryOptions(&ioctlp->ioctl, userp);
1405     if (optionsp && CM_IOCTL_QOPTS_HAVE_LITERAL(optionsp))
1406         flags |= (optionsp->literal ? CM_PARSE_FLAG_LITERAL : 0);
1407
1408     if (optionsp && CM_IOCTL_QOPTS_HAVE_FID(optionsp)) {
1409         cm_fid_t fid;
1410         cm_SkipIoctlPath(&ioctlp->ioctl);
1411         cm_SetFid(&fid, optionsp->fid.cell, optionsp->fid.volume,
1412                   optionsp->fid.vnode, optionsp->fid.unique);
1413         code = cm_GetSCache(&fid, &scp, userp, &req);
1414     } else {
1415         code = smb_ParseIoctlPath(ioctlp, userp, &req, &scp, flags);
1416     }
1417     if (code) 
1418         return code;
1419
1420     code = cm_IoctlWhereIs(&ioctlp->ioctl, userp, scp, &req);
1421
1422     cm_ReleaseSCache(scp);
1423
1424     return code;
1425 }
1426
1427
1428 afs_int32 
1429 smb_IoctlStatMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp)
1430 {
1431     afs_int32 code;
1432     cm_scache_t *dscp;
1433     cm_req_t req;
1434
1435     cm_InitReq(&req);
1436
1437     code = smb_ParseIoctlPath(ioctlp, userp, &req, &dscp, 0);
1438     if (code)
1439         return code;
1440
1441     code = cm_IoctlStatMountPoint(&ioctlp->ioctl, userp, dscp, &req);
1442
1443     cm_ReleaseSCache(dscp);
1444
1445     return code;
1446 }
1447
1448 afs_int32 
1449 smb_IoctlDeleteMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp)
1450 {
1451     afs_int32 code;
1452     cm_scache_t *dscp;
1453     cm_req_t req;
1454
1455     cm_InitReq(&req);
1456
1457     code = smb_ParseIoctlPath(ioctlp, userp, &req, &dscp, 0);
1458     if (code) 
1459         return code;
1460
1461     code = cm_IoctlDeleteMountPoint(&ioctlp->ioctl, userp, dscp, &req);
1462
1463     cm_ReleaseSCache(dscp);
1464
1465     return code;
1466 }
1467
1468 afs_int32 
1469 smb_IoctlCheckServers(struct smb_ioctl *ioctlp, struct cm_user *userp)
1470 {
1471     cm_SkipIoctlPath(&ioctlp->ioctl);   /* we don't care about the path */
1472
1473     return cm_IoctlCheckServers(&ioctlp->ioctl, userp);
1474 }
1475
1476 afs_int32 
1477 smb_IoctlGag(struct smb_ioctl *ioctlp, struct cm_user *userp)
1478 {
1479     /* we don't print anything superfluous, so we don't support the gag call */
1480     return CM_ERROR_INVAL;
1481 }
1482
1483 afs_int32 
1484 smb_IoctlCheckVolumes(struct smb_ioctl *ioctlp, struct cm_user *userp)
1485 {
1486     cm_SkipIoctlPath(&ioctlp->ioctl);
1487
1488     return cm_IoctlCheckVolumes(&ioctlp->ioctl, userp);
1489 }
1490
1491 afs_int32 smb_IoctlSetCacheSize(struct smb_ioctl *ioctlp, struct cm_user *userp)
1492 {
1493     cm_SkipIoctlPath(&ioctlp->ioctl);
1494
1495     return cm_IoctlSetCacheSize(&ioctlp->ioctl, userp);
1496 }
1497
1498
1499 afs_int32 
1500 smb_IoctlTraceControl(struct smb_ioctl *ioctlp, struct cm_user *userp)
1501 {
1502     cm_SkipIoctlPath(&ioctlp->ioctl);
1503        
1504     return cm_IoctlTraceControl(&ioctlp->ioctl, userp);
1505 }
1506
1507 afs_int32 
1508 smb_IoctlGetCacheParms(struct smb_ioctl *ioctlp, struct cm_user *userp)
1509 {
1510     cm_SkipIoctlPath(&ioctlp->ioctl);
1511        
1512     return cm_IoctlGetCacheParms(&ioctlp->ioctl, userp);
1513 }
1514
1515 afs_int32 
1516 smb_IoctlGetCell(struct smb_ioctl *ioctlp, struct cm_user *userp)
1517 {
1518     cm_SkipIoctlPath(&ioctlp->ioctl);
1519
1520     return cm_IoctlGetCell(&ioctlp->ioctl, userp);
1521 }
1522
1523 afs_int32 
1524 smb_IoctlNewCell(struct smb_ioctl *ioctlp, struct cm_user *userp)
1525 {
1526     cm_SkipIoctlPath(&ioctlp->ioctl);
1527
1528     return cm_IoctlNewCell(&ioctlp->ioctl, userp);
1529 }
1530
1531 afs_int32 
1532 smb_IoctlGetWsCell(smb_ioctl_t *ioctlp, cm_user_t *userp)
1533 {
1534     cm_SkipIoctlPath(&ioctlp->ioctl);
1535
1536     return cm_IoctlGetWsCell(&ioctlp->ioctl, userp);
1537 }
1538
1539 afs_int32 
1540 smb_IoctlSysName(struct smb_ioctl *ioctlp, struct cm_user *userp)
1541 {
1542     cm_SkipIoctlPath(&ioctlp->ioctl);
1543
1544     return cm_IoctlSysName(&ioctlp->ioctl, userp);
1545 }
1546
1547 afs_int32 
1548 smb_IoctlGetCellStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
1549 {
1550     cm_SkipIoctlPath(&ioctlp->ioctl);
1551
1552     return cm_IoctlGetCellStatus(&ioctlp->ioctl, userp);
1553 }
1554
1555 afs_int32 
1556 smb_IoctlSetCellStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
1557 {
1558     cm_SkipIoctlPath(&ioctlp->ioctl);
1559
1560     return cm_IoctlSetCellStatus(&ioctlp->ioctl, userp);
1561 }
1562
1563 afs_int32
1564 smb_IoctlSetSPrefs(struct smb_ioctl *ioctlp, struct cm_user *userp)
1565 {
1566     cm_SkipIoctlPath(&ioctlp->ioctl);
1567
1568     return cm_IoctlSetSPrefs(&ioctlp->ioctl, userp);
1569 }
1570
1571 afs_int32
1572 smb_IoctlGetSPrefs(struct smb_ioctl *ioctlp, struct cm_user *userp)
1573 {
1574     cm_SkipIoctlPath(&ioctlp->ioctl);
1575
1576     return cm_IoctlGetSPrefs(&ioctlp->ioctl, userp);
1577 }
1578
1579 afs_int32
1580 smb_IoctlStoreBehind(struct smb_ioctl *ioctlp, struct cm_user *userp)
1581 {
1582     /* we ignore default asynchrony since we only have one way
1583      * of doing this today.
1584      */
1585     return 0;
1586 }       
1587
1588 afs_int32
1589 smb_IoctlCreateMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp)
1590 {
1591     afs_int32 code;
1592     cm_scache_t *dscp;
1593     clientchar_t leaf[LEAF_SIZE];
1594     cm_req_t req;
1595
1596     cm_InitReq(&req);
1597         
1598     code = smb_ParseIoctlParent(ioctlp, userp, &req, &dscp, leaf);
1599     if (code)
1600         return code;
1601
1602     code = cm_IoctlCreateMountPoint(&ioctlp->ioctl, userp, dscp, &req, leaf);
1603
1604     cm_ReleaseSCache(dscp);
1605     return code;
1606 }
1607
1608 afs_int32
1609 smb_IoctlSymlink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1610 {
1611     afs_int32 code;
1612     cm_scache_t *dscp;
1613     clientchar_t leaf[LEAF_SIZE];
1614     cm_req_t req;
1615
1616     cm_InitReq(&req);
1617
1618     code = smb_ParseIoctlParent(ioctlp, userp, &req, &dscp, leaf);
1619     if (code) return code;
1620
1621     code = cm_IoctlSymlink(&ioctlp->ioctl, userp, dscp, &req, leaf);
1622
1623     cm_ReleaseSCache(dscp);
1624
1625     return code;
1626 }
1627
1628 afs_int32 
1629 smb_IoctlListlink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1630 {
1631     afs_int32 code;
1632     cm_scache_t *dscp;
1633     cm_req_t req;
1634
1635     cm_InitReq(&req);
1636
1637     code = smb_ParseIoctlPath(ioctlp, userp, &req, &dscp, 0);
1638     if (code) return code;
1639
1640     code = cm_IoctlListlink(&ioctlp->ioctl, userp, dscp, &req);
1641
1642     cm_ReleaseSCache(dscp);
1643     return code;
1644 }
1645
1646 afs_int32 
1647 smb_IoctlIslink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1648 {/*CHECK FOR VALID SYMLINK*/
1649     afs_int32 code;
1650     cm_scache_t *dscp;
1651     cm_req_t req;
1652
1653     cm_InitReq(&req);
1654
1655     code = smb_ParseIoctlPath(ioctlp, userp, &req, &dscp, 0);
1656     if (code) return code;
1657
1658     code = cm_IoctlIslink(&ioctlp->ioctl, userp, dscp, &req);
1659
1660     cm_ReleaseSCache(dscp);
1661
1662     return code;
1663 }
1664
1665 afs_int32 
1666 smb_IoctlDeletelink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1667 {
1668     afs_int32 code;
1669     cm_scache_t *dscp;
1670     cm_req_t req;
1671
1672     cm_InitReq(&req);
1673
1674     code = smb_ParseIoctlPath(ioctlp, userp, &req, &dscp, 0);
1675     if (code) return code;
1676
1677     code = cm_IoctlDeletelink(&ioctlp->ioctl, userp, dscp, &req);
1678
1679     cm_ReleaseSCache(dscp);
1680
1681     return code;
1682 }
1683
1684 afs_int32 
1685 smb_IoctlGetTokenIter(struct smb_ioctl *ioctlp, struct cm_user *userp)
1686 {
1687     cm_SkipIoctlPath(&ioctlp->ioctl);
1688
1689     return cm_IoctlGetTokenIter(&ioctlp->ioctl, userp);
1690 }
1691
1692 afs_int32
1693 smb_IoctlGetToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
1694 {
1695     cm_SkipIoctlPath(&ioctlp->ioctl);
1696
1697     return cm_IoctlGetToken(&ioctlp->ioctl, userp);
1698 }
1699
1700
1701 afs_int32
1702 smb_IoctlDelToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
1703 {
1704     cm_SkipIoctlPath(&ioctlp->ioctl);
1705
1706     return cm_IoctlDelToken(&ioctlp->ioctl, userp);
1707 }
1708
1709
1710 afs_int32
1711 smb_IoctlDelAllToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
1712 {
1713     cm_SkipIoctlPath(&ioctlp->ioctl);
1714
1715     return cm_IoctlDelAllToken(&ioctlp->ioctl, userp);
1716 }
1717
1718
1719 afs_int32
1720 smb_IoctlMakeSubmount(struct smb_ioctl *ioctlp, struct cm_user *userp)
1721 {
1722     cm_SkipIoctlPath(&ioctlp->ioctl);
1723
1724     return cm_IoctlMakeSubmount(&ioctlp->ioctl, userp);
1725 }
1726
1727 afs_int32
1728 smb_IoctlGetRxkcrypt(struct smb_ioctl *ioctlp, struct cm_user *userp)
1729 {
1730     cm_SkipIoctlPath(&ioctlp->ioctl);
1731
1732     return cm_IoctlGetRxkcrypt(&ioctlp->ioctl, userp);
1733 }
1734
1735 afs_int32
1736 smb_IoctlSetRxkcrypt(struct smb_ioctl *ioctlp, struct cm_user *userp)
1737 {
1738     cm_SkipIoctlPath(&ioctlp->ioctl);
1739
1740     return cm_IoctlSetRxkcrypt(&ioctlp->ioctl, userp);
1741 }
1742
1743 afs_int32
1744 smb_IoctlRxStatProcess(struct smb_ioctl *ioctlp, struct cm_user *userp)
1745 {
1746     cm_SkipIoctlPath(&ioctlp->ioctl);
1747
1748     return cm_IoctlRxStatProcess(&ioctlp->ioctl, userp);
1749 }
1750
1751
1752 afs_int32
1753 smb_IoctlRxStatPeer(struct smb_ioctl *ioctlp, struct cm_user *userp)
1754 {
1755     cm_SkipIoctlPath(&ioctlp->ioctl);
1756
1757     return cm_IoctlRxStatPeer(&ioctlp->ioctl, userp);
1758 }
1759
1760 afs_int32
1761 smb_IoctlUnicodeControl(struct smb_ioctl *ioctlp, struct cm_user *userp)
1762 {
1763     cm_SkipIoctlPath(&ioctlp->ioctl);
1764
1765     return cm_IoctlUnicodeControl(&ioctlp->ioctl, userp);
1766 }
1767
1768 afs_int32
1769 smb_IoctlUUIDControl(struct smb_ioctl *ioctlp, struct cm_user *userp)
1770 {
1771     cm_SkipIoctlPath(&ioctlp->ioctl);
1772
1773     return cm_IoctlUUIDControl(&ioctlp->ioctl, userp);
1774 }
1775
1776
1777 afs_int32
1778 smb_IoctlMemoryDump(struct smb_ioctl *ioctlp, struct cm_user *userp)
1779 {
1780     cm_SkipIoctlPath(&ioctlp->ioctl);
1781
1782     return cm_IoctlMemoryDump(&ioctlp->ioctl, userp);
1783 }
1784
1785 afs_int32
1786 smb_IoctlPathAvailability(struct smb_ioctl *ioctlp, struct cm_user *userp)
1787 {
1788     afs_int32 code;
1789     cm_scache_t *scp;
1790     cm_req_t req;
1791     cm_ioctlQueryOptions_t *optionsp;
1792     afs_uint32 flags = 0;
1793
1794     cm_InitReq(&req);
1795
1796     optionsp = cm_IoctlGetQueryOptions(&ioctlp->ioctl, userp);
1797     if (optionsp && CM_IOCTL_QOPTS_HAVE_LITERAL(optionsp))
1798         flags |= (optionsp->literal ? CM_PARSE_FLAG_LITERAL : 0);
1799
1800     if (optionsp && CM_IOCTL_QOPTS_HAVE_FID(optionsp)) {
1801         cm_fid_t fid;
1802         cm_SkipIoctlPath(&ioctlp->ioctl);
1803         cm_SetFid(&fid, optionsp->fid.cell, optionsp->fid.volume, 
1804                   optionsp->fid.vnode, optionsp->fid.unique);
1805         code = cm_GetSCache(&fid, &scp, userp, &req);
1806     } else {
1807         code = smb_ParseIoctlPath(ioctlp, userp, &req, &scp, flags);
1808     }
1809     if (code) 
1810         return code;
1811
1812     code = cm_IoctlPathAvailability(&ioctlp->ioctl, userp, scp, &req);
1813     cm_ReleaseSCache(scp);
1814     return code;
1815 }
1816
1817 afs_int32
1818 smb_IoctlVolStatTest(struct smb_ioctl *ioctlp, struct cm_user *userp)
1819 {
1820     cm_req_t req;
1821
1822     cm_InitReq(&req);
1823
1824     cm_SkipIoctlPath(&ioctlp->ioctl);
1825
1826     return cm_IoctlVolStatTest(&ioctlp->ioctl, userp, &req);
1827 }