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"
48 /* Copied from afs_tokens.h */
49 #define PIOCTL_LOGON 0x1
52 osi_mutex_t cm_Afsdsbmt_Lock;
54 extern afs_int32 cryptall;
55 extern char cm_NetbiosName[];
57 extern void afsi_log(char *pattern, ...);
59 void cm_InitIoctl(void)
61 lock_InitializeMutex(&cm_Afsdsbmt_Lock, "AFSDSBMT.INI Access Lock");
64 long cm_FlushFile(cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp)
68 lock_ObtainWrite(&scp->bufCreateLock);
69 code = buf_FlushCleanPages(scp, userp, reqp);
71 lock_ObtainMutex(&scp->mx);
72 scp->cbServerp = NULL;
74 lock_ReleaseMutex(&scp->mx);
76 lock_ReleaseWrite(&scp->bufCreateLock);
83 * cm_ResetACLCache -- invalidate ACL info for a user that has just
84 * obtained or lost tokens
86 void cm_ResetACLCache(cm_user_t *userp)
91 lock_ObtainWrite(&cm_scacheLock);
92 for (hash=0; hash < cm_hashTableSize; hash++) {
93 for (scp=cm_hashTablep[hash]; scp; scp=scp->nextp) {
95 lock_ReleaseWrite(&cm_scacheLock);
96 lock_ObtainMutex(&scp->mx);
97 cm_InvalidateACLUser(scp, userp);
98 lock_ReleaseMutex(&scp->mx);
99 lock_ObtainWrite(&cm_scacheLock);
103 lock_ReleaseWrite(&cm_scacheLock);
107 * TranslateExtendedChars - This is a fix for TR 54482.
109 * If an extended character (80 - FF) is entered into a file
110 * or directory name in Windows, the character is translated
111 * into the OEM character map before being passed to us. Why
112 * this occurs is unknown. Our pioctl functions must match
113 * this translation for paths given via our own commands (like
114 * fs). If we do not do this, then we will try to perform an
115 * operation on a non-translated path, which we will fail to
116 * find, since the path was created with the translated chars.
117 * This function performs the required translation.
119 void TranslateExtendedChars(char *str)
132 while (*p) *p++ &= 0x7f; /* turn off high bit; probably not right */
136 /* parse the passed-in file name and do a namei on it. If we fail,
137 * return an error code, otherwise return the vnode located in *scpp.
139 long cm_ParseIoctlPath(smb_ioctl_t *ioctlp, cm_user_t *userp, cm_req_t *reqp,
143 cm_scache_t *substRootp;
144 char * relativePath = ioctlp->inDatap;
146 /* This is usually the file name, but for StatMountPoint it is the path. */
147 /* ioctlp->inDatap can be either of the form:
150 * \\netbios-name\submount\path\.
151 * \\netbios-name\submount\path\file
153 TranslateExtendedChars(relativePath);
155 if (relativePath[0] == relativePath[1] &&
156 relativePath[1] == '\\' &&
157 !_strnicmp(cm_NetbiosName,relativePath+2,strlen(cm_NetbiosName)))
163 /* We may have found a UNC path.
164 * If the first component is the NetbiosName,
165 * then throw out the second component (the submount)
166 * since it had better expand into the value of ioctl->tidPathp
169 p = relativePath + 2 + strlen(cm_NetbiosName) + 1;
170 if ( !_strnicmp("all", p, 3) )
173 for (i = 0; *p && *p != '\\'; i++,p++ ) {
176 p++; /* skip past trailing slash */
177 shareName[i] = 0; /* terminate string */
179 shareFound = smb_FindShare(ioctlp->fidp->vcp, ioctlp->uidp, shareName, &sharePath);
181 /* we found a sharename, therefore use the resulting path */
182 code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
183 CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
184 userp, sharePath, reqp, &substRootp);
189 code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
190 userp, NULL, reqp, scpp);
194 /* otherwise, treat the name as a cellname mounted off the afs root.
195 * This requires that we reconstruct the shareName string with
196 * leading and trailing slashes.
198 p = relativePath + 2 + strlen(cm_NetbiosName) + 1;
199 if ( !_strnicmp("all", p, 3) )
203 for (i = 1; *p && *p != '\\'; i++,p++ ) {
206 p++; /* skip past trailing slash */
207 shareName[i++] = '/'; /* add trailing slash */
208 shareName[i] = 0; /* terminate string */
211 code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
212 CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
213 userp, shareName, reqp, &substRootp);
217 code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
218 userp, NULL, reqp, scpp);
223 code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
224 CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
225 userp, ioctlp->tidPathp, reqp, &substRootp);
229 code = cm_NameI(substRootp, relativePath, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
230 userp, NULL, reqp, scpp);
235 /* # of bytes of path */
236 code = strlen(ioctlp->inDatap) + 1;
237 ioctlp->inDatap += code;
239 /* This is usually nothing, but for StatMountPoint it is the file name. */
240 TranslateExtendedChars(ioctlp->inDatap);
242 /* and return success */
246 void cm_SkipIoctlPath(smb_ioctl_t *ioctlp)
250 temp = strlen(ioctlp->inDatap) + 1;
251 ioctlp->inDatap += temp;
255 /* format the specified path to look like "/afs/<cellname>/usr", by
256 * adding "/afs" (if necessary) in front, changing any \'s to /'s, and
257 * removing any trailing "/"'s. One weirdo caveat: "/afs" will be
258 * intentionally returned as "/afs/"--this makes submount manipulation
259 * easier (because we can always jump past the initial "/afs" to find
260 * the AFS path that should be written into afsdsbmt.ini).
262 void cm_NormalizeAfsPath(char *outpathp, long outlen, char *inpathp)
265 char bslash_mountRoot[256];
267 strncpy(bslash_mountRoot, cm_mountRoot, sizeof(bslash_mountRoot) - 1);
268 bslash_mountRoot[0] = '\\';
270 if (!strnicmp (inpathp, cm_mountRoot, strlen(cm_mountRoot)))
271 StringCbCopy(outpathp, outlen, inpathp);
272 else if (!strnicmp (inpathp, bslash_mountRoot, strlen(bslash_mountRoot)))
273 StringCbCopy(outpathp, outlen, inpathp);
274 else if ((inpathp[0] == '/') || (inpathp[0] == '\\'))
275 StringCbPrintfA(outpathp, outlen, "%s%s", cm_mountRoot, inpathp);
276 else // inpathp looks like "<cell>/usr"
277 StringCbPrintfA(outpathp, outlen, "%s/%s", cm_mountRoot, inpathp);
279 for (cp = outpathp; *cp != 0; ++cp) {
284 if (strlen(outpathp) && (outpathp[strlen(outpathp)-1] == '/')) {
285 outpathp[strlen(outpathp)-1] = 0;
288 if (!strcmpi (outpathp, cm_mountRoot)) {
289 StringCbCopy(outpathp, outlen, cm_mountRoot);
293 #define LEAF_SIZE 256
294 /* parse the passed-in file name and do a namei on its parent. If we fail,
295 * return an error code, otherwise return the vnode located in *scpp.
297 long cm_ParseIoctlParent(smb_ioctl_t *ioctlp, cm_user_t *userp, cm_req_t *reqp,
298 cm_scache_t **scpp, char *leafp)
303 cm_scache_t *substRootp;
305 StringCbCopyA(tbuffer, sizeof(tbuffer), ioctlp->inDatap);
306 tp = strrchr(tbuffer, '\\');
307 jp = strrchr(tbuffer, '/');
310 else if (jp && (tp - tbuffer) < (jp - tbuffer))
313 StringCbCopyA(tbuffer, sizeof(tbuffer), "\\");
315 StringCbCopyA(leafp, LEAF_SIZE, ioctlp->inDatap);
320 StringCbCopyA(leafp, LEAF_SIZE, tp+1);
323 if (tbuffer[0] == tbuffer[1] &&
324 tbuffer[1] == '\\' &&
325 !_strnicmp(cm_NetbiosName,tbuffer+2,strlen(cm_NetbiosName)))
331 /* We may have found a UNC path.
332 * If the first component is the NetbiosName,
333 * then throw out the second component (the submount)
334 * since it had better expand into the value of ioctl->tidPathp
337 p = tbuffer + 2 + strlen(cm_NetbiosName) + 1;
338 if ( !_strnicmp("all", p, 3) )
341 for (i = 0; *p && *p != '\\'; i++,p++ ) {
344 p++; /* skip past trailing slash */
345 shareName[i] = 0; /* terminate string */
347 shareFound = smb_FindShare(ioctlp->fidp->vcp, ioctlp->uidp, shareName, &sharePath);
349 /* we found a sharename, therefore use the resulting path */
350 code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
351 CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
352 userp, sharePath, reqp, &substRootp);
354 if (code) return code;
356 code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
357 userp, NULL, reqp, scpp);
358 if (code) return code;
360 /* otherwise, treat the name as a cellname mounted off the afs root.
361 * This requires that we reconstruct the shareName string with
362 * leading and trailing slashes.
364 p = tbuffer + 2 + strlen(cm_NetbiosName) + 1;
365 if ( !_strnicmp("all", p, 3) )
369 for (i = 1; *p && *p != '\\'; i++,p++ ) {
372 p++; /* skip past trailing slash */
373 shareName[i++] = '/'; /* add trailing slash */
374 shareName[i] = 0; /* terminate string */
376 code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
377 CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
378 userp, shareName, reqp, &substRootp);
379 if (code) return code;
381 code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
382 userp, NULL, reqp, scpp);
383 if (code) return code;
386 code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
387 CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
388 userp, ioctlp->tidPathp, reqp, &substRootp);
389 if (code) return code;
391 code = cm_NameI(substRootp, tbuffer, CM_FLAG_FOLLOW,
392 userp, NULL, reqp, scpp);
393 if (code) return code;
396 /* # of bytes of path */
397 code = strlen(ioctlp->inDatap) + 1;
398 ioctlp->inDatap += code;
400 /* and return success */
404 long cm_IoctlGetACL(smb_ioctl_t *ioctlp, cm_user_t *userp)
409 AFSFetchStatus fileStatus;
415 struct rx_connection * callp;
419 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
420 if (code) return code;
422 /* now make the get acl call */
423 fid.Volume = scp->fid.volume;
424 fid.Vnode = scp->fid.vnode;
425 fid.Unique = scp->fid.unique;
427 acl.AFSOpaque_val = ioctlp->outDatap;
428 acl.AFSOpaque_len = 0;
429 code = cm_Conn(&scp->fid, userp, &req, &connp);
432 callp = cm_GetRxConn(connp);
433 code = RXAFS_FetchACL(callp, &fid, &acl, &fileStatus, &volSync);
434 rx_PutConnection(callp);
436 } while (cm_Analyze(connp, userp, &req, &scp->fid, &volSync, NULL, NULL, code));
437 code = cm_MapRPCError(code, &req);
438 cm_ReleaseSCache(scp);
440 if (code) return code;
442 /* skip over return data */
443 tlen = strlen(ioctlp->outDatap) + 1;
444 ioctlp->outDatap += tlen;
446 /* and return success */
450 long cm_IoctlGetFileCellName(struct smb_ioctl *ioctlp, struct cm_user *userp)
459 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
460 if (code) return code;
462 #ifdef AFS_FREELANCE_CLIENT
463 if ( cm_freelanceEnabled &&
464 scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
465 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID &&
466 scp->fid.vnode==0x1 && scp->fid.unique==0x1 ) {
467 StringCbCopyA(ioctlp->outDatap, 999999, "Freelance.Local.Root");
468 ioctlp->outDatap += strlen(ioctlp->outDatap) + 1;
471 #endif /* AFS_FREELANCE_CLIENT */
473 cellp = cm_FindCellByID(scp->fid.cell);
475 StringCbCopyA(ioctlp->outDatap, 999999, cellp->namep);
476 ioctlp->outDatap += strlen(ioctlp->outDatap) + 1;
480 code = CM_ERROR_NOSUCHCELL;
483 cm_ReleaseSCache(scp);
487 long cm_IoctlSetACL(struct smb_ioctl *ioctlp, struct cm_user *userp)
492 AFSFetchStatus fileStatus;
497 struct rx_connection * callp;
501 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
502 if (code) return code;
504 /* now make the get acl call */
505 fid.Volume = scp->fid.volume;
506 fid.Vnode = scp->fid.vnode;
507 fid.Unique = scp->fid.unique;
509 acl.AFSOpaque_val = ioctlp->inDatap;
510 acl.AFSOpaque_len = strlen(ioctlp->inDatap)+1;
511 code = cm_Conn(&scp->fid, userp, &req, &connp);
514 callp = cm_GetRxConn(connp);
515 code = RXAFS_StoreACL(callp, &fid, &acl, &fileStatus, &volSync);
516 rx_PutConnection(callp);
518 } while (cm_Analyze(connp, userp, &req, &scp->fid, &volSync, NULL, NULL, code));
519 code = cm_MapRPCError(code, &req);
521 /* invalidate cache info, since we just trashed the ACL cache */
522 lock_ObtainMutex(&scp->mx);
523 cm_DiscardSCache(scp);
524 lock_ReleaseMutex(&scp->mx);
526 cm_ReleaseSCache(scp);
531 long cm_IoctlFlushVolume(struct smb_ioctl *ioctlp, struct cm_user *userp)
535 unsigned long volume;
541 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
542 if (code) return code;
544 volume = scp->fid.volume;
545 cm_ReleaseSCache(scp);
547 lock_ObtainWrite(&cm_scacheLock);
548 for (i=0; i<cm_hashTableSize; i++) {
549 for (scp = cm_hashTablep[i]; scp; scp = scp->nextp) {
550 if (scp->fid.volume == volume) {
552 lock_ReleaseWrite(&cm_scacheLock);
554 /* now flush the file */
555 code = cm_FlushFile(scp, userp, &req);
557 afsi_log("cm_FlushFile returns error: [%x]",code);
558 lock_ObtainWrite(&cm_scacheLock);
563 lock_ReleaseWrite(&cm_scacheLock);
568 long cm_IoctlFlushFile(struct smb_ioctl *ioctlp, struct cm_user *userp)
576 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
577 if (code) return code;
579 cm_FlushFile(scp, userp, &req);
580 cm_ReleaseSCache(scp);
585 long cm_IoctlSetVolumeStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
589 char offLineMsg[256];
593 AFSFetchVolumeStatus volStat;
594 AFSStoreVolumeStatus storeStat;
599 struct rx_connection * callp;
603 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
604 if (code) return code;
606 cellp = cm_FindCellByID(scp->fid.cell);
609 if (scp->flags & CM_SCACHEFLAG_RO) {
610 cm_ReleaseSCache(scp);
611 return CM_ERROR_READONLY;
614 code = cm_GetVolumeByID(cellp, scp->fid.volume, userp, &req, &tvp);
616 cm_ReleaseSCache(scp);
620 /* Copy the junk out, using cp as a roving pointer. */
621 cp = ioctlp->inDatap;
622 memcpy((char *)&volStat, cp, sizeof(AFSFetchVolumeStatus));
623 cp += sizeof(AFSFetchVolumeStatus);
624 StringCbCopyA(volName, sizeof(volName), cp);
625 cp += strlen(volName)+1;
626 StringCbCopyA(offLineMsg, sizeof(offLineMsg), cp);
627 cp += strlen(offLineMsg)+1;
628 StringCbCopyA(motd, sizeof(motd), cp);
630 if (volStat.MinQuota != -1) {
631 storeStat.MinQuota = volStat.MinQuota;
632 storeStat.Mask |= AFS_SETMINQUOTA;
634 if (volStat.MaxQuota != -1) {
635 storeStat.MaxQuota = volStat.MaxQuota;
636 storeStat.Mask |= AFS_SETMAXQUOTA;
640 code = cm_Conn(&scp->fid, userp, &req, &tcp);
643 callp = cm_GetRxConn(tcp);
644 code = RXAFS_SetVolumeStatus(callp, scp->fid.volume,
645 &storeStat, volName, offLineMsg, motd);
646 rx_PutConnection(callp);
648 } while (cm_Analyze(tcp, userp, &req, &scp->fid, NULL, NULL, NULL, code));
649 code = cm_MapRPCError(code, &req);
651 /* return on failure */
652 cm_ReleaseSCache(scp);
657 /* we are sending parms back to make compat. with prev system. should
658 * change interface later to not ask for current status, just set
661 cp = ioctlp->outDatap;
662 memcpy(cp, (char *)&volStat, sizeof(VolumeStatus));
663 cp += sizeof(VolumeStatus);
664 StringCbCopyA(cp, 999999, volName);
665 cp += strlen(volName)+1;
666 StringCbCopyA(cp, 999999, offLineMsg);
667 cp += strlen(offLineMsg)+1;
668 StringCbCopyA(cp, 999999, motd);
669 cp += strlen(motd)+1;
671 /* now return updated return data pointer */
672 ioctlp->outDatap = cp;
677 long cm_IoctlGetVolumeStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
681 char offLineMsg[256];
685 AFSFetchVolumeStatus volStat;
691 struct rx_connection * callp;
695 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
696 if (code) return code;
699 OfflineMsg = offLineMsg;
702 code = cm_Conn(&scp->fid, userp, &req, &tcp);
705 callp = cm_GetRxConn(tcp);
706 code = RXAFS_GetVolumeStatus(callp, scp->fid.volume,
707 &volStat, &Name, &OfflineMsg, &MOTD);
708 rx_PutConnection(callp);
710 } while (cm_Analyze(tcp, userp, &req, &scp->fid, NULL, NULL, NULL, code));
711 code = cm_MapRPCError(code, &req);
713 cm_ReleaseSCache(scp);
714 if (code) return code;
716 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
717 cp = ioctlp->outDatap;
718 memcpy(cp, (char *)&volStat, sizeof(AFSFetchVolumeStatus));
719 cp += sizeof(AFSFetchVolumeStatus);
720 StringCbCopyA(cp, 999999, volName);
721 cp += strlen(volName)+1;
722 StringCbCopyA(cp, 999999, offLineMsg);
723 cp += strlen(offLineMsg)+1;
724 StringCbCopyA(cp, 999999, motd);
725 cp += strlen(motd)+1;
727 /* return new size */
728 ioctlp->outDatap = cp;
733 long cm_IoctlWhereIs(struct smb_ioctl *ioctlp, struct cm_user *userp)
739 cm_serverRef_t **tsrpp, *current;
741 unsigned long volume;
747 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
748 if (code) return code;
750 volume = scp->fid.volume;
752 cellp = cm_FindCellByID(scp->fid.cell);
755 cm_ReleaseSCache(scp);
757 code = cm_GetVolumeByID(cellp, volume, userp, &req, &tvp);
758 if (code) return code;
760 cp = ioctlp->outDatap;
762 lock_ObtainMutex(&tvp->mx);
763 tsrpp = cm_GetVolServers(tvp, volume);
764 lock_ObtainRead(&cm_serverLock);
765 for (current = *tsrpp; current; current = current->next) {
766 tsp = current->server;
767 memcpy(cp, (char *)&tsp->addr.sin_addr.s_addr, sizeof(long));
770 lock_ReleaseRead(&cm_serverLock);
771 cm_FreeServerList(tsrpp);
772 lock_ReleaseMutex(&tvp->mx);
774 /* still room for terminating NULL, add it on */
775 volume = 0; /* reuse vbl */
776 memcpy(cp, (char *)&volume, sizeof(long));
779 ioctlp->outDatap = cp;
784 long cm_IoctlStatMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp)
794 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
795 if (code) return code;
797 cp = ioctlp->inDatap;
799 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
800 cm_ReleaseSCache(dscp);
801 if (code) return code;
803 lock_ObtainMutex(&scp->mx);
805 /* now check that this is a real mount point */
806 if (scp->fileType != CM_SCACHETYPE_MOUNTPOINT) {
807 lock_ReleaseMutex(&scp->mx);
808 cm_ReleaseSCache(scp);
809 return CM_ERROR_INVAL;
812 code = cm_ReadMountPoint(scp, userp, &req);
814 cp = ioctlp->outDatap;
815 StringCbCopyA(cp, 999999, scp->mountPointStringp);
816 cp += strlen(cp) + 1;
817 ioctlp->outDatap = cp;
819 lock_ReleaseMutex(&scp->mx);
820 cm_ReleaseSCache(scp);
825 long cm_IoctlDeleteMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp)
835 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
836 if (code) return code;
838 cp = ioctlp->inDatap;
840 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
842 /* if something went wrong, bail out now */
847 lock_ObtainMutex(&scp->mx);
848 code = cm_SyncOp(scp, NULL, userp, &req, 0,
849 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
851 lock_ReleaseMutex(&scp->mx);
852 cm_ReleaseSCache(scp);
856 /* now check that this is a real mount point */
857 if (scp->fileType != CM_SCACHETYPE_MOUNTPOINT) {
858 lock_ReleaseMutex(&scp->mx);
859 cm_ReleaseSCache(scp);
860 code = CM_ERROR_INVAL;
864 /* time to make the RPC, so drop the lock */
865 lock_ReleaseMutex(&scp->mx);
866 cm_ReleaseSCache(scp);
868 /* easier to do it this way */
869 code = cm_Unlink(dscp, cp, userp, &req);
870 if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
871 smb_NotifyChange(FILE_ACTION_REMOVED,
872 FILE_NOTIFY_CHANGE_DIR_NAME,
873 dscp, cp, NULL, TRUE);
876 cm_ReleaseSCache(dscp);
880 long cm_IoctlCheckServers(struct smb_ioctl *ioctlp, struct cm_user *userp)
890 cm_SkipIoctlPath(ioctlp); /* we don't care about the path */
891 tp = ioctlp->inDatap;
894 memcpy(&temp, tp, sizeof(temp));
895 if (temp == 0x12345678) { /* For afs3.3 version */
896 memcpy(&csi, tp, sizeof(csi));
897 if (csi.tinterval >= 0) {
898 cp = ioctlp->outDatap;
899 memcpy(cp, (char *)&cm_daemonCheckInterval, sizeof(long));
900 ioctlp->outDatap += sizeof(long);
901 if (csi.tinterval > 0) {
902 if (!smb_SUser(userp))
903 return CM_ERROR_NOACCESS;
904 cm_daemonCheckInterval = csi.tinterval;
912 } else { /* For pre afs3.3 versions */
913 memcpy((char *)&temp, ioctlp->inDatap, sizeof(long));
914 ioctlp->inDatap = cp = ioctlp->inDatap + sizeof(long);
915 if (cp - ioctlp->inAllocp < ioctlp->inCopied) /* still more data available */
920 * 1: fast check, don't contact servers.
921 * 2: local cell only.
924 /* have cell name, too */
925 cellp = cm_GetCell(cp, 0);
926 if (!cellp) return CM_ERROR_NOSUCHCELL;
928 else cellp = (cm_cell_t *) 0;
929 if (!cellp && (temp & 2)) {
931 cellp = cm_FindCellByID(1);
933 if (!(temp & 1)) { /* if not fast, call server checker routine */
934 /* check down servers */
935 cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS | CM_FLAG_CHECKUPSERVERS,
939 /* now return the current down server list */
940 cp = ioctlp->outDatap;
941 lock_ObtainRead(&cm_serverLock);
942 for (tsp = cm_allServersp; tsp; tsp=tsp->allNextp) {
943 if (cellp && tsp->cellp != cellp) continue; /* cell spec'd and wrong */
944 if ((tsp->flags & CM_SERVERFLAG_DOWN)
945 && tsp->type == CM_SERVER_FILE) {
946 memcpy(cp, (char *)&tsp->addr.sin_addr.s_addr, sizeof(long));
950 lock_ReleaseRead(&cm_serverLock);
952 ioctlp->outDatap = cp;
956 long cm_IoctlGag(struct smb_ioctl *ioctlp, struct cm_user *userp)
958 /* we don't print anything superfluous, so we don't support the gag call */
959 return CM_ERROR_INVAL;
962 long cm_IoctlCheckVolumes(struct smb_ioctl *ioctlp, struct cm_user *userp)
968 long cm_IoctlSetCacheSize(struct smb_ioctl *ioctlp, struct cm_user *userp)
973 cm_SkipIoctlPath(ioctlp);
975 memcpy(&temp, ioctlp->inDatap, sizeof(temp));
977 temp = buf_nOrigBuffers;
979 /* temp is in 1K units, convert to # of buffers */
980 temp = temp / (buf_bufferSize / 1024);
983 /* now adjust the cache size */
984 code = buf_SetNBuffers(temp);
989 long cm_IoctlTraceControl(struct smb_ioctl *ioctlp, struct cm_user *userp)
993 cm_SkipIoctlPath(ioctlp);
995 memcpy(&inValue, ioctlp->inDatap, sizeof(long));
999 afsd_ForceTrace(FALSE);
1000 buf_ForceTrace(FALSE);
1004 /* set tracing value to low order bit */
1005 if ((inValue & 1) == 0) {
1006 /* disable tracing */
1007 osi_LogDisable(afsd_logp);
1010 /* enable tracing */
1011 osi_LogEnable(afsd_logp);
1015 /* see if we're supposed to do a reset, too */
1017 osi_LogReset(afsd_logp);
1020 /* and copy out tracing flag */
1021 inValue = afsd_logp->enabled; /* use as a temp vbl */
1022 memcpy(ioctlp->outDatap, &inValue, sizeof(long));
1023 ioctlp->outDatap += sizeof(long);
1027 long cm_IoctlGetCacheParms(struct smb_ioctl *ioctlp, struct cm_user *userp)
1029 cm_cacheParms_t parms;
1031 memset(&parms, 0, sizeof(parms));
1033 /* first we get, in 1K units, the cache size */
1034 parms.parms[0] = buf_nbuffers * (buf_bufferSize / 1024);
1036 /* and then the actual # of buffers in use (not in the free list, I guess,
1037 * will be what we do).
1039 parms.parms[1] = (buf_nbuffers - buf_CountFreeList()) * (buf_bufferSize / 1024);
1041 memcpy(ioctlp->outDatap, &parms, sizeof(parms));
1042 ioctlp->outDatap += sizeof(parms);
1047 long cm_IoctlGetCell(struct smb_ioctl *ioctlp, struct cm_user *userp)
1052 cm_serverRef_t *serverRefp;
1053 cm_server_t *serverp;
1059 cm_SkipIoctlPath(ioctlp);
1061 tp = ioctlp->inDatap;
1063 memcpy((char *)&whichCell, tp, sizeof(long));
1066 /* see if more than one long passed in, ignoring the null pathname (the -1) */
1067 if (ioctlp->inCopied-1 > sizeof(long)) {
1068 memcpy((char *)&magic, tp, sizeof(long));
1071 lock_ObtainRead(&cm_cellLock);
1072 for (tcellp = cm_allCellsp; tcellp; tcellp = tcellp->nextp) {
1073 if (whichCell == 0) break;
1076 lock_ReleaseRead(&cm_cellLock);
1080 cp = ioctlp->outDatap;
1082 if (magic == 0x12345678) {
1083 memcpy(cp, (char *)&magic, sizeof(long));
1086 memset(cp, 0, max * sizeof(long));
1088 lock_ObtainRead(&cm_serverLock); /* for going down server list */
1089 /* jaltman - do the reference counts to serverRefp contents need to be increased? */
1090 serverRefp = tcellp->vlServersp;
1091 for (i=0; i<max; i++) {
1092 if (!serverRefp) break;
1093 serverp = serverRefp->server;
1094 memcpy(cp, &serverp->addr.sin_addr.s_addr, sizeof(long));
1096 serverRefp = serverRefp->next;
1098 lock_ReleaseRead(&cm_serverLock);
1099 cp = basep + max * sizeof(afs_int32);
1100 StringCbCopyA(cp, 999999, tcellp->namep);
1101 cp += strlen(tcellp->namep)+1;
1102 ioctlp->outDatap = cp;
1108 return CM_ERROR_NOMORETOKENS; /* mapped to EDOM */
1111 extern long cm_AddCellProc(void *rockp, struct sockaddr_in *addrp, char *namep);
1113 long cm_IoctlNewCell(struct smb_ioctl *ioctlp, struct cm_user *userp)
1115 /* NT cache manager will read cell information from afsdcell.ini each time
1116 * cell is accessed. So, this call is necessary only if list of server for a cell
1117 * changes (or IP addresses of cell servers changes).
1118 * All that needs to be done is to refresh server information for all cells that
1119 * are already loaded.
1121 * cell list will be cm_CellLock and cm_ServerLock will be held for write.
1126 cm_SkipIoctlPath(ioctlp);
1127 lock_ObtainWrite(&cm_cellLock);
1129 for (cp = cm_allCellsp; cp; cp=cp->nextp)
1132 /* delete all previous server lists - cm_FreeServerList will ask for write on cm_ServerLock*/
1133 cm_FreeServerList(&cp->vlServersp);
1134 cp->vlServersp = NULL;
1135 code = cm_SearchCellFile(cp->namep, cp->namep, cm_AddCellProc, cp);
1136 #ifdef AFS_AFSDB_ENV
1138 if (cm_dnsEnabled) {
1140 code = cm_SearchCellByDNS(cp->namep, cp->namep, &ttl, cm_AddCellProc, cp);
1141 if ( code == 0 ) { /* got cell from DNS */
1142 cp->flags |= CM_CELLFLAG_DNS;
1143 cp->flags &= ~CM_CELLFLAG_VLSERVER_INVALID;
1144 cp->timeout = time(0) + ttl;
1149 cp->flags &= ~CM_CELLFLAG_DNS;
1151 #endif /* AFS_AFSDB_ENV */
1153 cp->flags |= CM_CELLFLAG_VLSERVER_INVALID;
1156 cp->flags &= ~CM_CELLFLAG_VLSERVER_INVALID;
1157 cm_RandomizeServer(&cp->vlServersp);
1161 lock_ReleaseWrite(&cm_cellLock);
1165 long cm_IoctlGetWsCell(smb_ioctl_t *ioctlp, cm_user_t *userp)
1167 /* if we don't know our default cell, return failure */
1168 if (cm_rootCellp == NULL) {
1169 return CM_ERROR_NOSUCHCELL;
1172 /* return the default cellname to the caller */
1173 StringCbCopyA(ioctlp->outDatap, 999999, cm_rootCellp->namep);
1174 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
1180 long cm_IoctlSysName(struct smb_ioctl *ioctlp, struct cm_user *userp)
1182 long setSysName, foundname = 0;
1183 char *cp, *cp2, inname[MAXSYSNAME], outname[MAXSYSNAME];
1184 int t, count, num = 0;
1185 char **sysnamelist[MAXSYSNAME];
1187 cm_SkipIoctlPath(ioctlp);
1189 memcpy(&setSysName, ioctlp->inDatap, sizeof(long));
1190 ioctlp->inDatap += sizeof(long);
1194 if ( setSysName < 0 || setSysName > MAXNUMSYSNAMES )
1196 cp2 = ioctlp->inDatap;
1197 for ( cp=ioctlp->inDatap, count = 0; count < setSysName; count++ ) {
1198 /* won't go past end of ioctlp->inDatap since maxsysname*num < ioctlp->inDatap length */
1200 if (t >= MAXSYSNAME || t <= 0)
1202 /* check for names that can shoot us in the foot */
1203 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
1209 /* inname gets first entry in case we're being a translator */
1210 /* (we are never a translator) */
1211 t = strlen(ioctlp->inDatap);
1212 memcpy(inname, ioctlp->inDatap, t + 1);
1213 ioctlp->inDatap += t + 1;
1217 /* Not xlating, so local case */
1219 osi_panic("cm_IoctlSysName: !cm_sysName\n", __FILE__, __LINE__);
1221 if (!setSysName) { /* user just wants the info */
1222 StringCbCopyA(outname, sizeof(outname), cm_sysName);
1223 foundname = cm_sysNameCount;
1224 *sysnamelist = cm_sysNameList;
1226 /* Local guy; only root can change sysname */
1227 /* clear @sys entries from the dnlc, once afs_lookup can
1228 * do lookups of @sys entries and thinks it can trust them */
1229 /* privs ok, store the entry, ... */
1230 StringCbCopyA(cm_sysName, sizeof(cm_sysName), inname);
1231 StringCbCopyA(cm_sysNameList[0], MAXSYSNAME, inname);
1232 if (setSysName > 1) { /* ... or list */
1233 cp = ioctlp->inDatap;
1234 for (count = 1; count < setSysName; ++count) {
1235 if (!cm_sysNameList[count])
1236 osi_panic("cm_IoctlSysName: no cm_sysNameList entry to write\n",
1237 __FILE__, __LINE__);
1239 StringCbCopyA(cm_sysNameList[count], MAXSYSNAME, cp);
1243 cm_sysNameCount = setSysName;
1247 /* return the sysname to the caller */
1248 cp = ioctlp->outDatap;
1249 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
1250 cp += sizeof(afs_int32); /* skip found flag */
1252 StringCbCopyA(cp, 999999, outname);
1253 cp += strlen(outname) + 1; /* skip name and terminating null char */
1254 for ( count=1; count < foundname ; ++count) { /* ... or list */
1255 if ( !(*sysnamelist)[count] )
1256 osi_panic("cm_IoctlSysName: no cm_sysNameList entry to read\n",
1257 __FILE__, __LINE__);
1258 t = strlen((*sysnamelist)[count]);
1259 if (t >= MAXSYSNAME)
1260 osi_panic("cm_IoctlSysName: sysname entry garbled\n",
1261 __FILE__, __LINE__);
1262 StringCbCopyA(cp, 999999, (*sysnamelist)[count]);
1266 ioctlp->outDatap = cp;
1273 long cm_IoctlGetCellStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
1278 cm_SkipIoctlPath(ioctlp);
1280 cellp = cm_GetCell(ioctlp->inDatap, 0);
1282 return CM_ERROR_NOSUCHCELL;
1285 lock_ObtainMutex(&cellp->mx);
1286 if (cellp->flags & CM_CELLFLAG_SUID)
1287 temp |= CM_SETCELLFLAG_SUID;
1288 lock_ReleaseMutex(&cellp->mx);
1290 /* now copy out parm */
1291 memcpy(ioctlp->outDatap, &temp, sizeof(long));
1292 ioctlp->outDatap += sizeof(long);
1297 long cm_IoctlSetCellStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
1302 cm_SkipIoctlPath(ioctlp);
1304 cellp = cm_GetCell(ioctlp->inDatap + 2*sizeof(long), 0);
1306 return CM_ERROR_NOSUCHCELL;
1308 memcpy((char *)&temp, ioctlp->inDatap, sizeof(long));
1310 lock_ObtainMutex(&cellp->mx);
1311 if (temp & CM_SETCELLFLAG_SUID)
1312 cellp->flags |= CM_CELLFLAG_SUID;
1314 cellp->flags &= ~CM_CELLFLAG_SUID;
1315 lock_ReleaseMutex(&cellp->mx);
1320 long cm_IoctlSetSPrefs(struct smb_ioctl *ioctlp, struct cm_user *userp)
1322 cm_SSetPref_t *spin; /* input */
1323 cm_SPref_t *srvin; /* one input component */
1325 int i, vlonly, noServers, type;
1326 struct sockaddr_in tmp;
1327 unsigned short rank;
1329 cm_SkipIoctlPath(ioctlp); /* we don't care about the path */
1331 spin = (cm_SSetPref_t *)ioctlp->inDatap;
1332 noServers = spin->num_servers;
1333 vlonly = spin->flags;
1335 type = CM_SERVER_VLDB;
1337 type = CM_SERVER_FILE;
1339 for ( i=0; i < noServers; i++)
1341 srvin = &(spin->servers[i]);
1342 rank = srvin->rank + (rand() & 0x000f);
1343 tmp.sin_addr = srvin->host;
1344 tmp.sin_family = AF_INET;
1346 tsp = cm_FindServer(&tmp, type);
1347 if ( tsp ) /* an existing server - ref count increased */
1349 tsp->ipRank = rank; /* no need to protect by mutex*/
1351 if ( type == CM_SERVER_FILE) /* fileserver */
1353 /* find volumes which might have RO copy
1354 /* on server and change the ordering of
1356 cm_ChangeRankVolume(tsp);
1360 /* set preferences for an existing vlserver */
1361 cm_ChangeRankCellVLServer(tsp);
1363 cm_PutServer(tsp); /* decrease refcount */
1365 else /* add a new server without a cell */
1367 tsp = cm_NewServer(&tmp, type, NULL); /* refcount = 1 */
1374 long cm_IoctlGetSPrefs(struct smb_ioctl *ioctlp, struct cm_user *userp)
1376 cm_SPrefRequest_t *spin; /* input */
1377 cm_SPrefInfo_t *spout; /* output */
1378 cm_SPref_t *srvout; /* one output component */
1380 int i, vlonly, noServers;
1382 cm_SkipIoctlPath(ioctlp); /* we don't care about the path */
1384 spin = (cm_SPrefRequest_t *)ioctlp->inDatap;
1385 spout = (cm_SPrefInfo_t *) ioctlp->outDatap;
1386 srvout = spout->servers;
1387 noServers = spin->num_servers;
1388 vlonly = spin->flags & CM_SPREF_VLONLY;
1389 spout->num_servers = 0;
1391 lock_ObtainRead(&cm_serverLock); /* get server lock */
1393 for (tsp=cm_allServersp, i=0; tsp && noServers; tsp=tsp->allNextp,i++){
1394 if (spin->offset > i) {
1395 continue; /* catch up to where we left off */
1398 if ( vlonly && (tsp->type == CM_SERVER_FILE) )
1399 continue; /* ignore fileserver for -vlserver option*/
1400 if ( !vlonly && (tsp->type == CM_SERVER_VLDB) )
1401 continue; /* ignore vlservers */
1403 srvout->host = tsp->addr.sin_addr;
1404 srvout->rank = tsp->ipRank;
1406 spout->num_servers++;
1409 lock_ReleaseRead(&cm_serverLock); /* release server lock */
1411 if ( tsp ) /* we ran out of space in the output buffer */
1412 spout->next_offset = i;
1414 spout->next_offset = 0;
1415 ioctlp->outDatap += sizeof(cm_SPrefInfo_t) +
1416 (spout->num_servers -1 ) * sizeof(cm_SPref_t) ;
1420 long cm_IoctlStoreBehind(struct smb_ioctl *ioctlp, struct cm_user *userp)
1422 /* we ignore default asynchrony since we only have one way
1423 * of doing this today.
1428 long cm_IoctlCreateMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp)
1430 char leaf[LEAF_SIZE];
1444 code = cm_ParseIoctlParent(ioctlp, userp, &req, &dscp, leaf);
1445 if (code) return code;
1447 /* Translate chars for the mount point name */
1448 TranslateExtendedChars(leaf);
1451 * The fs command allows the user to specify partial cell names on NT. These must
1452 * be expanded to the full cell name for mount points so that the mount points will
1453 * work on UNIX clients.
1456 /* Extract the possibly partial cell name */
1457 StringCbCopyA(cell, sizeof(cell), ioctlp->inDatap + 1); /* Skip the mp type character */
1459 if (cp = strchr(cell, ':')) {
1460 /* Extract the volume name */
1462 StringCbCopyA(volume, sizeof(volume), cp + 1);
1464 /* Get the full name for this cell */
1465 code = cm_SearchCellFile(cell, fullCell, 0, 0);
1466 #ifdef AFS_AFSDB_ENV
1467 if (code && cm_dnsEnabled)
1468 code = cm_SearchCellByDNS(cell, fullCell, &ttl, 0, 0);
1471 return CM_ERROR_NOSUCHCELL;
1473 StringCbPrintfA(mpInfo, sizeof(mpInfo), "%c%s:%s", *ioctlp->inDatap, fullCell, volume);
1475 /* No cell name specified */
1476 StringCbCopyA(mpInfo, sizeof(mpInfo), ioctlp->inDatap);
1479 #ifdef AFS_FREELANCE_CLIENT
1480 if (cm_freelanceEnabled && dscp == cm_rootSCachep) {
1481 /* we are adding the mount point to the root dir., so call
1482 * the freelance code to do the add. */
1483 osi_Log0(afsd_logp,"IoctlCreateMountPoint within Freelance root dir");
1484 code = cm_FreelanceAddMount(leaf, fullCell, volume,
1485 *ioctlp->inDatap == '%', NULL);
1489 /* create the symlink with mode 644. The lack of X bits tells
1490 * us that it is a mount point.
1492 tattr.mask = CM_ATTRMASK_UNIXMODEBITS | CM_ATTRMASK_CLIENTMODTIME;
1493 tattr.unixModeBits = 0644;
1494 tattr.clientModTime = time(NULL);
1496 code = cm_SymLink(dscp, leaf, mpInfo, 0, &tattr, userp, &req);
1497 if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
1498 smb_NotifyChange(FILE_ACTION_ADDED,
1499 FILE_NOTIFY_CHANGE_DIR_NAME,
1500 dscp, leaf, NULL, TRUE);
1502 cm_ReleaseSCache(dscp);
1506 long cm_IoctlSymlink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1508 char leaf[LEAF_SIZE];
1517 code = cm_ParseIoctlParent(ioctlp, userp, &req, &dscp, leaf);
1518 if (code) return code;
1520 /* Translate chars for the link name */
1521 TranslateExtendedChars(leaf);
1523 /* Translate chars for the linked to name */
1524 TranslateExtendedChars(ioctlp->inDatap);
1526 cp = ioctlp->inDatap; /* contents of link */
1528 #ifdef AFS_FREELANCE_CLIENT
1529 if (cm_freelanceEnabled && dscp == cm_rootSCachep) {
1530 /* we are adding the symlink to the root dir., so call
1531 * the freelance code to do the add. */
1532 if (cp[0] == cp[1] && cp[1] == '\\' &&
1533 !_strnicmp(cm_NetbiosName,cp+2,strlen(cm_NetbiosName)))
1535 /* skip \\AFS\ or \\AFS\all\ */
1537 p = cp + 2 + strlen(cm_NetbiosName) + 1;
1538 if ( !_strnicmp("all", p, 3) )
1542 osi_Log0(afsd_logp,"IoctlCreateSymlink within Freelance root dir");
1543 code = cm_FreelanceAddSymlink(leaf, cp, NULL);
1548 /* Create symlink with mode 0755. */
1549 tattr.mask = CM_ATTRMASK_UNIXMODEBITS;
1550 tattr.unixModeBits = 0755;
1552 code = cm_SymLink(dscp, leaf, cp, 0, &tattr, userp, &req);
1553 if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
1554 smb_NotifyChange(FILE_ACTION_ADDED,
1555 FILE_NOTIFY_CHANGE_FILE_NAME
1556 | FILE_NOTIFY_CHANGE_DIR_NAME,
1557 dscp, leaf, NULL, TRUE);
1559 cm_ReleaseSCache(dscp);
1564 extern long cm_AssembleLink(cm_scache_t *linkScp, char *pathSuffixp,
1565 cm_scache_t **newRootScpp, cm_space_t **newSpaceBufferp,
1566 cm_user_t *userp, cm_req_t *reqp);
1568 long cm_IoctlListlink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1575 cm_scache_t *newRootScp;
1580 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
1581 if (code) return code;
1583 cp = ioctlp->inDatap;
1585 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
1586 cm_ReleaseSCache(dscp);
1587 if (code) return code;
1589 /* Check that it's a real symlink */
1590 if (scp->fileType != CM_SCACHETYPE_SYMLINK){
1591 cm_ReleaseSCache(scp);
1592 return CM_ERROR_INVAL;
1595 code = cm_AssembleLink(scp, "", &newRootScp, &spacep, userp, &req);
1596 cm_ReleaseSCache(scp);
1598 cp = ioctlp->outDatap;
1599 if (newRootScp != NULL) {
1600 StringCbCopyA(cp, 999999, cm_mountRoot);
1601 StringCbCatA(cp, 999999, "/");
1604 StringCbCopyA(cp, 999999, spacep->data);
1605 cp += strlen(cp) + 1;
1606 ioctlp->outDatap = cp;
1607 cm_FreeSpace(spacep);
1608 if (newRootScp != NULL)
1609 cm_ReleaseSCache(newRootScp);
1615 long cm_IoctlIslink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1616 {/*CHECK FOR VALID SYMLINK*/
1625 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
1626 if (code) return code;
1628 cp = ioctlp->inDatap;
1629 osi_LogEvent("cm_IoctlListlink",NULL," name[%s]",cp);
1631 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
1632 cm_ReleaseSCache(dscp);
1633 if (code) return code;
1635 /* Check that it's a real symlink */
1636 if (scp->fileType != CM_SCACHETYPE_SYMLINK)
1637 code = CM_ERROR_INVAL;
1638 cm_ReleaseSCache(scp);
1642 long cm_IoctlDeletelink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1652 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
1653 if (code) return code;
1655 cp = ioctlp->inDatap;
1657 #ifdef AFS_FREELANCE_CLIENT
1658 if (cm_freelanceEnabled && dscp == cm_rootSCachep) {
1659 /* we are adding the mount point to the root dir., so call
1660 * the freelance code to do the add. */
1661 osi_Log0(afsd_logp,"IoctlDeletelink from Freelance root dir");
1662 code = cm_FreelanceRemoveSymlink(cp);
1667 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
1669 /* if something went wrong, bail out now */
1674 lock_ObtainMutex(&scp->mx);
1675 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1676 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1678 lock_ReleaseMutex(&scp->mx);
1679 cm_ReleaseSCache(scp);
1683 /* now check that this is a real symlink */
1684 if (scp->fileType != CM_SCACHETYPE_SYMLINK) {
1685 lock_ReleaseMutex(&scp->mx);
1686 cm_ReleaseSCache(scp);
1687 code = CM_ERROR_INVAL;
1691 /* time to make the RPC, so drop the lock */
1692 lock_ReleaseMutex(&scp->mx);
1693 cm_ReleaseSCache(scp);
1695 /* easier to do it this way */
1696 code = cm_Unlink(dscp, cp, userp, &req);
1697 if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
1698 smb_NotifyChange(FILE_ACTION_REMOVED,
1699 FILE_NOTIFY_CHANGE_FILE_NAME
1700 | FILE_NOTIFY_CHANGE_DIR_NAME,
1701 dscp, cp, NULL, TRUE);
1704 cm_ReleaseSCache(dscp);
1708 long cm_IoctlSetToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
1715 struct ClearToken ct;
1724 saveDataPtr = ioctlp->inDatap;
1726 cm_SkipIoctlPath(ioctlp);
1728 tp = ioctlp->inDatap;
1731 memcpy(&ticketLen, tp, sizeof(ticketLen));
1732 tp += sizeof(ticketLen);
1733 if (ticketLen < MINKTCTICKETLEN || ticketLen > MAXKTCTICKETLEN)
1734 return CM_ERROR_INVAL;
1736 /* remember ticket and skip over it for now */
1740 /* clear token size */
1741 memcpy(&ctSize, tp, sizeof(ctSize));
1742 tp += sizeof(ctSize);
1743 if (ctSize != sizeof(struct ClearToken))
1744 return CM_ERROR_INVAL;
1747 memcpy(&ct, tp, ctSize);
1749 if (ct.AuthHandle == -1)
1750 ct.AuthHandle = 999; /* more rxvab compat stuff */
1752 /* more stuff, if any */
1753 if (ioctlp->inCopied > tp - saveDataPtr) {
1754 /* flags: logon flag */
1755 memcpy(&flags, tp, sizeof(int));
1759 cellp = cm_GetCell(tp, CM_FLAG_CREATE);
1760 if (!cellp) return CM_ERROR_NOSUCHCELL;
1761 tp += strlen(tp) + 1;
1765 tp += strlen(tp) + 1;
1767 if (flags & PIOCTL_LOGON) {
1768 /* SMB user name with which to associate tokens */
1770 osi_Log2(smb_logp,"cm_IoctlSetToken for user [%s] smbname [%s]",
1771 osi_LogSaveString(smb_logp,uname), osi_LogSaveString(smb_logp,smbname));
1772 fprintf(stderr, "SMB name = %s\n", smbname);
1773 tp += strlen(tp) + 1;
1775 osi_Log1(smb_logp,"cm_IoctlSetToken for user [%s]",
1776 osi_LogSaveString(smb_logp,uname));
1779 #ifndef DJGPP /* for win95, session key is back in pioctl */
1781 memcpy(&uuid, tp, sizeof(uuid));
1782 if (!cm_FindTokenEvent(uuid, sessionKey))
1783 return CM_ERROR_INVAL;
1786 cellp = cm_rootCellp;
1787 osi_Log0(smb_logp,"cm_IoctlSetToken - no name specified");
1790 if (flags & PIOCTL_LOGON) {
1791 userp = smb_FindCMUserByName(smbname, ioctlp->fidp->vcp->rname);
1794 /* store the token */
1795 lock_ObtainMutex(&userp->mx);
1796 ucellp = cm_GetUCell(userp, cellp);
1797 osi_Log1(smb_logp,"cm_IoctlSetToken ucellp %lx", ucellp);
1798 ucellp->ticketLen = ticketLen;
1799 if (ucellp->ticketp)
1800 free(ucellp->ticketp); /* Discard old token if any */
1801 ucellp->ticketp = malloc(ticketLen);
1802 memcpy(ucellp->ticketp, ticket, ticketLen);
1805 * Get the session key from the RPC, rather than from the pioctl.
1808 memcpy(&ucellp->sessionKey, ct.HandShakeKey, sizeof(ct.HandShakeKey));
1810 memcpy(ucellp->sessionKey.data, sessionKey, sizeof(sessionKey));
1812 /* for win95, we are getting the session key from the pioctl */
1813 memcpy(&ucellp->sessionKey, ct.HandShakeKey, sizeof(ct.HandShakeKey));
1815 ucellp->kvno = ct.AuthHandle;
1816 ucellp->expirationTime = ct.EndTimestamp;
1819 StringCbCopyA(ucellp->userName, MAXKTCNAMELEN, uname);
1820 ucellp->flags |= CM_UCELLFLAG_RXKAD;
1821 lock_ReleaseMutex(&userp->mx);
1823 if (flags & PIOCTL_LOGON) {
1824 ioctlp->flags |= SMB_IOCTLFLAG_LOGON;
1827 cm_ResetACLCache(userp);
1832 long cm_IoctlGetTokenIter(struct smb_ioctl *ioctlp, struct cm_user *userp)
1838 struct ClearToken ct;
1840 cm_SkipIoctlPath(ioctlp);
1842 tp = ioctlp->inDatap;
1843 cp = ioctlp->outDatap;
1846 memcpy(&iterator, tp, sizeof(iterator));
1847 tp += sizeof(iterator);
1849 lock_ObtainMutex(&userp->mx);
1851 /* look for token */
1852 for (;;iterator++) {
1853 ucellp = cm_FindUCell(userp, iterator);
1855 lock_ReleaseMutex(&userp->mx);
1856 return CM_ERROR_NOMORETOKENS;
1858 if (ucellp->flags & CM_UCELLFLAG_RXKAD)
1863 temp = ucellp->iterator + 1;
1864 memcpy(cp, &temp, sizeof(temp));
1868 memcpy(cp, &ucellp->ticketLen, sizeof(ucellp->ticketLen));
1869 cp += sizeof(ucellp->ticketLen);
1872 memcpy(cp, ucellp->ticketp, ucellp->ticketLen);
1873 cp += ucellp->ticketLen;
1875 /* clear token size */
1877 memcpy(cp, &temp, sizeof(temp));
1881 ct.AuthHandle = ucellp->kvno;
1884 * Don't give out a real session key here
1887 memcpy(ct.HandShakeKey, &ucellp->sessionKey, sizeof(ct.HandShakeKey));
1889 memset(ct.HandShakeKey, 0, sizeof(ct.HandShakeKey));
1891 memcpy(ct.HandShakeKey, &ucellp->sessionKey, sizeof(ct.HandShakeKey));
1893 ct.ViceId = 37; /* XXX */
1894 ct.BeginTimestamp = 0; /* XXX */
1895 ct.EndTimestamp = ucellp->expirationTime;
1896 memcpy(cp, &ct, sizeof(ct));
1899 /* Primary flag (unused) */
1901 memcpy(cp, &temp, sizeof(temp));
1905 StringCbCopyA(cp, 999999, ucellp->cellp->namep);
1906 cp += strlen(cp) + 1;
1909 StringCbCopyA(cp, 999999, ucellp->userName);
1910 cp += strlen(cp) + 1;
1912 ioctlp->outDatap = cp;
1914 lock_ReleaseMutex(&userp->mx);
1919 long cm_IoctlGetToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
1925 struct ClearToken ct;
1931 cm_SkipIoctlPath(ioctlp);
1933 tp = ioctlp->inDatap;
1935 cp = ioctlp->outDatap;
1937 /* cell name is right here */
1938 cellp = cm_GetCell(tp, 0);
1939 if (!cellp) return CM_ERROR_NOSUCHCELL;
1940 tp += strlen(tp) + 1;
1944 memcpy(&uuid, tp, sizeof(uuid));
1947 lock_ObtainMutex(&userp->mx);
1949 ucellp = cm_GetUCell(userp, cellp);
1950 if (!ucellp || !(ucellp->flags & CM_UCELLFLAG_RXKAD)) {
1951 lock_ReleaseMutex(&userp->mx);
1952 return CM_ERROR_NOMORETOKENS;
1956 memcpy(cp, &ucellp->ticketLen, sizeof(ucellp->ticketLen));
1957 cp += sizeof(ucellp->ticketLen);
1960 memcpy(cp, ucellp->ticketp, ucellp->ticketLen);
1961 cp += ucellp->ticketLen;
1963 /* clear token size */
1965 memcpy(cp, &temp, sizeof(temp));
1969 ct.AuthHandle = ucellp->kvno;
1972 * Don't give out a real session key here
1975 memcpy(ct.HandShakeKey, &ucellp->sessionKey, sizeof(ct.HandShakeKey));
1977 memset(ct.HandShakeKey, 0, sizeof(ct.HandShakeKey));
1979 memcpy(ct.HandShakeKey, &ucellp->sessionKey, sizeof(ct.HandShakeKey));
1981 ct.ViceId = 37; /* XXX */
1982 ct.BeginTimestamp = 0; /* XXX */
1983 ct.EndTimestamp = ucellp->expirationTime;
1984 memcpy(cp, &ct, sizeof(ct));
1987 /* Primary flag (unused) */
1989 memcpy(cp, &temp, sizeof(temp));
1993 StringCbCopyA(cp, 999999, ucellp->cellp->namep);
1994 cp += strlen(cp) + 1;
1997 StringCbCopyA(cp, 999999, ucellp->userName);
1998 cp += strlen(cp) + 1;
2000 ioctlp->outDatap = cp;
2002 lock_ReleaseMutex(&userp->mx);
2005 cm_RegisterNewTokenEvent(uuid, ucellp->sessionKey.data);
2011 long cm_IoctlDelToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
2017 cm_SkipIoctlPath(ioctlp);
2019 cp = ioctlp->outDatap;
2021 /* cell name is right here */
2022 cellp = cm_GetCell(ioctlp->inDatap, 0);
2023 if (!cellp) return CM_ERROR_NOSUCHCELL;
2025 lock_ObtainMutex(&userp->mx);
2027 ucellp = cm_GetUCell(userp, cellp);
2029 lock_ReleaseMutex(&userp->mx);
2030 return CM_ERROR_NOMORETOKENS;
2033 osi_Log1(smb_logp,"cm_IoctlDelToken ucellp %lx", ucellp);
2035 if (ucellp->ticketp) {
2036 free(ucellp->ticketp);
2037 ucellp->ticketp = NULL;
2039 ucellp->flags &= ~CM_UCELLFLAG_RXKAD;
2042 lock_ReleaseMutex(&userp->mx);
2044 cm_ResetACLCache(userp);
2049 long cm_IoctlDelAllToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
2053 lock_ObtainMutex(&userp->mx);
2055 for (ucellp = userp->cellInfop; ucellp; ucellp = ucellp->nextp) {
2056 osi_Log1(smb_logp,"cm_IoctlDelAllToken ucellp %lx", ucellp);
2057 ucellp->flags &= ~CM_UCELLFLAG_RXKAD;
2061 lock_ReleaseMutex(&userp->mx);
2063 cm_ResetACLCache(userp);
2068 long cm_IoctlMakeSubmount(smb_ioctl_t *ioctlp, cm_user_t *userp)
2070 char afspath[MAX_PATH];
2072 int nextAutoSubmount;
2074 DWORD dwType, dwSize;
2079 cm_SkipIoctlPath(ioctlp);
2081 /* Serialize this one, to prevent simultaneous mods
2084 lock_ObtainMutex(&cm_Afsdsbmt_Lock);
2086 /* Parse the input parameters--first the required afs path,
2087 * then the requested submount name (which may be "").
2089 cm_NormalizeAfsPath (afspath, sizeof(afspath), ioctlp->inDatap);
2090 submountreqp = ioctlp->inDatap + (strlen(ioctlp->inDatap)+1);
2092 /* If the caller supplied a suggested submount name, see if
2093 * that submount name is in use... if so, the submount's path
2094 * has to match our path.
2097 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
2098 "SOFTWARE\\OpenAFS\\Client\\Submounts",
2101 REG_OPTION_NON_VOLATILE,
2102 KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
2107 if (submountreqp && *submountreqp) {
2108 char submountPathNormalized[MAX_PATH];
2109 char submountPath[MAX_PATH];
2111 dwSize = sizeof(submountPath);
2112 status = RegQueryValueEx( hkSubmounts, submountreqp, 0,
2113 &dwType, submountPath, &dwSize);
2115 if (status != ERROR_SUCCESS) {
2117 /* The suggested submount name isn't in use now--
2118 * so we can safely map the requested submount name
2119 * to the supplied path. Remember not to write the
2120 * leading "/afs" when writing out the submount.
2122 RegSetValueEx( hkSubmounts, submountreqp, 0,
2124 (strlen(&afspath[strlen(cm_mountRoot)])) ?
2125 &afspath[strlen(cm_mountRoot)]:"/",
2126 (strlen(&afspath[strlen(cm_mountRoot)])) ?
2127 strlen(&afspath[strlen(cm_mountRoot)])+1:2);
2129 RegCloseKey( hkSubmounts );
2130 StringCbCopyA(ioctlp->outDatap, 999999, submountreqp);
2131 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
2132 lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
2136 /* The suggested submount name is already in use--if the
2137 * supplied path matches the submount's path, we can still
2138 * use the suggested submount name.
2140 cm_NormalizeAfsPath (submountPathNormalized, sizeof(submountPathNormalized), submountPath);
2141 if (!strcmp (submountPathNormalized, afspath)) {
2142 StringCbCopyA(ioctlp->outDatap, 999999, submountreqp);
2143 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
2144 RegCloseKey( hkSubmounts );
2145 lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
2150 RegQueryInfoKey( hkSubmounts,
2152 NULL, /* lpcClass */
2153 NULL, /* lpReserved */
2154 NULL, /* lpcSubKeys */
2155 NULL, /* lpcMaxSubKeyLen */
2156 NULL, /* lpcMaxClassLen */
2157 &dwSubmounts, /* lpcValues */
2158 NULL, /* lpcMaxValueNameLen */
2159 NULL, /* lpcMaxValueLen */
2160 NULL, /* lpcbSecurityDescriptor */
2161 NULL /* lpftLastWriteTime */
2165 /* Having obtained a list of all available submounts, start
2166 * searching that list for a path which matches the requested
2167 * AFS path. We'll also keep track of the highest "auto15"/"auto47"
2168 * submount, in case we need to add a new one later.
2171 nextAutoSubmount = 1;
2173 for ( dwIndex = 0; dwIndex < dwSubmounts; dwIndex ++ ) {
2174 char submountPathNormalized[MAX_PATH];
2175 char submountPath[MAX_PATH] = "";
2176 DWORD submountPathLen = sizeof(submountPath);
2177 char submountName[MAX_PATH];
2178 DWORD submountNameLen = sizeof(submountName);
2181 RegEnumValue( hkSubmounts, dwIndex, submountName, &submountNameLen, NULL,
2182 &dwType, submountPath, &submountPathLen);
2183 if (dwType == REG_EXPAND_SZ) {
2185 StringCbCopyA(buf, MAX_PATH, submountPath);
2186 submountPathLen = ExpandEnvironmentStrings(buf, submountPath, MAX_PATH);
2187 if (submountPathLen > MAX_PATH)
2191 /* If this is an Auto### submount, remember its ### value */
2192 if ((!strnicmp (submountName, "auto", 4)) &&
2193 (isdigit (submountName[strlen("auto")]))) {
2194 int thisAutoSubmount;
2195 thisAutoSubmount = atoi (&submountName[strlen("auto")]);
2196 nextAutoSubmount = max (nextAutoSubmount,
2197 thisAutoSubmount+1);
2200 if ((submountPathLen == 0) ||
2201 (submountPathLen == sizeof(submountPath) - 1)) {
2205 /* See if the path for this submount matches the path
2206 * that our caller specified. If so, we can return
2209 cm_NormalizeAfsPath (submountPathNormalized, sizeof(submountPathNormalized), submountPath);
2210 if (!strcmp (submountPathNormalized, afspath)) {
2211 StringCbCopyA(ioctlp->outDatap, 999999, submountName);
2212 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
2213 RegCloseKey(hkSubmounts);
2214 lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
2220 /* We've been through the entire list of existing submounts, and
2221 * didn't find any which matched the specified path. So, we'll
2222 * just have to add one. Remember not to write the leading "/afs"
2223 * when writing out the submount.
2226 StringCbPrintfA(ioctlp->outDatap, 999999, "auto%ld", nextAutoSubmount);
2228 RegSetValueEx( hkSubmounts,
2232 (strlen(&afspath[strlen(cm_mountRoot)])) ?
2233 &afspath[strlen(cm_mountRoot)]:"/",
2234 (strlen(&afspath[strlen(cm_mountRoot)])) ?
2235 strlen(&afspath[strlen(cm_mountRoot)])+1:2);
2237 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
2238 RegCloseKey(hkSubmounts);
2239 lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
2243 long cm_IoctlGetRxkcrypt(smb_ioctl_t *ioctlp, cm_user_t *userp)
2245 memcpy(ioctlp->outDatap, &cryptall, sizeof(cryptall));
2246 ioctlp->outDatap += sizeof(cryptall);
2251 long cm_IoctlSetRxkcrypt(smb_ioctl_t *ioctlp, cm_user_t *userp)
2253 cm_SkipIoctlPath(ioctlp);
2255 memcpy(&cryptall, ioctlp->inDatap, sizeof(cryptall));
2261 extern int afsd_shutdown(int);
2262 extern int afs_shutdown;
2264 long cm_IoctlShutdown(smb_ioctl_t *ioctlp, cm_user_t *userp) {
2265 afs_shutdown = 1; /* flag to shut down */
2270 long cm_IoctlGetSMBName(smb_ioctl_t *ioctlp, cm_user_t *userp)
2272 smb_user_t *uidp = ioctlp->uidp;
2274 if (uidp && uidp->unp) {
2275 memcpy(ioctlp->outDatap, uidp->unp->name, strlen(uidp->unp->name));
2276 ioctlp->outDatap += strlen(uidp->unp->name);
2283 * functions to dump contents of various structures.
2284 * In debug build (linked with crt debug library) will dump allocated but not freed memory
2286 extern int cm_DumpSCache(FILE *outputFile, char *cookie);
2287 extern int cm_DumpBufHashTable(FILE *outputFile, char *cookie);
2288 extern int smb_DumpVCP(FILE *outputFile, char *cookie);
2290 long cm_IoctlMemoryDump(struct smb_ioctl *ioctlp, struct cm_user *userp)
2294 char logfileName[MAX_PATH+1];
2298 static _CrtMemState memstate;
2301 cm_SkipIoctlPath(ioctlp);
2302 memcpy(&inValue, ioctlp->inDatap, sizeof(long));
2306 strncpy(logfileName, getenv("TEMP"), MAX_PATH);
2307 logfileName[MAX_PATH] = '\0';
2311 GetWindowsDirectory(logfileName, sizeof(logfileName));
2313 strncat(logfileName, "\\afsd_alloc.log", sizeof(logfileName));
2315 hLogFile = CreateFile(logfileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
2321 memcpy(ioctlp->outDatap, &inValue, sizeof(long));
2322 ioctlp->outDatap += sizeof(long);
2327 SetFilePointer(hLogFile, 0, NULL, FILE_END);
2329 cookie = inValue ? "b" : "e";
2335 _CrtMemCheckpoint(&memstate);
2339 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
2340 _CrtSetReportFile(_CRT_WARN, hLogFile);
2341 _CrtMemDumpAllObjectsSince(&memstate);
2345 /* dump all interesting data */
2346 cm_DumpSCache(hLogFile, cookie);
2347 cm_DumpBufHashTable(hLogFile, cookie);
2348 smb_DumpVCP(hLogFile, cookie);
2350 CloseHandle(hLogFile);
2352 memcpy(ioctlp->outDatap, &inValue, sizeof(long));
2353 ioctlp->outDatap += sizeof(long);