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;
55 void cm_InitIoctl(void)
57 lock_InitializeMutex(&cm_Afsdsbmt_Lock, "AFSDSBMT.INI Access Lock");
60 long cm_FlushFile(cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp)
64 lock_ObtainWrite(&scp->bufCreateLock);
65 code = buf_FlushCleanPages(scp, userp, reqp);
67 lock_ObtainMutex(&scp->mx);
68 scp->cbServerp = NULL;
70 lock_ReleaseMutex(&scp->mx);
72 lock_ReleaseWrite(&scp->bufCreateLock);
79 * cm_ResetACLCache -- invalidate ACL info for a user that has just
80 * obtained or lost tokens
82 void cm_ResetACLCache(cm_user_t *userp)
87 lock_ObtainWrite(&cm_scacheLock);
88 for (hash=0; hash < cm_hashTableSize; hash++) {
89 for (scp=cm_hashTablep[hash]; scp; scp=scp->nextp) {
91 lock_ReleaseWrite(&cm_scacheLock);
92 lock_ObtainMutex(&scp->mx);
93 cm_InvalidateACLUser(scp, userp);
94 lock_ReleaseMutex(&scp->mx);
95 lock_ObtainWrite(&cm_scacheLock);
99 lock_ReleaseWrite(&cm_scacheLock);
103 * TranslateExtendedChars - This is a fix for TR 54482.
105 * If an extended character (80 - FF) is entered into a file
106 * or directory name in Windows, the character is translated
107 * into the OEM character map before being passed to us. Why
108 * this occurs is unknown. Our pioctl functions must match
109 * this translation for paths given via our own commands (like
110 * fs). If we do not do this, then we will try to perform an
111 * operation on a non-translated path, which we will fail to
112 * find, since the path was created with the translated chars.
113 * This function performs the required translation.
115 void TranslateExtendedChars(char *str)
128 while (*p) *p++ &= 0x7f; /* turn off high bit; probably not right */
132 /* parse the passed-in file name and do a namei on it. If we fail,
133 * return an error code, otherwise return the vnode located in *scpp.
135 long cm_ParseIoctlPath(smb_ioctl_t *ioctlp, cm_user_t *userp, cm_req_t *reqp,
138 extern char cm_NetbiosName[];
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 != '\\'; 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 != '\\'; 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);
210 if (code) return code;
212 code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
213 userp, NULL, reqp, scpp);
214 if (code) return code;
217 code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
218 CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
219 userp, ioctlp->tidPathp, reqp, &substRootp);
220 if (code) return code;
222 code = cm_NameI(substRootp, relativePath, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
223 userp, NULL, reqp, scpp);
224 if (code) return code;
227 /* # of bytes of path */
228 code = strlen(ioctlp->inDatap) + 1;
229 ioctlp->inDatap += code;
231 /* This is usually nothing, but for StatMountPoint it is the file name. */
232 TranslateExtendedChars(ioctlp->inDatap);
234 /* and return success */
238 void cm_SkipIoctlPath(smb_ioctl_t *ioctlp)
242 temp = strlen(ioctlp->inDatap) + 1;
243 ioctlp->inDatap += temp;
247 /* format the specified path to look like "/afs/<cellname>/usr", by
248 * adding "/afs" (if necessary) in front, changing any \'s to /'s, and
249 * removing any trailing "/"'s. One weirdo caveat: "/afs" will be
250 * intentionally returned as "/afs/"--this makes submount manipulation
251 * easier (because we can always jump past the initial "/afs" to find
252 * the AFS path that should be written into afsdsbmt.ini).
254 void cm_NormalizeAfsPath (char *outpathp, char *inpathp)
257 char bslash_mountRoot[256];
259 strncpy(bslash_mountRoot, cm_mountRoot, sizeof(bslash_mountRoot) - 1);
260 bslash_mountRoot[0] = '\\';
262 if (!strnicmp (inpathp, cm_mountRoot, strlen(cm_mountRoot)))
263 lstrcpy (outpathp, inpathp);
264 else if (!strnicmp (inpathp, bslash_mountRoot, strlen(bslash_mountRoot)))
265 lstrcpy (outpathp, inpathp);
266 else if ((inpathp[0] == '/') || (inpathp[0] == '\\'))
267 sprintf (outpathp, "%s%s", cm_mountRoot, inpathp);
268 else // inpathp looks like "<cell>/usr"
269 sprintf (outpathp, "%s/%s", cm_mountRoot, inpathp);
271 for (cp = outpathp; *cp != 0; ++cp) {
276 if (strlen(outpathp) && (outpathp[strlen(outpathp)-1] == '/')) {
277 outpathp[strlen(outpathp)-1] = 0;
280 if (!strcmpi (outpathp, cm_mountRoot)) {
281 strcpy (outpathp, cm_mountRoot);
285 /* parse the passed-in file name and do a namei on its parent. If we fail,
286 * return an error code, otherwise return the vnode located in *scpp.
288 long cm_ParseIoctlParent(smb_ioctl_t *ioctlp, cm_user_t *userp, cm_req_t *reqp,
289 cm_scache_t **scpp, char *leafp)
294 cm_scache_t *substRootp;
296 strcpy(tbuffer, ioctlp->inDatap);
297 tp = strrchr(tbuffer, '\\');
298 jp = strrchr(tbuffer, '/');
301 else if (jp && (tp - tbuffer) < (jp - tbuffer))
304 strcpy(tbuffer, "\\");
305 if (leafp) strcpy(leafp, ioctlp->inDatap);
309 if (leafp) strcpy(leafp, tp+1);
312 code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
313 CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
314 userp, ioctlp->tidPathp, reqp, &substRootp);
315 if (code) return code;
317 code = cm_NameI(substRootp, tbuffer, CM_FLAG_FOLLOW,
318 userp, NULL, reqp, scpp);
319 if (code) return code;
321 /* # of bytes of path */
322 code = strlen(ioctlp->inDatap) + 1;
323 ioctlp->inDatap += code;
325 /* and return success */
329 long cm_IoctlGetACL(smb_ioctl_t *ioctlp, cm_user_t *userp)
334 AFSFetchStatus fileStatus;
343 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
344 if (code) return code;
346 /* now make the get acl call */
347 fid.Volume = scp->fid.volume;
348 fid.Vnode = scp->fid.vnode;
349 fid.Unique = scp->fid.unique;
351 acl.AFSOpaque_val = ioctlp->outDatap;
352 acl.AFSOpaque_len = 0;
353 code = cm_Conn(&scp->fid, userp, &req, &connp);
356 code = RXAFS_FetchACL(connp->callp, &fid, &acl, &fileStatus, &volSync);
357 } while (cm_Analyze(connp, userp, &req, &scp->fid,
358 &volSync, NULL, code));
359 code = cm_MapRPCError(code, &req);
360 cm_ReleaseSCache(scp);
362 if (code) return code;
364 /* skip over return data */
365 tlen = strlen(ioctlp->outDatap) + 1;
366 ioctlp->outDatap += tlen;
368 /* and return success */
372 long cm_IoctlGetFileCellName(struct smb_ioctl *ioctlp, struct cm_user *userp)
381 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
382 if (code) return code;
384 cellp = cm_FindCellByID(scp->fid.cell);
386 strcpy(ioctlp->outDatap, cellp->namep);
387 ioctlp->outDatap += strlen(ioctlp->outDatap) + 1;
390 else code = CM_ERROR_NOSUCHCELL;
392 cm_ReleaseSCache(scp);
396 long cm_IoctlSetACL(struct smb_ioctl *ioctlp, struct cm_user *userp)
401 AFSFetchStatus fileStatus;
409 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
410 if (code) return code;
412 /* now make the get acl call */
413 fid.Volume = scp->fid.volume;
414 fid.Vnode = scp->fid.vnode;
415 fid.Unique = scp->fid.unique;
417 acl.AFSOpaque_val = ioctlp->inDatap;
418 acl.AFSOpaque_len = strlen(ioctlp->inDatap)+1;
419 code = cm_Conn(&scp->fid, userp, &req, &connp);
422 code = RXAFS_StoreACL(connp->callp, &fid, &acl, &fileStatus, &volSync);
423 } while (cm_Analyze(connp, userp, &req, &scp->fid,
424 &volSync, NULL, code));
425 code = cm_MapRPCError(code, &req);
427 /* invalidate cache info, since we just trashed the ACL cache */
428 lock_ObtainMutex(&scp->mx);
429 cm_DiscardSCache(scp);
430 lock_ReleaseMutex(&scp->mx);
432 cm_ReleaseSCache(scp);
437 long cm_IoctlFlushVolume(struct smb_ioctl *ioctlp, struct cm_user *userp)
441 unsigned long volume;
447 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
448 if (code) return code;
450 volume = scp->fid.volume;
451 cm_ReleaseSCache(scp);
453 lock_ObtainWrite(&cm_scacheLock);
454 for(i=0; i<cm_hashTableSize; i++) {
455 for(scp = cm_hashTablep[i]; scp; scp = scp->nextp) {
456 if (scp->fid.volume == volume) {
458 lock_ReleaseWrite(&cm_scacheLock);
460 /* now flush the file */
461 cm_FlushFile(scp, userp, &req);
463 lock_ObtainWrite(&cm_scacheLock);
468 lock_ReleaseWrite(&cm_scacheLock);
473 long cm_IoctlFlushFile(struct smb_ioctl *ioctlp, struct cm_user *userp)
481 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
482 if (code) return code;
484 cm_FlushFile(scp, userp, &req);
485 cm_ReleaseSCache(scp);
490 long cm_IoctlSetVolumeStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
494 char offLineMsg[256];
498 AFSFetchVolumeStatus volStat;
499 AFSStoreVolumeStatus storeStat;
507 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
508 if (code) return code;
510 cellp = cm_FindCellByID(scp->fid.cell);
513 if (scp->flags & CM_SCACHEFLAG_RO) {
514 cm_ReleaseSCache(scp);
515 return CM_ERROR_READONLY;
518 code = cm_GetVolumeByID(cellp, scp->fid.volume, userp, &req, &tvp);
520 cm_ReleaseSCache(scp);
524 /* Copy the junk out, using cp as a roving pointer. */
525 cp = ioctlp->inDatap;
526 memcpy((char *)&volStat, cp, sizeof(AFSFetchVolumeStatus));
527 cp += sizeof(AFSFetchVolumeStatus);
529 cp += strlen(volName)+1;
530 strcpy(offLineMsg, cp);
531 cp += strlen(offLineMsg)+1;
534 if (volStat.MinQuota != -1) {
535 storeStat.MinQuota = volStat.MinQuota;
536 storeStat.Mask |= AFS_SETMINQUOTA;
538 if (volStat.MaxQuota != -1) {
539 storeStat.MaxQuota = volStat.MaxQuota;
540 storeStat.Mask |= AFS_SETMAXQUOTA;
544 code = cm_Conn(&scp->fid, userp, &req, &tcp);
547 code = RXAFS_SetVolumeStatus(tcp->callp, scp->fid.volume,
548 &storeStat, volName, offLineMsg, motd);
549 } while (cm_Analyze(tcp, userp, &req, &scp->fid, NULL, NULL, code));
550 code = cm_MapRPCError(code, &req);
552 /* return on failure */
553 cm_ReleaseSCache(scp);
558 /* we are sending parms back to make compat. with prev system. should
559 * change interface later to not ask for current status, just set
562 cp = ioctlp->outDatap;
563 memcpy(cp, (char *)&volStat, sizeof(VolumeStatus));
564 cp += sizeof(VolumeStatus);
566 cp += strlen(volName)+1;
567 strcpy(cp, offLineMsg);
568 cp += strlen(offLineMsg)+1;
570 cp += strlen(motd)+1;
572 /* now return updated return data pointer */
573 ioctlp->outDatap = cp;
578 long cm_IoctlGetVolumeStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
582 char offLineMsg[256];
586 AFSFetchVolumeStatus volStat;
595 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
596 if (code) return code;
599 OfflineMsg = offLineMsg;
602 code = cm_Conn(&scp->fid, userp, &req, &tcp);
605 code = RXAFS_GetVolumeStatus(tcp->callp, scp->fid.volume,
606 &volStat, &Name, &OfflineMsg, &MOTD);
607 } while (cm_Analyze(tcp, userp, &req, &scp->fid, NULL, NULL, code));
608 code = cm_MapRPCError(code, &req);
610 cm_ReleaseSCache(scp);
611 if (code) return code;
613 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
614 cp = ioctlp->outDatap;
615 memcpy(cp, (char *)&volStat, sizeof(AFSFetchVolumeStatus));
616 cp += sizeof(AFSFetchVolumeStatus);
618 cp += strlen(volName)+1;
619 strcpy(cp, offLineMsg);
620 cp += strlen(offLineMsg)+1;
622 cp += strlen(motd)+1;
624 /* return new size */
625 ioctlp->outDatap = cp;
630 long cm_IoctlWhereIs(struct smb_ioctl *ioctlp, struct cm_user *userp)
636 cm_serverRef_t *tsrp;
638 unsigned long volume;
644 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
645 if (code) return code;
647 volume = scp->fid.volume;
649 cellp = cm_FindCellByID(scp->fid.cell);
652 cm_ReleaseSCache(scp);
654 code = cm_GetVolumeByID(cellp, volume, userp, &req, &tvp);
655 if (code) return code;
657 cp = ioctlp->outDatap;
659 lock_ObtainMutex(&tvp->mx);
660 tsrp = cm_GetVolServers(tvp, volume);
661 lock_ObtainRead(&cm_serverLock);
664 memcpy(cp, (char *)&tsp->addr.sin_addr.s_addr, sizeof(long));
668 lock_ReleaseRead(&cm_serverLock);
669 lock_ReleaseMutex(&tvp->mx);
671 /* still room for terminating NULL, add it on */
672 volume = 0; /* reuse vbl */
673 memcpy(cp, (char *)&volume, sizeof(long));
676 ioctlp->outDatap = cp;
681 long cm_IoctlStatMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp)
691 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
692 if (code) return code;
694 cp = ioctlp->inDatap;
696 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
697 cm_ReleaseSCache(dscp);
698 if (code) return code;
700 lock_ObtainMutex(&scp->mx);
702 /* now check that this is a real mount point */
703 if (scp->fileType != CM_SCACHETYPE_MOUNTPOINT) {
704 lock_ReleaseMutex(&scp->mx);
705 cm_ReleaseSCache(scp);
706 return CM_ERROR_INVAL;
709 code = cm_ReadMountPoint(scp, userp, &req);
711 cp = ioctlp->outDatap;
712 strcpy(cp, scp->mountPointStringp);
713 cp += strlen(cp) + 1;
714 ioctlp->outDatap = cp;
716 lock_ReleaseMutex(&scp->mx);
717 cm_ReleaseSCache(scp);
722 long cm_IoctlDeleteMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp)
732 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
733 if (code) return code;
735 cp = ioctlp->inDatap;
737 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
739 /* if something went wrong, bail out now */
744 lock_ObtainMutex(&scp->mx);
745 code = cm_SyncOp(scp, NULL, userp, &req, 0,
746 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
748 lock_ReleaseMutex(&scp->mx);
749 cm_ReleaseSCache(scp);
753 /* now check that this is a real mount point */
754 if (scp->fileType != CM_SCACHETYPE_MOUNTPOINT) {
755 lock_ReleaseMutex(&scp->mx);
756 cm_ReleaseSCache(scp);
757 code = CM_ERROR_INVAL;
761 /* time to make the RPC, so drop the lock */
762 lock_ReleaseMutex(&scp->mx);
763 cm_ReleaseSCache(scp);
765 /* easier to do it this way */
766 code = cm_Unlink(dscp, cp, userp, &req);
767 if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
768 smb_NotifyChange(FILE_ACTION_REMOVED,
769 FILE_NOTIFY_CHANGE_DIR_NAME,
770 dscp, cp, NULL, TRUE);
773 cm_ReleaseSCache(dscp);
777 long cm_IoctlCheckServers(struct smb_ioctl *ioctlp, struct cm_user *userp)
787 cm_SkipIoctlPath(ioctlp); /* we don't care about the path */
788 tp = ioctlp->inDatap;
791 memcpy(&temp, tp, sizeof(temp));
792 if (temp == 0x12345678) { /* For afs3.3 version */
793 memcpy(&csi, tp, sizeof(csi));
794 if (csi.tinterval >= 0) {
795 cp = ioctlp->outDatap;
796 memcpy(cp, (char *)&cm_daemonCheckInterval, sizeof(long));
797 ioctlp->outDatap += sizeof(long);
798 if (csi.tinterval > 0) {
799 if (!smb_SUser(userp))
800 return CM_ERROR_NOACCESS;
801 cm_daemonCheckInterval = csi.tinterval;
809 } else { /* For pre afs3.3 versions */
810 memcpy((char *)&temp, ioctlp->inDatap, sizeof(long));
811 ioctlp->inDatap = cp = ioctlp->inDatap + sizeof(long);
812 if (cp - ioctlp->inAllocp < ioctlp->inCopied) /* still more data available */
817 * 1: fast check, don't contact servers.
818 * 2: local cell only.
821 /* have cell name, too */
822 cellp = cm_GetCell(cp, 0);
823 if (!cellp) return CM_ERROR_NOSUCHCELL;
825 else cellp = (cm_cell_t *) 0;
826 if (!cellp && (temp & 2)) {
828 cellp = cm_FindCellByID(1);
830 if (!(temp & 1)) { /* if not fast, call server checker routine */
831 /* check down servers */
832 cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS | CM_FLAG_CHECKUPSERVERS,
836 /* now return the current down server list */
837 cp = ioctlp->outDatap;
838 lock_ObtainRead(&cm_serverLock);
839 for(tsp = cm_allServersp; tsp; tsp=tsp->allNextp) {
840 if (cellp && tsp->cellp != cellp) continue; /* cell spec'd and wrong */
841 if ((tsp->flags & CM_SERVERFLAG_DOWN)
842 && tsp->type == CM_SERVER_FILE) {
843 memcpy(cp, (char *)&tsp->addr.sin_addr.s_addr, sizeof(long));
847 lock_ReleaseRead(&cm_serverLock);
849 ioctlp->outDatap = cp;
853 long cm_IoctlGag(struct smb_ioctl *ioctlp, struct cm_user *userp)
855 /* we don't print anything superfluous, so we don't support the gag call */
856 return CM_ERROR_INVAL;
859 long cm_IoctlCheckVolumes(struct smb_ioctl *ioctlp, struct cm_user *userp)
865 long cm_IoctlSetCacheSize(struct smb_ioctl *ioctlp, struct cm_user *userp)
870 cm_SkipIoctlPath(ioctlp);
872 memcpy(&temp, ioctlp->inDatap, sizeof(temp));
873 if (temp == 0) temp = buf_nOrigBuffers;
875 /* temp is in 1K units, convert to # of buffers */
876 temp = temp / (buf_bufferSize / 1024);
879 /* now adjust the cache size */
880 code = buf_SetNBuffers(temp);
885 long cm_IoctlTraceControl(struct smb_ioctl *ioctlp, struct cm_user *userp)
889 cm_SkipIoctlPath(ioctlp);
891 memcpy(&inValue, ioctlp->inDatap, sizeof(long));
895 afsd_ForceTrace(FALSE);
899 /* set tracing value to low order bit */
900 if ((inValue & 1) == 0) {
901 /* disable tracing */
902 osi_LogDisable(afsd_logp);
906 osi_LogEnable(afsd_logp);
910 /* see if we're supposed to do a reset, too */
912 osi_LogReset(afsd_logp);
915 /* and copy out tracing flag */
916 inValue = afsd_logp->enabled; /* use as a temp vbl */
917 memcpy(ioctlp->outDatap, &inValue, sizeof(long));
918 ioctlp->outDatap += sizeof(long);
922 long cm_IoctlGetCacheParms(struct smb_ioctl *ioctlp, struct cm_user *userp)
924 cm_cacheParms_t parms;
926 memset(&parms, 0, sizeof(parms));
928 /* first we get, in 1K units, the cache size */
929 parms.parms[0] = buf_nbuffers * (buf_bufferSize / 1024);
931 /* and then the actual # of buffers in use (not in the free list, I guess,
932 * will be what we do).
934 parms.parms[1] = (buf_nbuffers - buf_CountFreeList()) * (buf_bufferSize / 1024);
936 memcpy(ioctlp->outDatap, &parms, sizeof(parms));
937 ioctlp->outDatap += sizeof(parms);
942 long cm_IoctlGetCell(struct smb_ioctl *ioctlp, struct cm_user *userp)
947 cm_serverRef_t *serverRefp;
948 cm_server_t *serverp;
954 cm_SkipIoctlPath(ioctlp);
956 tp = ioctlp->inDatap;
958 memcpy((char *)&whichCell, tp, sizeof(long));
961 /* see if more than one long passed in, ignoring the null pathname (the -1) */
962 if (ioctlp->inCopied-1 > sizeof(long)) {
963 memcpy((char *)&magic, tp, sizeof(long));
966 lock_ObtainRead(&cm_cellLock);
967 for(tcellp = cm_allCellsp; tcellp; tcellp = tcellp->nextp) {
968 if (whichCell == 0) break;
971 lock_ReleaseRead(&cm_cellLock);
975 cp = ioctlp->outDatap;
977 if (magic == 0x12345678) {
978 memcpy(cp, (char *)&magic, sizeof(long));
981 memset(cp, 0, max * sizeof(long));
983 lock_ObtainRead(&cm_serverLock); /* for going down server list */
984 serverRefp = tcellp->vlServersp;
985 for(i=0; i<max; i++) {
986 if (!serverRefp) break;
987 serverp = serverRefp->server;
988 memcpy(cp, &serverp->addr.sin_addr.s_addr, sizeof(long));
990 serverRefp = serverRefp->next;
992 lock_ReleaseRead(&cm_serverLock);
993 cp = basep + max * sizeof(afs_int32);
994 strcpy(cp, tcellp->namep);
995 cp += strlen(tcellp->namep)+1;
996 ioctlp->outDatap = cp;
999 if (tcellp) return 0;
1000 else return CM_ERROR_NOMORETOKENS; /* mapped to EDOM */
1003 extern long cm_AddCellProc(void *rockp, struct sockaddr_in *addrp, char *namep);
1005 long cm_IoctlNewCell(struct smb_ioctl *ioctlp, struct cm_user *userp)
1007 /* NT cache manager will read cell information from afsdcell.ini each time
1008 * cell is accessed. So, this call is necessary only if list of server for a cell
1009 * changes (or IP addresses of cell servers changes).
1010 * All that needs to be done is to refresh server information for all cells that
1011 * are already loaded.
1013 * cell list will be cm_CellLock and cm_ServerLock will be held for write.
1019 cm_SkipIoctlPath(ioctlp);
1020 lock_ObtainWrite(&cm_cellLock);
1022 for(cp = cm_allCellsp; cp; cp=cp->nextp)
1026 /* delete all previous server lists - cm_FreeServerList will ask for write on cm_ServerLock*/
1027 cm_FreeServerList(&cp->vlServersp);
1028 cp->vlServersp = NULL;
1029 code = cm_SearchCellFile(cp->namep, cp->namep, cm_AddCellProc, cp);
1031 #ifdef AFS_AFSDB_ENV
1032 if (cm_dnsEnabled) {
1034 code = cm_SearchCellByDNS(cp->namep, cp->namep, &ttl, cm_AddCellProc, cp);
1036 if ( cm_allCellsp == cp )
1037 cm_allCellsp = cp->nextp;
1039 for(tcp = cm_allCellsp; tcp->nextp; tcp=tcp->nextp) {
1040 if ( tcp->nextp == cp ) {
1041 tcp->nextp = cp->nextp;
1047 lock_FinalizeMutex(&cp->mx);
1050 else { /* got cell from DNS */
1051 cp->flags |= CM_CELLFLAG_DNS;
1052 cp->timeout = time(0) + ttl;
1055 #endif /* AFS_AFSDB_ENV */
1064 cm_RandomizeServer(&cp->vlServersp);
1067 lock_ReleaseWrite(&cm_cellLock);
1071 long cm_IoctlGetWsCell(smb_ioctl_t *ioctlp, cm_user_t *userp)
1073 /* if we don't know our default cell, return failure */
1074 if (cm_rootCellp == NULL) {
1075 return CM_ERROR_NOSUCHCELL;
1078 /* return the default cellname to the caller */
1079 strcpy(ioctlp->outDatap, cm_rootCellp->namep);
1080 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
1086 long cm_IoctlSysName(struct smb_ioctl *ioctlp, struct cm_user *userp)
1091 cm_SkipIoctlPath(ioctlp);
1093 memcpy(&setSysName, ioctlp->inDatap, sizeof(long));
1094 ioctlp->inDatap += sizeof(long);
1097 strcpy(cm_sysName, ioctlp->inDatap);
1100 /* return the sysname to the caller */
1101 setSysName = 1; /* really means "found sys name */
1102 cp = ioctlp->outDatap;
1103 memcpy(cp, &setSysName, sizeof(long));
1104 cp += sizeof(long); /* skip found flag */
1105 strcpy(cp, cm_sysName);
1106 cp += strlen(cp) + 1; /* skip name and terminating null char */
1107 ioctlp->outDatap = cp;
1114 long cm_IoctlGetCellStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
1119 cm_SkipIoctlPath(ioctlp);
1121 cellp = cm_GetCell(ioctlp->inDatap, 0);
1122 if (!cellp) return CM_ERROR_NOSUCHCELL;
1125 lock_ObtainMutex(&cellp->mx);
1126 if (cellp->flags & CM_CELLFLAG_SUID)
1127 temp |= CM_SETCELLFLAG_SUID;
1128 lock_ReleaseMutex(&cellp->mx);
1130 /* now copy out parm */
1131 memcpy(ioctlp->outDatap, &temp, sizeof(long));
1132 ioctlp->outDatap += sizeof(long);
1137 long cm_IoctlSetCellStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
1142 cm_SkipIoctlPath(ioctlp);
1144 cellp = cm_GetCell(ioctlp->inDatap + 2*sizeof(long), 0);
1145 if (!cellp) return CM_ERROR_NOSUCHCELL;
1147 memcpy((char *)&temp, ioctlp->inDatap, sizeof(long));
1149 lock_ObtainMutex(&cellp->mx);
1150 if (temp & CM_SETCELLFLAG_SUID)
1151 cellp->flags |= CM_CELLFLAG_SUID;
1153 cellp->flags &= ~CM_CELLFLAG_SUID;
1154 lock_ReleaseMutex(&cellp->mx);
1159 long cm_IoctlSetSPrefs(struct smb_ioctl *ioctlp, struct cm_user *userp)
1161 cm_SSetPref_t *spin; /* input */
1162 cm_SPref_t *srvin; /* one input component */
1164 int i, vlonly, noServers, type;
1165 struct sockaddr_in tmp;
1166 unsigned short rank;
1168 cm_SkipIoctlPath(ioctlp); /* we don't care about the path */
1170 spin = (cm_SSetPref_t *)ioctlp->inDatap;
1171 noServers = spin->num_servers;
1172 vlonly = spin->flags;
1174 type = CM_SERVER_VLDB;
1176 type = CM_SERVER_FILE;
1178 for ( i=0; i < noServers; i++)
1180 srvin = &(spin->servers[i]);
1181 rank = srvin->rank + (rand() & 0x000f);
1182 tmp.sin_addr = srvin->host;
1183 tmp.sin_family = AF_INET;
1185 tsp = cm_FindServer(&tmp, type);
1186 if ( tsp ) /* an existing server - ref count increased */
1188 tsp->ipRank = rank; /* no need to protect by mutex*/
1190 if ( type == CM_SERVER_FILE) /* fileserver */
1192 /* find volumes which might have RO copy
1193 /* on server and change the ordering of
1195 cm_ChangeRankVolume(tsp);
1199 /* set preferences for an existing vlserver */
1200 cm_ChangeRankCellVLServer(tsp);
1202 cm_PutServer(tsp); /* decrease refcount */
1204 else /* add a new server without a cell */
1206 tsp = cm_NewServer(&tmp, type, NULL); /* refcount = 1 */
1213 long cm_IoctlGetSPrefs(struct smb_ioctl *ioctlp, struct cm_user *userp)
1215 cm_SPrefRequest_t *spin; /* input */
1216 cm_SPrefInfo_t *spout; /* output */
1217 cm_SPref_t *srvout; /* one output component */
1219 int i, vlonly, noServers;
1221 cm_SkipIoctlPath(ioctlp); /* we don't care about the path */
1223 spin = (cm_SPrefRequest_t *)ioctlp->inDatap;
1224 spout = (cm_SPrefInfo_t *) ioctlp->outDatap;
1225 srvout = spout->servers;
1226 noServers = spin->num_servers;
1227 vlonly = spin->flags & CM_SPREF_VLONLY;
1228 spout->num_servers = 0;
1230 lock_ObtainRead(&cm_serverLock); /* get server lock */
1232 for(tsp=cm_allServersp, i=0; tsp && noServers; tsp=tsp->allNextp,i++){
1233 if (spin->offset > i) {
1234 continue; /* catch up to where we left off */
1237 if ( vlonly && (tsp->type == CM_SERVER_FILE) )
1238 continue; /* ignore fileserver for -vlserver option*/
1239 if ( !vlonly && (tsp->type == CM_SERVER_VLDB) )
1240 continue; /* ignore vlservers */
1242 srvout->host = tsp->addr.sin_addr;
1243 srvout->rank = tsp->ipRank;
1245 spout->num_servers++;
1248 lock_ReleaseRead(&cm_serverLock); /* release server lock */
1250 if ( tsp ) /* we ran out of space in the output buffer */
1251 spout->next_offset = i;
1253 spout->next_offset = 0;
1254 ioctlp->outDatap += sizeof(cm_SPrefInfo_t) +
1255 (spout->num_servers -1 ) * sizeof(cm_SPref_t) ;
1259 long cm_IoctlStoreBehind(struct smb_ioctl *ioctlp, struct cm_user *userp)
1261 /* we ignore default asynchrony since we only have one way
1262 * of doing this today.
1267 long cm_IoctlCreateMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp)
1283 code = cm_ParseIoctlParent(ioctlp, userp, &req, &dscp, leaf);
1284 if (code) return code;
1286 /* Translate chars for the mount point name */
1287 TranslateExtendedChars(leaf);
1290 * The fs command allows the user to specify partial cell names on NT. These must
1291 * be expanded to the full cell name for mount points so that the mount points will
1292 * work on UNIX clients.
1295 /* Extract the possibly partial cell name */
1296 strcpy(cell, ioctlp->inDatap + 1); /* Skip the mp type character */
1298 if (cp = strchr(cell, ':')) {
1299 /* Extract the volume name */
1301 strcpy(volume, cp + 1);
1303 /* Get the full name for this cell */
1304 code = cm_SearchCellFile(cell, fullCell, 0, 0);
1305 #ifdef AFS_AFSDB_ENV
1306 if (code && cm_dnsEnabled)
1307 code = cm_SearchCellByDNS(cell, fullCell, &ttl, 0, 0);
1310 return CM_ERROR_NOSUCHCELL;
1312 sprintf(mpInfo, "%c%s:%s", *ioctlp->inDatap, fullCell, volume);
1314 /* No cell name specified */
1315 strcpy(mpInfo, ioctlp->inDatap);
1318 #ifdef AFS_FREELANCE_CLIENT
1319 if (cm_freelanceEnabled && dscp == cm_rootSCachep) {
1320 /* we are adding the mount point to the root dir., so call
1321 the freelance code to do the add. */
1322 code = cm_FreelanceAddMount(leaf, fullCell, volume, NULL);
1326 /* create the symlink with mode 644. The lack of X bits tells
1327 * us that it is a mount point.
1329 tattr.mask = CM_ATTRMASK_UNIXMODEBITS | CM_ATTRMASK_CLIENTMODTIME;
1330 tattr.unixModeBits = 0644;
1331 tattr.clientModTime = time(NULL);
1333 code = cm_SymLink(dscp, leaf, mpInfo, 0, &tattr, userp, &req);
1334 if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
1335 smb_NotifyChange(FILE_ACTION_ADDED,
1336 FILE_NOTIFY_CHANGE_DIR_NAME,
1337 dscp, leaf, NULL, TRUE);
1339 cm_ReleaseSCache(dscp);
1343 long cm_IoctlSymlink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1354 code = cm_ParseIoctlParent(ioctlp, userp, &req, &dscp, leaf);
1355 if (code) return code;
1357 /* Translate chars for the link name */
1358 TranslateExtendedChars(leaf);
1360 /* Translate chars for the linked to name */
1361 TranslateExtendedChars(ioctlp->inDatap);
1363 cp = ioctlp->inDatap; /* contents of link */
1365 /* Create symlink with mode 0755. */
1366 tattr.mask = CM_ATTRMASK_UNIXMODEBITS;
1367 tattr.unixModeBits = 0755;
1369 code = cm_SymLink(dscp, leaf, cp, 0, &tattr, userp, &req);
1370 if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
1371 smb_NotifyChange(FILE_ACTION_ADDED,
1372 FILE_NOTIFY_CHANGE_FILE_NAME
1373 | FILE_NOTIFY_CHANGE_DIR_NAME,
1374 dscp, leaf, NULL, TRUE);
1376 cm_ReleaseSCache(dscp);
1381 extern long cm_AssembleLink(cm_scache_t *linkScp, char *pathSuffixp,
1382 cm_scache_t **newRootScpp, cm_space_t **newSpaceBufferp,
1383 cm_user_t *userp, cm_req_t *reqp);
1385 long cm_IoctlListlink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1392 cm_scache_t *newRootScp;
1397 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
1398 if (code) return code;
1400 cp = ioctlp->inDatap;
1402 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
1403 cm_ReleaseSCache(dscp);
1404 if (code) return code;
1406 /* Check that it's a real symlink */
1407 if (scp->fileType != CM_SCACHETYPE_SYMLINK){
1408 cm_ReleaseSCache(scp);
1409 return CM_ERROR_INVAL;
1412 code = cm_AssembleLink(scp, "", &newRootScp, &spacep, userp, &req);
1413 cm_ReleaseSCache(scp);
1415 cp = ioctlp->outDatap;
1416 if (newRootScp != NULL) {
1417 strcpy(cp, cm_mountRoot);
1421 strcpy(cp, spacep->data);
1422 cp += strlen(cp) + 1;
1423 ioctlp->outDatap = cp;
1424 cm_FreeSpace(spacep);
1425 if (newRootScp != NULL)
1426 cm_ReleaseSCache(newRootScp);
1432 long cm_IoctlIslink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1433 {/*CHECK FOR VALID SYMLINK*/
1442 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
1443 if (code) return code;
1445 cp = ioctlp->inDatap;
1446 osi_LogEvent("cm_IoctlListlink",NULL," name[%s]",cp);
1448 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
1449 cm_ReleaseSCache(dscp);
1450 if (code) return code;
1452 /* Check that it's a real symlink */
1453 if (scp->fileType != CM_SCACHETYPE_SYMLINK)
1454 code = CM_ERROR_INVAL;
1455 cm_ReleaseSCache(scp);
1459 long cm_IoctlDeletelink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1469 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
1470 if (code) return code;
1472 cp = ioctlp->inDatap;
1474 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
1476 /* if something went wrong, bail out now */
1481 lock_ObtainMutex(&scp->mx);
1482 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1483 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1485 lock_ReleaseMutex(&scp->mx);
1486 cm_ReleaseSCache(scp);
1490 /* now check that this is a real symlink */
1491 if (scp->fileType != CM_SCACHETYPE_SYMLINK) {
1492 lock_ReleaseMutex(&scp->mx);
1493 cm_ReleaseSCache(scp);
1494 code = CM_ERROR_INVAL;
1498 /* time to make the RPC, so drop the lock */
1499 lock_ReleaseMutex(&scp->mx);
1500 cm_ReleaseSCache(scp);
1502 /* easier to do it this way */
1503 code = cm_Unlink(dscp, cp, userp, &req);
1504 if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
1505 smb_NotifyChange(FILE_ACTION_REMOVED,
1506 FILE_NOTIFY_CHANGE_FILE_NAME
1507 | FILE_NOTIFY_CHANGE_DIR_NAME,
1508 dscp, cp, NULL, TRUE);
1511 cm_ReleaseSCache(dscp);
1515 long cm_IoctlSetToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
1522 struct ClearToken ct;
1531 saveDataPtr = ioctlp->inDatap;
1533 cm_SkipIoctlPath(ioctlp);
1535 tp = ioctlp->inDatap;
1538 memcpy(&ticketLen, tp, sizeof(ticketLen));
1539 tp += sizeof(ticketLen);
1540 if (ticketLen < MINKTCTICKETLEN || ticketLen > MAXKTCTICKETLEN)
1541 return CM_ERROR_INVAL;
1543 /* remember ticket and skip over it for now */
1547 /* clear token size */
1548 memcpy(&ctSize, tp, sizeof(ctSize));
1549 tp += sizeof(ctSize);
1550 if (ctSize != sizeof(struct ClearToken))
1551 return CM_ERROR_INVAL;
1554 memcpy(&ct, tp, ctSize);
1556 if (ct.AuthHandle == -1)
1557 ct.AuthHandle = 999; /* more rxvab compat stuff */
1559 /* more stuff, if any */
1560 if (ioctlp->inCopied > tp - saveDataPtr) {
1561 /* flags: logon flag */
1562 memcpy(&flags, tp, sizeof(int));
1566 cellp = cm_GetCell(tp, CM_FLAG_CREATE);
1567 if (!cellp) return CM_ERROR_NOSUCHCELL;
1568 tp += strlen(tp) + 1;
1572 tp += strlen(tp) + 1;
1574 if (flags & PIOCTL_LOGON) {
1575 /* SMB user name with which to associate tokens */
1577 fprintf(stderr, "SMB name = %s\n", smbname);
1578 tp += strlen(tp) + 1;
1581 #ifndef DJGPP /* for win95, session key is back in pioctl */
1583 memcpy(&uuid, tp, sizeof(uuid));
1584 if (!cm_FindTokenEvent(uuid, sessionKey))
1585 return CM_ERROR_INVAL;
1588 cellp = cm_rootCellp;
1590 if (flags & PIOCTL_LOGON) {
1591 userp = smb_FindCMUserByName(smbname, ioctlp->fidp->vcp->rname);
1594 /* store the token */
1595 lock_ObtainMutex(&userp->mx);
1596 ucellp = cm_GetUCell(userp, cellp);
1597 ucellp->ticketLen = ticketLen;
1598 if (ucellp->ticketp)
1599 free(ucellp->ticketp); /* Discard old token if any */
1600 ucellp->ticketp = malloc(ticketLen);
1601 memcpy(ucellp->ticketp, ticket, ticketLen);
1604 * Get the session key from the RPC, rather than from the pioctl.
1607 memcpy(&ucellp->sessionKey, ct.HandShakeKey, sizeof(ct.HandShakeKey));
1609 memcpy(ucellp->sessionKey.data, sessionKey, sizeof(sessionKey));
1611 /* for win95, we are getting the session key from the pioctl */
1612 memcpy(&ucellp->sessionKey, ct.HandShakeKey, sizeof(ct.HandShakeKey));
1614 ucellp->kvno = ct.AuthHandle;
1615 ucellp->expirationTime = ct.EndTimestamp;
1617 if (uname) strcpy(ucellp->userName, uname);
1618 ucellp->flags |= CM_UCELLFLAG_RXKAD;
1619 lock_ReleaseMutex(&userp->mx);
1621 if (flags & PIOCTL_LOGON) {
1622 ioctlp->flags |= SMB_IOCTLFLAG_LOGON;
1625 cm_ResetACLCache(userp);
1630 long cm_IoctlGetTokenIter(struct smb_ioctl *ioctlp, struct cm_user *userp)
1636 struct ClearToken ct;
1638 cm_SkipIoctlPath(ioctlp);
1640 tp = ioctlp->inDatap;
1641 cp = ioctlp->outDatap;
1644 memcpy(&iterator, tp, sizeof(iterator));
1645 tp += sizeof(iterator);
1647 lock_ObtainMutex(&userp->mx);
1649 /* look for token */
1650 for (;;iterator++) {
1651 ucellp = cm_FindUCell(userp, iterator);
1653 lock_ReleaseMutex(&userp->mx);
1654 return CM_ERROR_NOMORETOKENS;
1656 if (ucellp->flags & CM_UCELLFLAG_RXKAD)
1661 temp = ucellp->iterator + 1;
1662 memcpy(cp, &temp, sizeof(temp));
1666 memcpy(cp, &ucellp->ticketLen, sizeof(ucellp->ticketLen));
1667 cp += sizeof(ucellp->ticketLen);
1670 memcpy(cp, ucellp->ticketp, ucellp->ticketLen);
1671 cp += ucellp->ticketLen;
1673 /* clear token size */
1675 memcpy(cp, &temp, sizeof(temp));
1679 ct.AuthHandle = ucellp->kvno;
1682 * Don't give out a real session key here
1685 memcpy(ct.HandShakeKey, &ucellp->sessionKey, sizeof(ct.HandShakeKey));
1687 memset(ct.HandShakeKey, 0, sizeof(ct.HandShakeKey));
1689 memcpy(ct.HandShakeKey, &ucellp->sessionKey, sizeof(ct.HandShakeKey));
1691 ct.ViceId = 37; /* XXX */
1692 ct.BeginTimestamp = 0; /* XXX */
1693 ct.EndTimestamp = ucellp->expirationTime;
1694 memcpy(cp, &ct, sizeof(ct));
1697 /* Primary flag (unused) */
1699 memcpy(cp, &temp, sizeof(temp));
1703 strcpy(cp, ucellp->cellp->namep);
1704 cp += strlen(cp) + 1;
1707 strcpy(cp, ucellp->userName);
1708 cp += strlen(cp) + 1;
1710 ioctlp->outDatap = cp;
1712 lock_ReleaseMutex(&userp->mx);
1717 long cm_IoctlGetToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
1723 struct ClearToken ct;
1729 cm_SkipIoctlPath(ioctlp);
1731 tp = ioctlp->inDatap;
1733 cp = ioctlp->outDatap;
1735 /* cell name is right here */
1736 cellp = cm_GetCell(tp, 0);
1737 if (!cellp) return CM_ERROR_NOSUCHCELL;
1738 tp += strlen(tp) + 1;
1742 memcpy(&uuid, tp, sizeof(uuid));
1745 lock_ObtainMutex(&userp->mx);
1747 ucellp = cm_GetUCell(userp, cellp);
1748 if (!ucellp || !(ucellp->flags & CM_UCELLFLAG_RXKAD)) {
1749 lock_ReleaseMutex(&userp->mx);
1750 return CM_ERROR_NOMORETOKENS;
1754 memcpy(cp, &ucellp->ticketLen, sizeof(ucellp->ticketLen));
1755 cp += sizeof(ucellp->ticketLen);
1758 memcpy(cp, ucellp->ticketp, ucellp->ticketLen);
1759 cp += ucellp->ticketLen;
1761 /* clear token size */
1763 memcpy(cp, &temp, sizeof(temp));
1767 ct.AuthHandle = ucellp->kvno;
1770 * Don't give out a real session key here
1773 memcpy(ct.HandShakeKey, &ucellp->sessionKey, sizeof(ct.HandShakeKey));
1775 memset(ct.HandShakeKey, 0, sizeof(ct.HandShakeKey));
1777 memcpy(ct.HandShakeKey, &ucellp->sessionKey, sizeof(ct.HandShakeKey));
1779 ct.ViceId = 37; /* XXX */
1780 ct.BeginTimestamp = 0; /* XXX */
1781 ct.EndTimestamp = ucellp->expirationTime;
1782 memcpy(cp, &ct, sizeof(ct));
1785 /* Primary flag (unused) */
1787 memcpy(cp, &temp, sizeof(temp));
1791 strcpy(cp, ucellp->cellp->namep);
1792 cp += strlen(cp) + 1;
1795 strcpy(cp, ucellp->userName);
1796 cp += strlen(cp) + 1;
1798 ioctlp->outDatap = cp;
1800 lock_ReleaseMutex(&userp->mx);
1803 cm_RegisterNewTokenEvent(uuid, ucellp->sessionKey.data);
1809 long cm_IoctlDelToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
1815 cm_SkipIoctlPath(ioctlp);
1817 cp = ioctlp->outDatap;
1819 /* cell name is right here */
1820 cellp = cm_GetCell(ioctlp->inDatap, 0);
1821 if (!cellp) return CM_ERROR_NOSUCHCELL;
1823 lock_ObtainMutex(&userp->mx);
1825 ucellp = cm_GetUCell(userp, cellp);
1827 lock_ReleaseMutex(&userp->mx);
1828 return CM_ERROR_NOMORETOKENS;
1831 if (ucellp->ticketp) {
1832 free(ucellp->ticketp);
1833 ucellp->ticketp = NULL;
1835 ucellp->flags &= ~CM_UCELLFLAG_RXKAD;
1838 lock_ReleaseMutex(&userp->mx);
1840 cm_ResetACLCache(userp);
1845 long cm_IoctlDelAllToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
1849 lock_ObtainMutex(&userp->mx);
1851 for (ucellp = userp->cellInfop; ucellp; ucellp = ucellp->nextp) {
1852 ucellp->flags &= ~CM_UCELLFLAG_RXKAD;
1856 lock_ReleaseMutex(&userp->mx);
1858 cm_ResetACLCache(userp);
1863 long cm_IoctlMakeSubmount(smb_ioctl_t *ioctlp, cm_user_t *userp)
1865 char afspath[MAX_PATH];
1868 int submountDataSize;
1871 int nextAutoSubmount;
1873 cm_SkipIoctlPath(ioctlp);
1875 /* Serialize this one, to prevent simultaneous mods
1878 lock_ObtainMutex(&cm_Afsdsbmt_Lock);
1880 /* Parse the input parameters--first the required afs path,
1881 * then the requested submount name (which may be "").
1883 cm_NormalizeAfsPath (afspath, ioctlp->inDatap);
1884 submountreqp = ioctlp->inDatap + (strlen(ioctlp->inDatap)+1);
1886 /* If the caller supplied a suggested submount name, see if
1887 * that submount name is in use... if so, the submount's path
1888 * has to match our path.
1890 if (submountreqp && *submountreqp) {
1891 char submountPathNormalized[MAX_PATH];
1892 char submountPath[MAX_PATH];
1893 int submountPathLen;
1895 submountPathLen = GetPrivateProfileString("AFS Submounts",
1896 submountreqp, "", submountPath,
1897 sizeof(submountPath), "afsdsbmt.ini");
1899 if ((submountPathLen == 0) ||
1900 (submountPathLen == sizeof(submountPath) - 1)) {
1902 /* The suggested submount name isn't in use now--
1903 * so we can safely map the requested submount name
1904 * to the supplied path. Remember not to write the
1905 * leading "/afs" when writing out the submount.
1907 WritePrivateProfileString("AFS Submounts",
1909 (strlen(&afspath[strlen(cm_mountRoot)])) ?
1910 &afspath[strlen(cm_mountRoot)]:"/",
1913 strcpy(ioctlp->outDatap, submountreqp);
1914 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
1915 lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
1919 /* The suggested submount name is already in use--if the
1920 * supplied path matches the submount's path, we can still
1921 * use the suggested submount name.
1923 cm_NormalizeAfsPath (submountPathNormalized, submountPath);
1924 if (!strcmp (submountPathNormalized, afspath)) {
1925 strcpy(ioctlp->outDatap, submountreqp);
1926 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
1927 lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
1932 /* At this point, the user either didn't request a particular
1933 * submount name, or that submount name couldn't be used.
1934 * Look through afsdsbmt.ini to see if there are any submounts
1935 * already associated with the specified path. The first
1936 * step in doing that search is to load the AFS Submounts
1937 * section of afsdsbmt.ini into memory.
1940 submountDataSize = 1024;
1941 submountData = malloc (submountDataSize);
1943 for (iteration = 0; iteration < 5; ++iteration) {
1946 sectionSize = GetPrivateProfileString("AFS Submounts",
1947 NULL, "", submountData,
1948 submountDataSize, "afsdsbmt.ini");
1949 if (sectionSize < submountDataSize-2)
1952 free (submountData);
1953 submountDataSize *= 2;
1954 submountData = malloc (submountDataSize);
1957 /* Having obtained a list of all available submounts, start
1958 * searching that list for a path which matches the requested
1959 * AFS path. We'll also keep track of the highest "auto15"/"auto47"
1960 * submount, in case we need to add a new one later.
1963 nextAutoSubmount = 1;
1965 for (submountName = submountData;
1966 submountName && *submountName;
1967 submountName += 1+strlen(submountName)) {
1969 char submountPathNormalized[MAX_PATH];
1970 char submountPath[MAX_PATH] = "";
1971 int submountPathLen;
1973 /* If this is an Auto### submount, remember its ### value */
1975 if ((!strnicmp (submountName, "auto", 4)) &&
1976 (isdigit (submountName[strlen("auto")]))) {
1977 int thisAutoSubmount;
1978 thisAutoSubmount = atoi (&submountName[strlen("auto")]);
1979 nextAutoSubmount = max (nextAutoSubmount,
1980 thisAutoSubmount+1);
1983 /* We have the name of a submount in the AFS Submounts
1984 * section; read that entry to find out what path it
1987 submountPathLen = GetPrivateProfileString("AFS Submounts",
1988 submountName, "", submountPath,
1989 sizeof(submountPath), "afsdsbmt.ini");
1991 if ((submountPathLen == 0) ||
1992 (submountPathLen == sizeof(submountPath) - 1)) {
1996 /* See if the path for this submount matches the path
1997 * that our caller specified. If so, we can return
2000 cm_NormalizeAfsPath (submountPathNormalized, submountPath);
2001 if (!strcmp (submountPathNormalized, afspath)) {
2003 strcpy(ioctlp->outDatap, submountName);
2004 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
2005 free (submountData);
2006 lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
2012 free (submountData);
2014 /* We've been through the entire list of existing submounts, and
2015 * didn't find any which matched the specified path. So, we'll
2016 * just have to add one. Remember not to write the leading "/afs"
2017 * when writing out the submount.
2020 sprintf(ioctlp->outDatap, "auto%ld", nextAutoSubmount);
2022 WritePrivateProfileString("AFS Submounts", ioctlp->outDatap,
2023 (strlen(&afspath[lstrlen(cm_mountRoot)])) ?
2024 &afspath[lstrlen(cm_mountRoot)]:"/",
2027 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
2028 lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
2032 long cm_IoctlGetRxkcrypt(smb_ioctl_t *ioctlp, cm_user_t *userp)
2034 memcpy(ioctlp->outDatap, &cryptall, sizeof(cryptall));
2035 ioctlp->outDatap += sizeof(cryptall);
2040 long cm_IoctlSetRxkcrypt(smb_ioctl_t *ioctlp, cm_user_t *userp)
2042 cm_SkipIoctlPath(ioctlp);
2044 memcpy(&cryptall, ioctlp->inDatap, sizeof(cryptall));
2050 extern int afsd_shutdown(int);
2051 extern int afs_shutdown;
2053 long cm_IoctlShutdown(smb_ioctl_t *ioctlp, cm_user_t *userp) {
2054 afs_shutdown = 1; /* flag to shut down */
2059 long cm_IoctlGetSMBName(smb_ioctl_t *ioctlp, cm_user_t *userp)
2061 smb_user_t *uidp = ioctlp->uidp;
2063 if (uidp && uidp->unp) {
2064 memcpy(ioctlp->outDatap, uidp->unp->name, strlen(uidp->unp->name));
2065 ioctlp->outDatap += strlen(uidp->unp->name);
2072 * functions to dump contents of various structures.
2073 * In debug build (linked with crt debug library) will dump allocated but not freed memory
2075 extern int cm_DumpSCache(FILE *outputFile, char *cookie);
2076 extern int cm_DumpBufHashTable(FILE *outputFile, char *cookie);
2077 extern int smb_DumpVCP(FILE *outputFile, char *cookie);
2079 long cm_IoctlMemoryDump(struct smb_ioctl *ioctlp, struct cm_user *userp)
2083 char logfileName[MAX_PATH+1];
2087 static _CrtMemState memstate;
2090 cm_SkipIoctlPath(ioctlp);
2091 memcpy(&inValue, ioctlp->inDatap, sizeof(long));
2095 strncpy(logfileName, getenv("TEMP"), MAX_PATH);
2096 logfileName[MAX_PATH] = '\0';
2100 GetWindowsDirectory(logfileName, sizeof(logfileName));
2102 strncat(logfileName, "\\afsd_alloc.log", sizeof(logfileName));
2104 hLogFile = CreateFile(logfileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
2110 memcpy(ioctlp->outDatap, &inValue, sizeof(long));
2111 ioctlp->outDatap += sizeof(long);
2116 SetFilePointer(hLogFile, 0, NULL, FILE_END);
2118 cookie = inValue ? "b" : "e";
2124 _CrtMemCheckpoint(&memstate);
2128 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
2129 _CrtSetReportFile(_CRT_WARN, hLogFile);
2130 _CrtMemDumpAllObjectsSince(&memstate);
2134 /* dump all interesting data */
2135 cm_DumpSCache(hLogFile, cookie);
2136 cm_DumpBufHashTable(hLogFile, cookie);
2137 smb_DumpVCP(hLogFile, cookie);
2139 CloseHandle(hLogFile);
2141 memcpy(ioctlp->outDatap, &inValue, sizeof(long));
2142 ioctlp->outDatap += sizeof(long);