2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afs/param.h>
16 #include <sys/socket.h>
28 #include "afsd_init.h"
31 #include "cm_server.h"
47 /* Copied from afs_tokens.h */
48 #define PIOCTL_LOGON 0x1
51 osi_mutex_t cm_Afsdsbmt_Lock;
53 extern afs_int32 cryptall;
54 extern char cm_NetbiosName[];
56 void cm_InitIoctl(void)
58 lock_InitializeMutex(&cm_Afsdsbmt_Lock, "AFSDSBMT.INI Access Lock");
61 long cm_FlushFile(cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp)
65 lock_ObtainWrite(&scp->bufCreateLock);
66 code = buf_FlushCleanPages(scp, userp, reqp);
68 lock_ObtainMutex(&scp->mx);
69 scp->cbServerp = NULL;
71 lock_ReleaseMutex(&scp->mx);
73 lock_ReleaseWrite(&scp->bufCreateLock);
80 * cm_ResetACLCache -- invalidate ACL info for a user that has just
81 * obtained or lost tokens
83 void cm_ResetACLCache(cm_user_t *userp)
88 lock_ObtainWrite(&cm_scacheLock);
89 for (hash=0; hash < cm_hashTableSize; hash++) {
90 for (scp=cm_hashTablep[hash]; scp; scp=scp->nextp) {
92 lock_ReleaseWrite(&cm_scacheLock);
93 lock_ObtainMutex(&scp->mx);
94 cm_InvalidateACLUser(scp, userp);
95 lock_ReleaseMutex(&scp->mx);
96 lock_ObtainWrite(&cm_scacheLock);
100 lock_ReleaseWrite(&cm_scacheLock);
104 * TranslateExtendedChars - This is a fix for TR 54482.
106 * If an extended character (80 - FF) is entered into a file
107 * or directory name in Windows, the character is translated
108 * into the OEM character map before being passed to us. Why
109 * this occurs is unknown. Our pioctl functions must match
110 * this translation for paths given via our own commands (like
111 * fs). If we do not do this, then we will try to perform an
112 * operation on a non-translated path, which we will fail to
113 * find, since the path was created with the translated chars.
114 * This function performs the required translation.
116 void TranslateExtendedChars(char *str)
129 while (*p) *p++ &= 0x7f; /* turn off high bit; probably not right */
133 /* parse the passed-in file name and do a namei on it. If we fail,
134 * return an error code, otherwise return the vnode located in *scpp.
136 long cm_ParseIoctlPath(smb_ioctl_t *ioctlp, cm_user_t *userp, cm_req_t *reqp,
140 cm_scache_t *substRootp;
141 char * relativePath = ioctlp->inDatap;
143 /* This is usually the file name, but for StatMountPoint it is the path. */
144 /* ioctlp->inDatap can be either of the form:
147 * \\netbios-name\submount\path\.
148 * \\netbios-name\submount\path\file
150 TranslateExtendedChars(relativePath);
152 if (relativePath[0] == relativePath[1] &&
153 relativePath[1] == '\\' &&
154 !_strnicmp(cm_NetbiosName,relativePath+2,strlen(cm_NetbiosName)))
160 /* We may have found a UNC path.
161 * If the first component is the NetbiosName,
162 * then throw out the second component (the submount)
163 * since it had better expand into the value of ioctl->tidPathp
166 p = relativePath + 2 + strlen(cm_NetbiosName) + 1;
167 if ( !_strnicmp("all", p, 3) )
170 for (i = 0; *p && *p != '\\'; i++,p++ ) {
173 p++; /* skip past trailing slash */
174 shareName[i] = 0; /* terminate string */
176 shareFound = smb_FindShare(ioctlp->fidp->vcp, ioctlp->uidp, shareName, &sharePath);
178 /* we found a sharename, therefore use the resulting path */
179 code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
180 CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
181 userp, sharePath, reqp, &substRootp);
183 if (code) return code;
185 code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
186 userp, NULL, reqp, scpp);
187 if (code) return code;
189 /* otherwise, treat the name as a cellname mounted off the afs root.
190 * This requires that we reconstruct the shareName string with
191 * leading and trailing slashes.
193 p = relativePath + 2 + strlen(cm_NetbiosName) + 1;
194 if ( !_strnicmp("all", p, 3) )
198 for (i = 1; *p && *p != '\\'; i++,p++ ) {
201 p++; /* skip past trailing slash */
202 shareName[i++] = '/'; /* add trailing slash */
203 shareName[i] = 0; /* terminate string */
206 code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
207 CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
208 userp, shareName, reqp, &substRootp);
209 if (code) return code;
211 code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
212 userp, NULL, reqp, scpp);
213 if (code) return code;
216 code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
217 CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
218 userp, ioctlp->tidPathp, reqp, &substRootp);
219 if (code) return code;
221 code = cm_NameI(substRootp, relativePath, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
222 userp, NULL, reqp, scpp);
223 if (code) return code;
226 /* # of bytes of path */
227 code = strlen(ioctlp->inDatap) + 1;
228 ioctlp->inDatap += code;
230 /* This is usually nothing, but for StatMountPoint it is the file name. */
231 TranslateExtendedChars(ioctlp->inDatap);
233 /* and return success */
237 void cm_SkipIoctlPath(smb_ioctl_t *ioctlp)
241 temp = strlen(ioctlp->inDatap) + 1;
242 ioctlp->inDatap += temp;
246 /* format the specified path to look like "/afs/<cellname>/usr", by
247 * adding "/afs" (if necessary) in front, changing any \'s to /'s, and
248 * removing any trailing "/"'s. One weirdo caveat: "/afs" will be
249 * intentionally returned as "/afs/"--this makes submount manipulation
250 * easier (because we can always jump past the initial "/afs" to find
251 * the AFS path that should be written into afsdsbmt.ini).
253 void cm_NormalizeAfsPath (char *outpathp, char *inpathp)
256 char bslash_mountRoot[256];
258 strncpy(bslash_mountRoot, cm_mountRoot, sizeof(bslash_mountRoot) - 1);
259 bslash_mountRoot[0] = '\\';
261 if (!strnicmp (inpathp, cm_mountRoot, strlen(cm_mountRoot)))
262 lstrcpy (outpathp, inpathp);
263 else if (!strnicmp (inpathp, bslash_mountRoot, strlen(bslash_mountRoot)))
264 lstrcpy (outpathp, inpathp);
265 else if ((inpathp[0] == '/') || (inpathp[0] == '\\'))
266 sprintf (outpathp, "%s%s", cm_mountRoot, inpathp);
267 else // inpathp looks like "<cell>/usr"
268 sprintf (outpathp, "%s/%s", cm_mountRoot, inpathp);
270 for (cp = outpathp; *cp != 0; ++cp) {
275 if (strlen(outpathp) && (outpathp[strlen(outpathp)-1] == '/')) {
276 outpathp[strlen(outpathp)-1] = 0;
279 if (!strcmpi (outpathp, cm_mountRoot)) {
280 strcpy (outpathp, cm_mountRoot);
284 /* parse the passed-in file name and do a namei on its parent. If we fail,
285 * return an error code, otherwise return the vnode located in *scpp.
287 long cm_ParseIoctlParent(smb_ioctl_t *ioctlp, cm_user_t *userp, cm_req_t *reqp,
288 cm_scache_t **scpp, char *leafp)
293 cm_scache_t *substRootp;
295 strcpy(tbuffer, ioctlp->inDatap);
296 tp = strrchr(tbuffer, '\\');
297 jp = strrchr(tbuffer, '/');
300 else if (jp && (tp - tbuffer) < (jp - tbuffer))
303 strcpy(tbuffer, "\\");
305 strcpy(leafp, ioctlp->inDatap);
313 if (tbuffer[0] == tbuffer[1] &&
314 tbuffer[1] == '\\' &&
315 !_strnicmp(cm_NetbiosName,tbuffer+2,strlen(cm_NetbiosName)))
321 /* We may have found a UNC path.
322 * If the first component is the NetbiosName,
323 * then throw out the second component (the submount)
324 * since it had better expand into the value of ioctl->tidPathp
327 p = tbuffer + 2 + strlen(cm_NetbiosName) + 1;
328 if ( !_strnicmp("all", p, 3) )
331 for (i = 0; *p && *p != '\\'; i++,p++ ) {
334 p++; /* skip past trailing slash */
335 shareName[i] = 0; /* terminate string */
337 shareFound = smb_FindShare(ioctlp->fidp->vcp, ioctlp->uidp, shareName, &sharePath);
339 /* we found a sharename, therefore use the resulting path */
340 code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
341 CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
342 userp, sharePath, reqp, &substRootp);
344 if (code) return code;
346 code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
347 userp, NULL, reqp, scpp);
348 if (code) return code;
350 /* otherwise, treat the name as a cellname mounted off the afs root.
351 * This requires that we reconstruct the shareName string with
352 * leading and trailing slashes.
354 p = tbuffer + 2 + strlen(cm_NetbiosName) + 1;
355 if ( !_strnicmp("all", p, 3) )
359 for (i = 1; *p && *p != '\\'; i++,p++ ) {
362 p++; /* skip past trailing slash */
363 shareName[i++] = '/'; /* add trailing slash */
364 shareName[i] = 0; /* terminate string */
366 code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
367 CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
368 userp, shareName, reqp, &substRootp);
369 if (code) return code;
371 code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
372 userp, NULL, reqp, scpp);
373 if (code) return code;
376 code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
377 CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
378 userp, ioctlp->tidPathp, reqp, &substRootp);
379 if (code) return code;
381 code = cm_NameI(substRootp, tbuffer, CM_FLAG_FOLLOW,
382 userp, NULL, reqp, scpp);
383 if (code) return code;
386 /* # of bytes of path */
387 code = strlen(ioctlp->inDatap) + 1;
388 ioctlp->inDatap += code;
390 /* and return success */
394 long cm_IoctlGetACL(smb_ioctl_t *ioctlp, cm_user_t *userp)
399 AFSFetchStatus fileStatus;
408 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
409 if (code) return code;
411 /* now make the get acl call */
412 fid.Volume = scp->fid.volume;
413 fid.Vnode = scp->fid.vnode;
414 fid.Unique = scp->fid.unique;
416 acl.AFSOpaque_val = ioctlp->outDatap;
417 acl.AFSOpaque_len = 0;
418 code = cm_Conn(&scp->fid, userp, &req, &connp);
421 code = RXAFS_FetchACL(connp->callp, &fid, &acl, &fileStatus, &volSync);
422 } while (cm_Analyze(connp, userp, &req, &scp->fid,
423 &volSync, NULL, code));
424 code = cm_MapRPCError(code, &req);
425 cm_ReleaseSCache(scp);
427 if (code) return code;
429 /* skip over return data */
430 tlen = strlen(ioctlp->outDatap) + 1;
431 ioctlp->outDatap += tlen;
433 /* and return success */
437 long cm_IoctlGetFileCellName(struct smb_ioctl *ioctlp, struct cm_user *userp)
446 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
447 if (code) return code;
449 cellp = cm_FindCellByID(scp->fid.cell);
451 strcpy(ioctlp->outDatap, cellp->namep);
452 ioctlp->outDatap += strlen(ioctlp->outDatap) + 1;
455 else code = CM_ERROR_NOSUCHCELL;
457 cm_ReleaseSCache(scp);
461 long cm_IoctlSetACL(struct smb_ioctl *ioctlp, struct cm_user *userp)
466 AFSFetchStatus fileStatus;
474 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
475 if (code) return code;
477 /* now make the get acl call */
478 fid.Volume = scp->fid.volume;
479 fid.Vnode = scp->fid.vnode;
480 fid.Unique = scp->fid.unique;
482 acl.AFSOpaque_val = ioctlp->inDatap;
483 acl.AFSOpaque_len = strlen(ioctlp->inDatap)+1;
484 code = cm_Conn(&scp->fid, userp, &req, &connp);
487 code = RXAFS_StoreACL(connp->callp, &fid, &acl, &fileStatus, &volSync);
488 } while (cm_Analyze(connp, userp, &req, &scp->fid,
489 &volSync, NULL, code));
490 code = cm_MapRPCError(code, &req);
492 /* invalidate cache info, since we just trashed the ACL cache */
493 lock_ObtainMutex(&scp->mx);
494 cm_DiscardSCache(scp);
495 lock_ReleaseMutex(&scp->mx);
497 cm_ReleaseSCache(scp);
502 long cm_IoctlFlushVolume(struct smb_ioctl *ioctlp, struct cm_user *userp)
506 unsigned long volume;
512 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
513 if (code) return code;
515 volume = scp->fid.volume;
516 cm_ReleaseSCache(scp);
518 lock_ObtainWrite(&cm_scacheLock);
519 for(i=0; i<cm_hashTableSize; i++) {
520 for(scp = cm_hashTablep[i]; scp; scp = scp->nextp) {
521 if (scp->fid.volume == volume) {
523 lock_ReleaseWrite(&cm_scacheLock);
525 /* now flush the file */
526 cm_FlushFile(scp, userp, &req);
528 lock_ObtainWrite(&cm_scacheLock);
533 lock_ReleaseWrite(&cm_scacheLock);
538 long cm_IoctlFlushFile(struct smb_ioctl *ioctlp, struct cm_user *userp)
546 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
547 if (code) return code;
549 cm_FlushFile(scp, userp, &req);
550 cm_ReleaseSCache(scp);
555 long cm_IoctlSetVolumeStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
559 char offLineMsg[256];
563 AFSFetchVolumeStatus volStat;
564 AFSStoreVolumeStatus storeStat;
572 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
573 if (code) return code;
575 cellp = cm_FindCellByID(scp->fid.cell);
578 if (scp->flags & CM_SCACHEFLAG_RO) {
579 cm_ReleaseSCache(scp);
580 return CM_ERROR_READONLY;
583 code = cm_GetVolumeByID(cellp, scp->fid.volume, userp, &req, &tvp);
585 cm_ReleaseSCache(scp);
589 /* Copy the junk out, using cp as a roving pointer. */
590 cp = ioctlp->inDatap;
591 memcpy((char *)&volStat, cp, sizeof(AFSFetchVolumeStatus));
592 cp += sizeof(AFSFetchVolumeStatus);
594 cp += strlen(volName)+1;
595 strcpy(offLineMsg, cp);
596 cp += strlen(offLineMsg)+1;
599 if (volStat.MinQuota != -1) {
600 storeStat.MinQuota = volStat.MinQuota;
601 storeStat.Mask |= AFS_SETMINQUOTA;
603 if (volStat.MaxQuota != -1) {
604 storeStat.MaxQuota = volStat.MaxQuota;
605 storeStat.Mask |= AFS_SETMAXQUOTA;
609 code = cm_Conn(&scp->fid, userp, &req, &tcp);
612 code = RXAFS_SetVolumeStatus(tcp->callp, scp->fid.volume,
613 &storeStat, volName, offLineMsg, motd);
614 } while (cm_Analyze(tcp, userp, &req, &scp->fid, NULL, NULL, code));
615 code = cm_MapRPCError(code, &req);
617 /* return on failure */
618 cm_ReleaseSCache(scp);
623 /* we are sending parms back to make compat. with prev system. should
624 * change interface later to not ask for current status, just set
627 cp = ioctlp->outDatap;
628 memcpy(cp, (char *)&volStat, sizeof(VolumeStatus));
629 cp += sizeof(VolumeStatus);
631 cp += strlen(volName)+1;
632 strcpy(cp, offLineMsg);
633 cp += strlen(offLineMsg)+1;
635 cp += strlen(motd)+1;
637 /* now return updated return data pointer */
638 ioctlp->outDatap = cp;
643 long cm_IoctlGetVolumeStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
647 char offLineMsg[256];
651 AFSFetchVolumeStatus volStat;
660 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
661 if (code) return code;
664 OfflineMsg = offLineMsg;
667 code = cm_Conn(&scp->fid, userp, &req, &tcp);
670 code = RXAFS_GetVolumeStatus(tcp->callp, scp->fid.volume,
671 &volStat, &Name, &OfflineMsg, &MOTD);
672 } while (cm_Analyze(tcp, userp, &req, &scp->fid, NULL, NULL, code));
673 code = cm_MapRPCError(code, &req);
675 cm_ReleaseSCache(scp);
676 if (code) return code;
678 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
679 cp = ioctlp->outDatap;
680 memcpy(cp, (char *)&volStat, sizeof(AFSFetchVolumeStatus));
681 cp += sizeof(AFSFetchVolumeStatus);
683 cp += strlen(volName)+1;
684 strcpy(cp, offLineMsg);
685 cp += strlen(offLineMsg)+1;
687 cp += strlen(motd)+1;
689 /* return new size */
690 ioctlp->outDatap = cp;
695 long cm_IoctlWhereIs(struct smb_ioctl *ioctlp, struct cm_user *userp)
701 cm_serverRef_t *tsrp;
703 unsigned long volume;
709 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
710 if (code) return code;
712 volume = scp->fid.volume;
714 cellp = cm_FindCellByID(scp->fid.cell);
717 cm_ReleaseSCache(scp);
719 code = cm_GetVolumeByID(cellp, volume, userp, &req, &tvp);
720 if (code) return code;
722 cp = ioctlp->outDatap;
724 lock_ObtainMutex(&tvp->mx);
725 tsrp = cm_GetVolServers(tvp, volume);
726 lock_ObtainRead(&cm_serverLock);
729 memcpy(cp, (char *)&tsp->addr.sin_addr.s_addr, sizeof(long));
733 lock_ReleaseRead(&cm_serverLock);
734 lock_ReleaseMutex(&tvp->mx);
736 /* still room for terminating NULL, add it on */
737 volume = 0; /* reuse vbl */
738 memcpy(cp, (char *)&volume, sizeof(long));
741 ioctlp->outDatap = cp;
746 long cm_IoctlStatMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp)
756 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
757 if (code) return code;
759 cp = ioctlp->inDatap;
761 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
762 cm_ReleaseSCache(dscp);
763 if (code) return code;
765 lock_ObtainMutex(&scp->mx);
767 /* now check that this is a real mount point */
768 if (scp->fileType != CM_SCACHETYPE_MOUNTPOINT) {
769 lock_ReleaseMutex(&scp->mx);
770 cm_ReleaseSCache(scp);
771 return CM_ERROR_INVAL;
774 code = cm_ReadMountPoint(scp, userp, &req);
776 cp = ioctlp->outDatap;
777 strcpy(cp, scp->mountPointStringp);
778 cp += strlen(cp) + 1;
779 ioctlp->outDatap = cp;
781 lock_ReleaseMutex(&scp->mx);
782 cm_ReleaseSCache(scp);
787 long cm_IoctlDeleteMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp)
797 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
798 if (code) return code;
800 cp = ioctlp->inDatap;
802 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
804 /* if something went wrong, bail out now */
809 lock_ObtainMutex(&scp->mx);
810 code = cm_SyncOp(scp, NULL, userp, &req, 0,
811 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
813 lock_ReleaseMutex(&scp->mx);
814 cm_ReleaseSCache(scp);
818 /* now check that this is a real mount point */
819 if (scp->fileType != CM_SCACHETYPE_MOUNTPOINT) {
820 lock_ReleaseMutex(&scp->mx);
821 cm_ReleaseSCache(scp);
822 code = CM_ERROR_INVAL;
826 /* time to make the RPC, so drop the lock */
827 lock_ReleaseMutex(&scp->mx);
828 cm_ReleaseSCache(scp);
830 /* easier to do it this way */
831 code = cm_Unlink(dscp, cp, userp, &req);
832 if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
833 smb_NotifyChange(FILE_ACTION_REMOVED,
834 FILE_NOTIFY_CHANGE_DIR_NAME,
835 dscp, cp, NULL, TRUE);
838 cm_ReleaseSCache(dscp);
842 long cm_IoctlCheckServers(struct smb_ioctl *ioctlp, struct cm_user *userp)
852 cm_SkipIoctlPath(ioctlp); /* we don't care about the path */
853 tp = ioctlp->inDatap;
856 memcpy(&temp, tp, sizeof(temp));
857 if (temp == 0x12345678) { /* For afs3.3 version */
858 memcpy(&csi, tp, sizeof(csi));
859 if (csi.tinterval >= 0) {
860 cp = ioctlp->outDatap;
861 memcpy(cp, (char *)&cm_daemonCheckInterval, sizeof(long));
862 ioctlp->outDatap += sizeof(long);
863 if (csi.tinterval > 0) {
864 if (!smb_SUser(userp))
865 return CM_ERROR_NOACCESS;
866 cm_daemonCheckInterval = csi.tinterval;
874 } else { /* For pre afs3.3 versions */
875 memcpy((char *)&temp, ioctlp->inDatap, sizeof(long));
876 ioctlp->inDatap = cp = ioctlp->inDatap + sizeof(long);
877 if (cp - ioctlp->inAllocp < ioctlp->inCopied) /* still more data available */
882 * 1: fast check, don't contact servers.
883 * 2: local cell only.
886 /* have cell name, too */
887 cellp = cm_GetCell(cp, 0);
888 if (!cellp) return CM_ERROR_NOSUCHCELL;
890 else cellp = (cm_cell_t *) 0;
891 if (!cellp && (temp & 2)) {
893 cellp = cm_FindCellByID(1);
895 if (!(temp & 1)) { /* if not fast, call server checker routine */
896 /* check down servers */
897 cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS | CM_FLAG_CHECKUPSERVERS,
901 /* now return the current down server list */
902 cp = ioctlp->outDatap;
903 lock_ObtainRead(&cm_serverLock);
904 for(tsp = cm_allServersp; tsp; tsp=tsp->allNextp) {
905 if (cellp && tsp->cellp != cellp) continue; /* cell spec'd and wrong */
906 if ((tsp->flags & CM_SERVERFLAG_DOWN)
907 && tsp->type == CM_SERVER_FILE) {
908 memcpy(cp, (char *)&tsp->addr.sin_addr.s_addr, sizeof(long));
912 lock_ReleaseRead(&cm_serverLock);
914 ioctlp->outDatap = cp;
918 long cm_IoctlGag(struct smb_ioctl *ioctlp, struct cm_user *userp)
920 /* we don't print anything superfluous, so we don't support the gag call */
921 return CM_ERROR_INVAL;
924 long cm_IoctlCheckVolumes(struct smb_ioctl *ioctlp, struct cm_user *userp)
930 long cm_IoctlSetCacheSize(struct smb_ioctl *ioctlp, struct cm_user *userp)
935 cm_SkipIoctlPath(ioctlp);
937 memcpy(&temp, ioctlp->inDatap, sizeof(temp));
938 if (temp == 0) temp = buf_nOrigBuffers;
940 /* temp is in 1K units, convert to # of buffers */
941 temp = temp / (buf_bufferSize / 1024);
944 /* now adjust the cache size */
945 code = buf_SetNBuffers(temp);
950 long cm_IoctlTraceControl(struct smb_ioctl *ioctlp, struct cm_user *userp)
954 cm_SkipIoctlPath(ioctlp);
956 memcpy(&inValue, ioctlp->inDatap, sizeof(long));
960 afsd_ForceTrace(FALSE);
964 /* set tracing value to low order bit */
965 if ((inValue & 1) == 0) {
966 /* disable tracing */
967 osi_LogDisable(afsd_logp);
971 osi_LogEnable(afsd_logp);
975 /* see if we're supposed to do a reset, too */
977 osi_LogReset(afsd_logp);
980 /* and copy out tracing flag */
981 inValue = afsd_logp->enabled; /* use as a temp vbl */
982 memcpy(ioctlp->outDatap, &inValue, sizeof(long));
983 ioctlp->outDatap += sizeof(long);
987 long cm_IoctlGetCacheParms(struct smb_ioctl *ioctlp, struct cm_user *userp)
989 cm_cacheParms_t parms;
991 memset(&parms, 0, sizeof(parms));
993 /* first we get, in 1K units, the cache size */
994 parms.parms[0] = buf_nbuffers * (buf_bufferSize / 1024);
996 /* and then the actual # of buffers in use (not in the free list, I guess,
997 * will be what we do).
999 parms.parms[1] = (buf_nbuffers - buf_CountFreeList()) * (buf_bufferSize / 1024);
1001 memcpy(ioctlp->outDatap, &parms, sizeof(parms));
1002 ioctlp->outDatap += sizeof(parms);
1007 long cm_IoctlGetCell(struct smb_ioctl *ioctlp, struct cm_user *userp)
1012 cm_serverRef_t *serverRefp;
1013 cm_server_t *serverp;
1019 cm_SkipIoctlPath(ioctlp);
1021 tp = ioctlp->inDatap;
1023 memcpy((char *)&whichCell, tp, sizeof(long));
1026 /* see if more than one long passed in, ignoring the null pathname (the -1) */
1027 if (ioctlp->inCopied-1 > sizeof(long)) {
1028 memcpy((char *)&magic, tp, sizeof(long));
1031 lock_ObtainRead(&cm_cellLock);
1032 for(tcellp = cm_allCellsp; tcellp; tcellp = tcellp->nextp) {
1033 if (whichCell == 0) break;
1036 lock_ReleaseRead(&cm_cellLock);
1040 cp = ioctlp->outDatap;
1042 if (magic == 0x12345678) {
1043 memcpy(cp, (char *)&magic, sizeof(long));
1046 memset(cp, 0, max * sizeof(long));
1048 lock_ObtainRead(&cm_serverLock); /* for going down server list */
1049 serverRefp = tcellp->vlServersp;
1050 for(i=0; i<max; i++) {
1051 if (!serverRefp) break;
1052 serverp = serverRefp->server;
1053 memcpy(cp, &serverp->addr.sin_addr.s_addr, sizeof(long));
1055 serverRefp = serverRefp->next;
1057 lock_ReleaseRead(&cm_serverLock);
1058 cp = basep + max * sizeof(afs_int32);
1059 strcpy(cp, tcellp->namep);
1060 cp += strlen(tcellp->namep)+1;
1061 ioctlp->outDatap = cp;
1064 if (tcellp) return 0;
1065 else return CM_ERROR_NOMORETOKENS; /* mapped to EDOM */
1068 extern long cm_AddCellProc(void *rockp, struct sockaddr_in *addrp, char *namep);
1070 long cm_IoctlNewCell(struct smb_ioctl *ioctlp, struct cm_user *userp)
1072 /* NT cache manager will read cell information from afsdcell.ini each time
1073 * cell is accessed. So, this call is necessary only if list of server for a cell
1074 * changes (or IP addresses of cell servers changes).
1075 * All that needs to be done is to refresh server information for all cells that
1076 * are already loaded.
1078 * cell list will be cm_CellLock and cm_ServerLock will be held for write.
1084 cm_SkipIoctlPath(ioctlp);
1085 lock_ObtainWrite(&cm_cellLock);
1087 for(cp = cm_allCellsp; cp; cp=cp->nextp)
1090 /* delete all previous server lists - cm_FreeServerList will ask for write on cm_ServerLock*/
1091 cm_FreeServerList(&cp->vlServersp);
1092 cp->vlServersp = NULL;
1093 code = cm_SearchCellFile(cp->namep, cp->namep, cm_AddCellProc, cp);
1094 #ifdef AFS_AFSDB_ENV
1096 if (cm_dnsEnabled) {
1098 code = cm_SearchCellByDNS(cp->namep, cp->namep, &ttl, cm_AddCellProc, cp);
1099 if ( code == 0 ) { /* got cell from DNS */
1100 cp->flags |= CM_CELLFLAG_DNS;
1101 cp->flags &= ~CM_CELLFLAG_VLSERVER_INVALID;
1102 cp->timeout = time(0) + ttl;
1107 cp->flags &= ~CM_CELLFLAG_DNS;
1109 #endif /* AFS_AFSDB_ENV */
1111 cp->flags |= CM_CELLFLAG_VLSERVER_INVALID;
1114 cp->flags &= ~CM_CELLFLAG_VLSERVER_INVALID;
1115 cm_RandomizeServer(&cp->vlServersp);
1119 lock_ReleaseWrite(&cm_cellLock);
1123 long cm_IoctlGetWsCell(smb_ioctl_t *ioctlp, cm_user_t *userp)
1125 /* if we don't know our default cell, return failure */
1126 if (cm_rootCellp == NULL) {
1127 return CM_ERROR_NOSUCHCELL;
1130 /* return the default cellname to the caller */
1131 strcpy(ioctlp->outDatap, cm_rootCellp->namep);
1132 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
1138 long cm_IoctlSysName(struct smb_ioctl *ioctlp, struct cm_user *userp)
1143 cm_SkipIoctlPath(ioctlp);
1145 memcpy(&setSysName, ioctlp->inDatap, sizeof(long));
1146 ioctlp->inDatap += sizeof(long);
1149 strcpy(cm_sysName, ioctlp->inDatap);
1152 /* return the sysname to the caller */
1153 setSysName = 1; /* really means "found sys name */
1154 cp = ioctlp->outDatap;
1155 memcpy(cp, &setSysName, sizeof(long));
1156 cp += sizeof(long); /* skip found flag */
1157 strcpy(cp, cm_sysName);
1158 cp += strlen(cp) + 1; /* skip name and terminating null char */
1159 ioctlp->outDatap = cp;
1166 long cm_IoctlGetCellStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
1171 cm_SkipIoctlPath(ioctlp);
1173 cellp = cm_GetCell(ioctlp->inDatap, 0);
1174 if (!cellp) return CM_ERROR_NOSUCHCELL;
1177 lock_ObtainMutex(&cellp->mx);
1178 if (cellp->flags & CM_CELLFLAG_SUID)
1179 temp |= CM_SETCELLFLAG_SUID;
1180 lock_ReleaseMutex(&cellp->mx);
1182 /* now copy out parm */
1183 memcpy(ioctlp->outDatap, &temp, sizeof(long));
1184 ioctlp->outDatap += sizeof(long);
1189 long cm_IoctlSetCellStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
1194 cm_SkipIoctlPath(ioctlp);
1196 cellp = cm_GetCell(ioctlp->inDatap + 2*sizeof(long), 0);
1197 if (!cellp) return CM_ERROR_NOSUCHCELL;
1199 memcpy((char *)&temp, ioctlp->inDatap, sizeof(long));
1201 lock_ObtainMutex(&cellp->mx);
1202 if (temp & CM_SETCELLFLAG_SUID)
1203 cellp->flags |= CM_CELLFLAG_SUID;
1205 cellp->flags &= ~CM_CELLFLAG_SUID;
1206 lock_ReleaseMutex(&cellp->mx);
1211 long cm_IoctlSetSPrefs(struct smb_ioctl *ioctlp, struct cm_user *userp)
1213 cm_SSetPref_t *spin; /* input */
1214 cm_SPref_t *srvin; /* one input component */
1216 int i, vlonly, noServers, type;
1217 struct sockaddr_in tmp;
1218 unsigned short rank;
1220 cm_SkipIoctlPath(ioctlp); /* we don't care about the path */
1222 spin = (cm_SSetPref_t *)ioctlp->inDatap;
1223 noServers = spin->num_servers;
1224 vlonly = spin->flags;
1226 type = CM_SERVER_VLDB;
1228 type = CM_SERVER_FILE;
1230 for ( i=0; i < noServers; i++)
1232 srvin = &(spin->servers[i]);
1233 rank = srvin->rank + (rand() & 0x000f);
1234 tmp.sin_addr = srvin->host;
1235 tmp.sin_family = AF_INET;
1237 tsp = cm_FindServer(&tmp, type);
1238 if ( tsp ) /* an existing server - ref count increased */
1240 tsp->ipRank = rank; /* no need to protect by mutex*/
1242 if ( type == CM_SERVER_FILE) /* fileserver */
1244 /* find volumes which might have RO copy
1245 /* on server and change the ordering of
1247 cm_ChangeRankVolume(tsp);
1251 /* set preferences for an existing vlserver */
1252 cm_ChangeRankCellVLServer(tsp);
1254 cm_PutServer(tsp); /* decrease refcount */
1256 else /* add a new server without a cell */
1258 tsp = cm_NewServer(&tmp, type, NULL); /* refcount = 1 */
1265 long cm_IoctlGetSPrefs(struct smb_ioctl *ioctlp, struct cm_user *userp)
1267 cm_SPrefRequest_t *spin; /* input */
1268 cm_SPrefInfo_t *spout; /* output */
1269 cm_SPref_t *srvout; /* one output component */
1271 int i, vlonly, noServers;
1273 cm_SkipIoctlPath(ioctlp); /* we don't care about the path */
1275 spin = (cm_SPrefRequest_t *)ioctlp->inDatap;
1276 spout = (cm_SPrefInfo_t *) ioctlp->outDatap;
1277 srvout = spout->servers;
1278 noServers = spin->num_servers;
1279 vlonly = spin->flags & CM_SPREF_VLONLY;
1280 spout->num_servers = 0;
1282 lock_ObtainRead(&cm_serverLock); /* get server lock */
1284 for(tsp=cm_allServersp, i=0; tsp && noServers; tsp=tsp->allNextp,i++){
1285 if (spin->offset > i) {
1286 continue; /* catch up to where we left off */
1289 if ( vlonly && (tsp->type == CM_SERVER_FILE) )
1290 continue; /* ignore fileserver for -vlserver option*/
1291 if ( !vlonly && (tsp->type == CM_SERVER_VLDB) )
1292 continue; /* ignore vlservers */
1294 srvout->host = tsp->addr.sin_addr;
1295 srvout->rank = tsp->ipRank;
1297 spout->num_servers++;
1300 lock_ReleaseRead(&cm_serverLock); /* release server lock */
1302 if ( tsp ) /* we ran out of space in the output buffer */
1303 spout->next_offset = i;
1305 spout->next_offset = 0;
1306 ioctlp->outDatap += sizeof(cm_SPrefInfo_t) +
1307 (spout->num_servers -1 ) * sizeof(cm_SPref_t) ;
1311 long cm_IoctlStoreBehind(struct smb_ioctl *ioctlp, struct cm_user *userp)
1313 /* we ignore default asynchrony since we only have one way
1314 * of doing this today.
1319 long cm_IoctlCreateMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp)
1335 code = cm_ParseIoctlParent(ioctlp, userp, &req, &dscp, leaf);
1336 if (code) return code;
1338 /* Translate chars for the mount point name */
1339 TranslateExtendedChars(leaf);
1342 * The fs command allows the user to specify partial cell names on NT. These must
1343 * be expanded to the full cell name for mount points so that the mount points will
1344 * work on UNIX clients.
1347 /* Extract the possibly partial cell name */
1348 strcpy(cell, ioctlp->inDatap + 1); /* Skip the mp type character */
1350 if (cp = strchr(cell, ':')) {
1351 /* Extract the volume name */
1353 strcpy(volume, cp + 1);
1355 /* Get the full name for this cell */
1356 code = cm_SearchCellFile(cell, fullCell, 0, 0);
1357 #ifdef AFS_AFSDB_ENV
1358 if (code && cm_dnsEnabled)
1359 code = cm_SearchCellByDNS(cell, fullCell, &ttl, 0, 0);
1362 return CM_ERROR_NOSUCHCELL;
1364 sprintf(mpInfo, "%c%s:%s", *ioctlp->inDatap, fullCell, volume);
1366 /* No cell name specified */
1367 strcpy(mpInfo, ioctlp->inDatap);
1370 #ifdef AFS_FREELANCE_CLIENT
1371 if (cm_freelanceEnabled && dscp == cm_rootSCachep) {
1372 /* we are adding the mount point to the root dir., so call
1373 the freelance code to do the add. */
1374 osi_Log0(afsd_logp,"IoctlCreateMountPoint within Freelance root dir");
1375 code = cm_FreelanceAddMount(leaf, fullCell, volume, NULL);
1379 /* create the symlink with mode 644. The lack of X bits tells
1380 * us that it is a mount point.
1382 tattr.mask = CM_ATTRMASK_UNIXMODEBITS | CM_ATTRMASK_CLIENTMODTIME;
1383 tattr.unixModeBits = 0644;
1384 tattr.clientModTime = time(NULL);
1386 code = cm_SymLink(dscp, leaf, mpInfo, 0, &tattr, userp, &req);
1387 if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
1388 smb_NotifyChange(FILE_ACTION_ADDED,
1389 FILE_NOTIFY_CHANGE_DIR_NAME,
1390 dscp, leaf, NULL, TRUE);
1392 cm_ReleaseSCache(dscp);
1396 long cm_IoctlSymlink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1407 code = cm_ParseIoctlParent(ioctlp, userp, &req, &dscp, leaf);
1408 if (code) return code;
1410 /* Translate chars for the link name */
1411 TranslateExtendedChars(leaf);
1413 /* Translate chars for the linked to name */
1414 TranslateExtendedChars(ioctlp->inDatap);
1416 cp = ioctlp->inDatap; /* contents of link */
1418 /* Create symlink with mode 0755. */
1419 tattr.mask = CM_ATTRMASK_UNIXMODEBITS;
1420 tattr.unixModeBits = 0755;
1422 code = cm_SymLink(dscp, leaf, cp, 0, &tattr, userp, &req);
1423 if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
1424 smb_NotifyChange(FILE_ACTION_ADDED,
1425 FILE_NOTIFY_CHANGE_FILE_NAME
1426 | FILE_NOTIFY_CHANGE_DIR_NAME,
1427 dscp, leaf, NULL, TRUE);
1429 cm_ReleaseSCache(dscp);
1434 extern long cm_AssembleLink(cm_scache_t *linkScp, char *pathSuffixp,
1435 cm_scache_t **newRootScpp, cm_space_t **newSpaceBufferp,
1436 cm_user_t *userp, cm_req_t *reqp);
1438 long cm_IoctlListlink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1445 cm_scache_t *newRootScp;
1450 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
1451 if (code) return code;
1453 cp = ioctlp->inDatap;
1455 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
1456 cm_ReleaseSCache(dscp);
1457 if (code) return code;
1459 /* Check that it's a real symlink */
1460 if (scp->fileType != CM_SCACHETYPE_SYMLINK){
1461 cm_ReleaseSCache(scp);
1462 return CM_ERROR_INVAL;
1465 code = cm_AssembleLink(scp, "", &newRootScp, &spacep, userp, &req);
1466 cm_ReleaseSCache(scp);
1468 cp = ioctlp->outDatap;
1469 if (newRootScp != NULL) {
1470 strcpy(cp, cm_mountRoot);
1474 strcpy(cp, spacep->data);
1475 cp += strlen(cp) + 1;
1476 ioctlp->outDatap = cp;
1477 cm_FreeSpace(spacep);
1478 if (newRootScp != NULL)
1479 cm_ReleaseSCache(newRootScp);
1485 long cm_IoctlIslink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1486 {/*CHECK FOR VALID SYMLINK*/
1495 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
1496 if (code) return code;
1498 cp = ioctlp->inDatap;
1499 osi_LogEvent("cm_IoctlListlink",NULL," name[%s]",cp);
1501 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
1502 cm_ReleaseSCache(dscp);
1503 if (code) return code;
1505 /* Check that it's a real symlink */
1506 if (scp->fileType != CM_SCACHETYPE_SYMLINK)
1507 code = CM_ERROR_INVAL;
1508 cm_ReleaseSCache(scp);
1512 long cm_IoctlDeletelink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1522 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
1523 if (code) return code;
1525 cp = ioctlp->inDatap;
1527 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
1529 /* if something went wrong, bail out now */
1534 lock_ObtainMutex(&scp->mx);
1535 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1536 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1538 lock_ReleaseMutex(&scp->mx);
1539 cm_ReleaseSCache(scp);
1543 /* now check that this is a real symlink */
1544 if (scp->fileType != CM_SCACHETYPE_SYMLINK) {
1545 lock_ReleaseMutex(&scp->mx);
1546 cm_ReleaseSCache(scp);
1547 code = CM_ERROR_INVAL;
1551 /* time to make the RPC, so drop the lock */
1552 lock_ReleaseMutex(&scp->mx);
1553 cm_ReleaseSCache(scp);
1555 /* easier to do it this way */
1556 code = cm_Unlink(dscp, cp, userp, &req);
1557 if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
1558 smb_NotifyChange(FILE_ACTION_REMOVED,
1559 FILE_NOTIFY_CHANGE_FILE_NAME
1560 | FILE_NOTIFY_CHANGE_DIR_NAME,
1561 dscp, cp, NULL, TRUE);
1564 cm_ReleaseSCache(dscp);
1568 long cm_IoctlSetToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
1575 struct ClearToken ct;
1584 saveDataPtr = ioctlp->inDatap;
1586 cm_SkipIoctlPath(ioctlp);
1588 tp = ioctlp->inDatap;
1591 memcpy(&ticketLen, tp, sizeof(ticketLen));
1592 tp += sizeof(ticketLen);
1593 if (ticketLen < MINKTCTICKETLEN || ticketLen > MAXKTCTICKETLEN)
1594 return CM_ERROR_INVAL;
1596 /* remember ticket and skip over it for now */
1600 /* clear token size */
1601 memcpy(&ctSize, tp, sizeof(ctSize));
1602 tp += sizeof(ctSize);
1603 if (ctSize != sizeof(struct ClearToken))
1604 return CM_ERROR_INVAL;
1607 memcpy(&ct, tp, ctSize);
1609 if (ct.AuthHandle == -1)
1610 ct.AuthHandle = 999; /* more rxvab compat stuff */
1612 /* more stuff, if any */
1613 if (ioctlp->inCopied > tp - saveDataPtr) {
1614 /* flags: logon flag */
1615 memcpy(&flags, tp, sizeof(int));
1619 cellp = cm_GetCell(tp, CM_FLAG_CREATE);
1620 if (!cellp) return CM_ERROR_NOSUCHCELL;
1621 tp += strlen(tp) + 1;
1625 tp += strlen(tp) + 1;
1627 if (flags & PIOCTL_LOGON) {
1628 /* SMB user name with which to associate tokens */
1630 fprintf(stderr, "SMB name = %s\n", smbname);
1631 tp += strlen(tp) + 1;
1634 #ifndef DJGPP /* for win95, session key is back in pioctl */
1636 memcpy(&uuid, tp, sizeof(uuid));
1637 if (!cm_FindTokenEvent(uuid, sessionKey))
1638 return CM_ERROR_INVAL;
1641 cellp = cm_rootCellp;
1643 if (flags & PIOCTL_LOGON) {
1644 userp = smb_FindCMUserByName(smbname, ioctlp->fidp->vcp->rname);
1647 /* store the token */
1648 lock_ObtainMutex(&userp->mx);
1649 ucellp = cm_GetUCell(userp, cellp);
1650 ucellp->ticketLen = ticketLen;
1651 if (ucellp->ticketp)
1652 free(ucellp->ticketp); /* Discard old token if any */
1653 ucellp->ticketp = malloc(ticketLen);
1654 memcpy(ucellp->ticketp, ticket, ticketLen);
1657 * Get the session key from the RPC, rather than from the pioctl.
1660 memcpy(&ucellp->sessionKey, ct.HandShakeKey, sizeof(ct.HandShakeKey));
1662 memcpy(ucellp->sessionKey.data, sessionKey, sizeof(sessionKey));
1664 /* for win95, we are getting the session key from the pioctl */
1665 memcpy(&ucellp->sessionKey, ct.HandShakeKey, sizeof(ct.HandShakeKey));
1667 ucellp->kvno = ct.AuthHandle;
1668 ucellp->expirationTime = ct.EndTimestamp;
1670 if (uname) strcpy(ucellp->userName, uname);
1671 ucellp->flags |= CM_UCELLFLAG_RXKAD;
1672 lock_ReleaseMutex(&userp->mx);
1674 if (flags & PIOCTL_LOGON) {
1675 ioctlp->flags |= SMB_IOCTLFLAG_LOGON;
1678 cm_ResetACLCache(userp);
1683 long cm_IoctlGetTokenIter(struct smb_ioctl *ioctlp, struct cm_user *userp)
1689 struct ClearToken ct;
1691 cm_SkipIoctlPath(ioctlp);
1693 tp = ioctlp->inDatap;
1694 cp = ioctlp->outDatap;
1697 memcpy(&iterator, tp, sizeof(iterator));
1698 tp += sizeof(iterator);
1700 lock_ObtainMutex(&userp->mx);
1702 /* look for token */
1703 for (;;iterator++) {
1704 ucellp = cm_FindUCell(userp, iterator);
1706 lock_ReleaseMutex(&userp->mx);
1707 return CM_ERROR_NOMORETOKENS;
1709 if (ucellp->flags & CM_UCELLFLAG_RXKAD)
1714 temp = ucellp->iterator + 1;
1715 memcpy(cp, &temp, sizeof(temp));
1719 memcpy(cp, &ucellp->ticketLen, sizeof(ucellp->ticketLen));
1720 cp += sizeof(ucellp->ticketLen);
1723 memcpy(cp, ucellp->ticketp, ucellp->ticketLen);
1724 cp += ucellp->ticketLen;
1726 /* clear token size */
1728 memcpy(cp, &temp, sizeof(temp));
1732 ct.AuthHandle = ucellp->kvno;
1735 * Don't give out a real session key here
1738 memcpy(ct.HandShakeKey, &ucellp->sessionKey, sizeof(ct.HandShakeKey));
1740 memset(ct.HandShakeKey, 0, sizeof(ct.HandShakeKey));
1742 memcpy(ct.HandShakeKey, &ucellp->sessionKey, sizeof(ct.HandShakeKey));
1744 ct.ViceId = 37; /* XXX */
1745 ct.BeginTimestamp = 0; /* XXX */
1746 ct.EndTimestamp = ucellp->expirationTime;
1747 memcpy(cp, &ct, sizeof(ct));
1750 /* Primary flag (unused) */
1752 memcpy(cp, &temp, sizeof(temp));
1756 strcpy(cp, ucellp->cellp->namep);
1757 cp += strlen(cp) + 1;
1760 strcpy(cp, ucellp->userName);
1761 cp += strlen(cp) + 1;
1763 ioctlp->outDatap = cp;
1765 lock_ReleaseMutex(&userp->mx);
1770 long cm_IoctlGetToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
1776 struct ClearToken ct;
1782 cm_SkipIoctlPath(ioctlp);
1784 tp = ioctlp->inDatap;
1786 cp = ioctlp->outDatap;
1788 /* cell name is right here */
1789 cellp = cm_GetCell(tp, 0);
1790 if (!cellp) return CM_ERROR_NOSUCHCELL;
1791 tp += strlen(tp) + 1;
1795 memcpy(&uuid, tp, sizeof(uuid));
1798 lock_ObtainMutex(&userp->mx);
1800 ucellp = cm_GetUCell(userp, cellp);
1801 if (!ucellp || !(ucellp->flags & CM_UCELLFLAG_RXKAD)) {
1802 lock_ReleaseMutex(&userp->mx);
1803 return CM_ERROR_NOMORETOKENS;
1807 memcpy(cp, &ucellp->ticketLen, sizeof(ucellp->ticketLen));
1808 cp += sizeof(ucellp->ticketLen);
1811 memcpy(cp, ucellp->ticketp, ucellp->ticketLen);
1812 cp += ucellp->ticketLen;
1814 /* clear token size */
1816 memcpy(cp, &temp, sizeof(temp));
1820 ct.AuthHandle = ucellp->kvno;
1823 * Don't give out a real session key here
1826 memcpy(ct.HandShakeKey, &ucellp->sessionKey, sizeof(ct.HandShakeKey));
1828 memset(ct.HandShakeKey, 0, sizeof(ct.HandShakeKey));
1830 memcpy(ct.HandShakeKey, &ucellp->sessionKey, sizeof(ct.HandShakeKey));
1832 ct.ViceId = 37; /* XXX */
1833 ct.BeginTimestamp = 0; /* XXX */
1834 ct.EndTimestamp = ucellp->expirationTime;
1835 memcpy(cp, &ct, sizeof(ct));
1838 /* Primary flag (unused) */
1840 memcpy(cp, &temp, sizeof(temp));
1844 strcpy(cp, ucellp->cellp->namep);
1845 cp += strlen(cp) + 1;
1848 strcpy(cp, ucellp->userName);
1849 cp += strlen(cp) + 1;
1851 ioctlp->outDatap = cp;
1853 lock_ReleaseMutex(&userp->mx);
1856 cm_RegisterNewTokenEvent(uuid, ucellp->sessionKey.data);
1862 long cm_IoctlDelToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
1868 cm_SkipIoctlPath(ioctlp);
1870 cp = ioctlp->outDatap;
1872 /* cell name is right here */
1873 cellp = cm_GetCell(ioctlp->inDatap, 0);
1874 if (!cellp) return CM_ERROR_NOSUCHCELL;
1876 lock_ObtainMutex(&userp->mx);
1878 ucellp = cm_GetUCell(userp, cellp);
1880 lock_ReleaseMutex(&userp->mx);
1881 return CM_ERROR_NOMORETOKENS;
1884 if (ucellp->ticketp) {
1885 free(ucellp->ticketp);
1886 ucellp->ticketp = NULL;
1888 ucellp->flags &= ~CM_UCELLFLAG_RXKAD;
1891 lock_ReleaseMutex(&userp->mx);
1893 cm_ResetACLCache(userp);
1898 long cm_IoctlDelAllToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
1902 lock_ObtainMutex(&userp->mx);
1904 for (ucellp = userp->cellInfop; ucellp; ucellp = ucellp->nextp) {
1905 ucellp->flags &= ~CM_UCELLFLAG_RXKAD;
1909 lock_ReleaseMutex(&userp->mx);
1911 cm_ResetACLCache(userp);
1916 long cm_IoctlMakeSubmount(smb_ioctl_t *ioctlp, cm_user_t *userp)
1918 char afspath[MAX_PATH];
1921 int submountDataSize;
1924 int nextAutoSubmount;
1926 cm_SkipIoctlPath(ioctlp);
1928 /* Serialize this one, to prevent simultaneous mods
1931 lock_ObtainMutex(&cm_Afsdsbmt_Lock);
1933 /* Parse the input parameters--first the required afs path,
1934 * then the requested submount name (which may be "").
1936 cm_NormalizeAfsPath (afspath, ioctlp->inDatap);
1937 submountreqp = ioctlp->inDatap + (strlen(ioctlp->inDatap)+1);
1939 /* If the caller supplied a suggested submount name, see if
1940 * that submount name is in use... if so, the submount's path
1941 * has to match our path.
1943 if (submountreqp && *submountreqp) {
1944 char submountPathNormalized[MAX_PATH];
1945 char submountPath[MAX_PATH];
1946 int submountPathLen;
1948 submountPathLen = GetPrivateProfileString("AFS Submounts",
1949 submountreqp, "", submountPath,
1950 sizeof(submountPath), "afsdsbmt.ini");
1952 if ((submountPathLen == 0) ||
1953 (submountPathLen == sizeof(submountPath) - 1)) {
1955 /* The suggested submount name isn't in use now--
1956 * so we can safely map the requested submount name
1957 * to the supplied path. Remember not to write the
1958 * leading "/afs" when writing out the submount.
1960 WritePrivateProfileString("AFS Submounts",
1962 (strlen(&afspath[strlen(cm_mountRoot)])) ?
1963 &afspath[strlen(cm_mountRoot)]:"/",
1966 strcpy(ioctlp->outDatap, submountreqp);
1967 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
1968 lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
1972 /* The suggested submount name is already in use--if the
1973 * supplied path matches the submount's path, we can still
1974 * use the suggested submount name.
1976 cm_NormalizeAfsPath (submountPathNormalized, submountPath);
1977 if (!strcmp (submountPathNormalized, afspath)) {
1978 strcpy(ioctlp->outDatap, submountreqp);
1979 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
1980 lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
1985 /* At this point, the user either didn't request a particular
1986 * submount name, or that submount name couldn't be used.
1987 * Look through afsdsbmt.ini to see if there are any submounts
1988 * already associated with the specified path. The first
1989 * step in doing that search is to load the AFS Submounts
1990 * section of afsdsbmt.ini into memory.
1993 submountDataSize = 1024;
1994 submountData = malloc (submountDataSize);
1996 for (iteration = 0; iteration < 5; ++iteration) {
1999 sectionSize = GetPrivateProfileString("AFS Submounts",
2000 NULL, "", submountData,
2001 submountDataSize, "afsdsbmt.ini");
2002 if (sectionSize < submountDataSize-2)
2005 free (submountData);
2006 submountDataSize *= 2;
2007 submountData = malloc (submountDataSize);
2010 /* Having obtained a list of all available submounts, start
2011 * searching that list for a path which matches the requested
2012 * AFS path. We'll also keep track of the highest "auto15"/"auto47"
2013 * submount, in case we need to add a new one later.
2016 nextAutoSubmount = 1;
2018 for (submountName = submountData;
2019 submountName && *submountName;
2020 submountName += 1+strlen(submountName)) {
2022 char submountPathNormalized[MAX_PATH];
2023 char submountPath[MAX_PATH] = "";
2024 int submountPathLen;
2026 /* If this is an Auto### submount, remember its ### value */
2028 if ((!strnicmp (submountName, "auto", 4)) &&
2029 (isdigit (submountName[strlen("auto")]))) {
2030 int thisAutoSubmount;
2031 thisAutoSubmount = atoi (&submountName[strlen("auto")]);
2032 nextAutoSubmount = max (nextAutoSubmount,
2033 thisAutoSubmount+1);
2036 /* We have the name of a submount in the AFS Submounts
2037 * section; read that entry to find out what path it
2040 submountPathLen = GetPrivateProfileString("AFS Submounts",
2041 submountName, "", submountPath,
2042 sizeof(submountPath), "afsdsbmt.ini");
2044 if ((submountPathLen == 0) ||
2045 (submountPathLen == sizeof(submountPath) - 1)) {
2049 /* See if the path for this submount matches the path
2050 * that our caller specified. If so, we can return
2053 cm_NormalizeAfsPath (submountPathNormalized, submountPath);
2054 if (!strcmp (submountPathNormalized, afspath)) {
2056 strcpy(ioctlp->outDatap, submountName);
2057 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
2058 free (submountData);
2059 lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
2065 free (submountData);
2067 /* We've been through the entire list of existing submounts, and
2068 * didn't find any which matched the specified path. So, we'll
2069 * just have to add one. Remember not to write the leading "/afs"
2070 * when writing out the submount.
2073 sprintf(ioctlp->outDatap, "auto%ld", nextAutoSubmount);
2075 WritePrivateProfileString("AFS Submounts", ioctlp->outDatap,
2076 (strlen(&afspath[lstrlen(cm_mountRoot)])) ?
2077 &afspath[lstrlen(cm_mountRoot)]:"/",
2080 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
2081 lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
2085 long cm_IoctlGetRxkcrypt(smb_ioctl_t *ioctlp, cm_user_t *userp)
2087 memcpy(ioctlp->outDatap, &cryptall, sizeof(cryptall));
2088 ioctlp->outDatap += sizeof(cryptall);
2093 long cm_IoctlSetRxkcrypt(smb_ioctl_t *ioctlp, cm_user_t *userp)
2095 cm_SkipIoctlPath(ioctlp);
2097 memcpy(&cryptall, ioctlp->inDatap, sizeof(cryptall));
2103 extern int afsd_shutdown(int);
2104 extern int afs_shutdown;
2106 long cm_IoctlShutdown(smb_ioctl_t *ioctlp, cm_user_t *userp) {
2107 afs_shutdown = 1; /* flag to shut down */
2112 long cm_IoctlGetSMBName(smb_ioctl_t *ioctlp, cm_user_t *userp)
2114 smb_user_t *uidp = ioctlp->uidp;
2116 if (uidp && uidp->unp) {
2117 memcpy(ioctlp->outDatap, uidp->unp->name, strlen(uidp->unp->name));
2118 ioctlp->outDatap += strlen(uidp->unp->name);
2125 * functions to dump contents of various structures.
2126 * In debug build (linked with crt debug library) will dump allocated but not freed memory
2128 extern int cm_DumpSCache(FILE *outputFile, char *cookie);
2129 extern int cm_DumpBufHashTable(FILE *outputFile, char *cookie);
2130 extern int smb_DumpVCP(FILE *outputFile, char *cookie);
2132 long cm_IoctlMemoryDump(struct smb_ioctl *ioctlp, struct cm_user *userp)
2136 char logfileName[MAX_PATH+1];
2140 static _CrtMemState memstate;
2143 cm_SkipIoctlPath(ioctlp);
2144 memcpy(&inValue, ioctlp->inDatap, sizeof(long));
2148 strncpy(logfileName, getenv("TEMP"), MAX_PATH);
2149 logfileName[MAX_PATH] = '\0';
2153 GetWindowsDirectory(logfileName, sizeof(logfileName));
2155 strncat(logfileName, "\\afsd_alloc.log", sizeof(logfileName));
2157 hLogFile = CreateFile(logfileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
2163 memcpy(ioctlp->outDatap, &inValue, sizeof(long));
2164 ioctlp->outDatap += sizeof(long);
2169 SetFilePointer(hLogFile, 0, NULL, FILE_END);
2171 cookie = inValue ? "b" : "e";
2177 _CrtMemCheckpoint(&memstate);
2181 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
2182 _CrtSetReportFile(_CRT_WARN, hLogFile);
2183 _CrtMemDumpAllObjectsSince(&memstate);
2187 /* dump all interesting data */
2188 cm_DumpSCache(hLogFile, cookie);
2189 cm_DumpBufHashTable(hLogFile, cookie);
2190 smb_DumpVCP(hLogFile, cookie);
2192 CloseHandle(hLogFile);
2194 memcpy(ioctlp->outDatap, &inValue, sizeof(long));
2195 ioctlp->outDatap += sizeof(long);