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, 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 lstrcpy (outpathp, inpathp);
272 else if (!strnicmp (inpathp, bslash_mountRoot, strlen(bslash_mountRoot)))
273 lstrcpy (outpathp, inpathp);
274 else if ((inpathp[0] == '/') || (inpathp[0] == '\\'))
275 sprintf (outpathp, "%s%s", cm_mountRoot, inpathp);
276 else // inpathp looks like "<cell>/usr"
277 sprintf (outpathp, "%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 strcpy (outpathp, cm_mountRoot);
293 /* parse the passed-in file name and do a namei on its parent. If we fail,
294 * return an error code, otherwise return the vnode located in *scpp.
296 long cm_ParseIoctlParent(smb_ioctl_t *ioctlp, cm_user_t *userp, cm_req_t *reqp,
297 cm_scache_t **scpp, char *leafp)
302 cm_scache_t *substRootp;
304 strcpy(tbuffer, ioctlp->inDatap);
305 tp = strrchr(tbuffer, '\\');
306 jp = strrchr(tbuffer, '/');
309 else if (jp && (tp - tbuffer) < (jp - tbuffer))
312 strcpy(tbuffer, "\\");
314 strcpy(leafp, ioctlp->inDatap);
322 if (tbuffer[0] == tbuffer[1] &&
323 tbuffer[1] == '\\' &&
324 !_strnicmp(cm_NetbiosName,tbuffer+2,strlen(cm_NetbiosName)))
330 /* We may have found a UNC path.
331 * If the first component is the NetbiosName,
332 * then throw out the second component (the submount)
333 * since it had better expand into the value of ioctl->tidPathp
336 p = tbuffer + 2 + strlen(cm_NetbiosName) + 1;
337 if ( !_strnicmp("all", p, 3) )
340 for (i = 0; *p && *p != '\\'; i++,p++ ) {
343 p++; /* skip past trailing slash */
344 shareName[i] = 0; /* terminate string */
346 shareFound = smb_FindShare(ioctlp->fidp->vcp, ioctlp->uidp, shareName, &sharePath);
348 /* we found a sharename, therefore use the resulting path */
349 code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
350 CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
351 userp, sharePath, reqp, &substRootp);
353 if (code) return code;
355 code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
356 userp, NULL, reqp, scpp);
357 if (code) return code;
359 /* otherwise, treat the name as a cellname mounted off the afs root.
360 * This requires that we reconstruct the shareName string with
361 * leading and trailing slashes.
363 p = tbuffer + 2 + strlen(cm_NetbiosName) + 1;
364 if ( !_strnicmp("all", p, 3) )
368 for (i = 1; *p && *p != '\\'; i++,p++ ) {
371 p++; /* skip past trailing slash */
372 shareName[i++] = '/'; /* add trailing slash */
373 shareName[i] = 0; /* terminate string */
375 code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
376 CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
377 userp, shareName, reqp, &substRootp);
378 if (code) return code;
380 code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
381 userp, NULL, reqp, scpp);
382 if (code) return code;
385 code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
386 CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
387 userp, ioctlp->tidPathp, reqp, &substRootp);
388 if (code) return code;
390 code = cm_NameI(substRootp, tbuffer, CM_FLAG_FOLLOW,
391 userp, NULL, reqp, scpp);
392 if (code) return code;
395 /* # of bytes of path */
396 code = strlen(ioctlp->inDatap) + 1;
397 ioctlp->inDatap += code;
399 /* and return success */
403 long cm_IoctlGetACL(smb_ioctl_t *ioctlp, cm_user_t *userp)
408 AFSFetchStatus fileStatus;
414 struct rx_connection * callp;
418 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
419 if (code) return code;
421 /* now make the get acl call */
422 fid.Volume = scp->fid.volume;
423 fid.Vnode = scp->fid.vnode;
424 fid.Unique = scp->fid.unique;
426 acl.AFSOpaque_val = ioctlp->outDatap;
427 acl.AFSOpaque_len = 0;
428 code = cm_Conn(&scp->fid, userp, &req, &connp);
431 callp = cm_GetRxConn(connp);
432 code = RXAFS_FetchACL(callp, &fid, &acl, &fileStatus, &volSync);
433 rx_PutConnection(callp);
435 } while (cm_Analyze(connp, userp, &req, &scp->fid, &volSync, NULL, NULL, code));
436 code = cm_MapRPCError(code, &req);
437 cm_ReleaseSCache(scp);
439 if (code) return code;
441 /* skip over return data */
442 tlen = strlen(ioctlp->outDatap) + 1;
443 ioctlp->outDatap += tlen;
445 /* and return success */
449 long cm_IoctlGetFileCellName(struct smb_ioctl *ioctlp, struct cm_user *userp)
458 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
459 if (code) return code;
461 cellp = cm_FindCellByID(scp->fid.cell);
463 strcpy(ioctlp->outDatap, cellp->namep);
464 ioctlp->outDatap += strlen(ioctlp->outDatap) + 1;
467 else code = CM_ERROR_NOSUCHCELL;
469 cm_ReleaseSCache(scp);
473 long cm_IoctlSetACL(struct smb_ioctl *ioctlp, struct cm_user *userp)
478 AFSFetchStatus fileStatus;
483 struct rx_connection * callp;
487 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
488 if (code) return code;
490 /* now make the get acl call */
491 fid.Volume = scp->fid.volume;
492 fid.Vnode = scp->fid.vnode;
493 fid.Unique = scp->fid.unique;
495 acl.AFSOpaque_val = ioctlp->inDatap;
496 acl.AFSOpaque_len = strlen(ioctlp->inDatap)+1;
497 code = cm_Conn(&scp->fid, userp, &req, &connp);
500 callp = cm_GetRxConn(connp);
501 code = RXAFS_StoreACL(callp, &fid, &acl, &fileStatus, &volSync);
502 rx_PutConnection(callp);
504 } while (cm_Analyze(connp, userp, &req, &scp->fid, &volSync, NULL, NULL, code));
505 code = cm_MapRPCError(code, &req);
507 /* invalidate cache info, since we just trashed the ACL cache */
508 lock_ObtainMutex(&scp->mx);
509 cm_DiscardSCache(scp);
510 lock_ReleaseMutex(&scp->mx);
512 cm_ReleaseSCache(scp);
517 long cm_IoctlFlushVolume(struct smb_ioctl *ioctlp, struct cm_user *userp)
521 unsigned long volume;
527 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
528 if (code) return code;
530 volume = scp->fid.volume;
531 cm_ReleaseSCache(scp);
533 lock_ObtainWrite(&cm_scacheLock);
534 for (i=0; i<cm_hashTableSize; i++) {
535 for (scp = cm_hashTablep[i]; scp; scp = scp->nextp) {
536 if (scp->fid.volume == volume) {
538 lock_ReleaseWrite(&cm_scacheLock);
540 /* now flush the file */
541 code = cm_FlushFile(scp, userp, &req);
543 afsi_log("cm_FlushFile returns error: [%x]",code);
544 lock_ObtainWrite(&cm_scacheLock);
549 lock_ReleaseWrite(&cm_scacheLock);
554 long cm_IoctlFlushFile(struct smb_ioctl *ioctlp, struct cm_user *userp)
562 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
563 if (code) return code;
565 cm_FlushFile(scp, userp, &req);
566 cm_ReleaseSCache(scp);
571 long cm_IoctlSetVolumeStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
575 char offLineMsg[256];
579 AFSFetchVolumeStatus volStat;
580 AFSStoreVolumeStatus storeStat;
585 struct rx_connection * callp;
589 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
590 if (code) return code;
592 cellp = cm_FindCellByID(scp->fid.cell);
595 if (scp->flags & CM_SCACHEFLAG_RO) {
596 cm_ReleaseSCache(scp);
597 return CM_ERROR_READONLY;
600 code = cm_GetVolumeByID(cellp, scp->fid.volume, userp, &req, &tvp);
602 cm_ReleaseSCache(scp);
606 /* Copy the junk out, using cp as a roving pointer. */
607 cp = ioctlp->inDatap;
608 memcpy((char *)&volStat, cp, sizeof(AFSFetchVolumeStatus));
609 cp += sizeof(AFSFetchVolumeStatus);
611 cp += strlen(volName)+1;
612 strcpy(offLineMsg, cp);
613 cp += strlen(offLineMsg)+1;
616 if (volStat.MinQuota != -1) {
617 storeStat.MinQuota = volStat.MinQuota;
618 storeStat.Mask |= AFS_SETMINQUOTA;
620 if (volStat.MaxQuota != -1) {
621 storeStat.MaxQuota = volStat.MaxQuota;
622 storeStat.Mask |= AFS_SETMAXQUOTA;
626 code = cm_Conn(&scp->fid, userp, &req, &tcp);
629 callp = cm_GetRxConn(tcp);
630 code = RXAFS_SetVolumeStatus(callp, scp->fid.volume,
631 &storeStat, volName, offLineMsg, motd);
632 rx_PutConnection(callp);
634 } while (cm_Analyze(tcp, userp, &req, &scp->fid, NULL, NULL, NULL, code));
635 code = cm_MapRPCError(code, &req);
637 /* return on failure */
638 cm_ReleaseSCache(scp);
643 /* we are sending parms back to make compat. with prev system. should
644 * change interface later to not ask for current status, just set
647 cp = ioctlp->outDatap;
648 memcpy(cp, (char *)&volStat, sizeof(VolumeStatus));
649 cp += sizeof(VolumeStatus);
651 cp += strlen(volName)+1;
652 strcpy(cp, offLineMsg);
653 cp += strlen(offLineMsg)+1;
655 cp += strlen(motd)+1;
657 /* now return updated return data pointer */
658 ioctlp->outDatap = cp;
663 long cm_IoctlGetVolumeStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
667 char offLineMsg[256];
671 AFSFetchVolumeStatus volStat;
677 struct rx_connection * callp;
681 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
682 if (code) return code;
685 OfflineMsg = offLineMsg;
688 code = cm_Conn(&scp->fid, userp, &req, &tcp);
691 callp = cm_GetRxConn(tcp);
692 code = RXAFS_GetVolumeStatus(callp, scp->fid.volume,
693 &volStat, &Name, &OfflineMsg, &MOTD);
694 rx_PutConnection(callp);
696 } while (cm_Analyze(tcp, userp, &req, &scp->fid, NULL, NULL, NULL, code));
697 code = cm_MapRPCError(code, &req);
699 cm_ReleaseSCache(scp);
700 if (code) return code;
702 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
703 cp = ioctlp->outDatap;
704 memcpy(cp, (char *)&volStat, sizeof(AFSFetchVolumeStatus));
705 cp += sizeof(AFSFetchVolumeStatus);
707 cp += strlen(volName)+1;
708 strcpy(cp, offLineMsg);
709 cp += strlen(offLineMsg)+1;
711 cp += strlen(motd)+1;
713 /* return new size */
714 ioctlp->outDatap = cp;
719 long cm_IoctlWhereIs(struct smb_ioctl *ioctlp, struct cm_user *userp)
725 cm_serverRef_t **tsrpp, *current;
727 unsigned long volume;
733 code = cm_ParseIoctlPath(ioctlp, userp, &req, &scp);
734 if (code) return code;
736 volume = scp->fid.volume;
738 cellp = cm_FindCellByID(scp->fid.cell);
741 cm_ReleaseSCache(scp);
743 code = cm_GetVolumeByID(cellp, volume, userp, &req, &tvp);
744 if (code) return code;
746 cp = ioctlp->outDatap;
748 lock_ObtainMutex(&tvp->mx);
749 tsrpp = cm_GetVolServers(tvp, volume);
750 lock_ObtainRead(&cm_serverLock);
751 for (current = *tsrpp; current; current = current->next) {
752 tsp = current->server;
753 memcpy(cp, (char *)&tsp->addr.sin_addr.s_addr, sizeof(long));
756 lock_ReleaseRead(&cm_serverLock);
757 cm_FreeServerList(tsrpp);
758 lock_ReleaseMutex(&tvp->mx);
760 /* still room for terminating NULL, add it on */
761 volume = 0; /* reuse vbl */
762 memcpy(cp, (char *)&volume, sizeof(long));
765 ioctlp->outDatap = cp;
770 long cm_IoctlStatMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp)
780 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
781 if (code) return code;
783 cp = ioctlp->inDatap;
785 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
786 cm_ReleaseSCache(dscp);
787 if (code) return code;
789 lock_ObtainMutex(&scp->mx);
791 /* now check that this is a real mount point */
792 if (scp->fileType != CM_SCACHETYPE_MOUNTPOINT) {
793 lock_ReleaseMutex(&scp->mx);
794 cm_ReleaseSCache(scp);
795 return CM_ERROR_INVAL;
798 code = cm_ReadMountPoint(scp, userp, &req);
800 cp = ioctlp->outDatap;
801 strcpy(cp, scp->mountPointStringp);
802 cp += strlen(cp) + 1;
803 ioctlp->outDatap = cp;
805 lock_ReleaseMutex(&scp->mx);
806 cm_ReleaseSCache(scp);
811 long cm_IoctlDeleteMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp)
821 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
822 if (code) return code;
824 cp = ioctlp->inDatap;
826 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
828 /* if something went wrong, bail out now */
833 lock_ObtainMutex(&scp->mx);
834 code = cm_SyncOp(scp, NULL, userp, &req, 0,
835 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
837 lock_ReleaseMutex(&scp->mx);
838 cm_ReleaseSCache(scp);
842 /* now check that this is a real mount point */
843 if (scp->fileType != CM_SCACHETYPE_MOUNTPOINT) {
844 lock_ReleaseMutex(&scp->mx);
845 cm_ReleaseSCache(scp);
846 code = CM_ERROR_INVAL;
850 /* time to make the RPC, so drop the lock */
851 lock_ReleaseMutex(&scp->mx);
852 cm_ReleaseSCache(scp);
854 /* easier to do it this way */
855 code = cm_Unlink(dscp, cp, userp, &req);
856 if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
857 smb_NotifyChange(FILE_ACTION_REMOVED,
858 FILE_NOTIFY_CHANGE_DIR_NAME,
859 dscp, cp, NULL, TRUE);
862 cm_ReleaseSCache(dscp);
866 long cm_IoctlCheckServers(struct smb_ioctl *ioctlp, struct cm_user *userp)
876 cm_SkipIoctlPath(ioctlp); /* we don't care about the path */
877 tp = ioctlp->inDatap;
880 memcpy(&temp, tp, sizeof(temp));
881 if (temp == 0x12345678) { /* For afs3.3 version */
882 memcpy(&csi, tp, sizeof(csi));
883 if (csi.tinterval >= 0) {
884 cp = ioctlp->outDatap;
885 memcpy(cp, (char *)&cm_daemonCheckInterval, sizeof(long));
886 ioctlp->outDatap += sizeof(long);
887 if (csi.tinterval > 0) {
888 if (!smb_SUser(userp))
889 return CM_ERROR_NOACCESS;
890 cm_daemonCheckInterval = csi.tinterval;
898 } else { /* For pre afs3.3 versions */
899 memcpy((char *)&temp, ioctlp->inDatap, sizeof(long));
900 ioctlp->inDatap = cp = ioctlp->inDatap + sizeof(long);
901 if (cp - ioctlp->inAllocp < ioctlp->inCopied) /* still more data available */
906 * 1: fast check, don't contact servers.
907 * 2: local cell only.
910 /* have cell name, too */
911 cellp = cm_GetCell(cp, 0);
912 if (!cellp) return CM_ERROR_NOSUCHCELL;
914 else cellp = (cm_cell_t *) 0;
915 if (!cellp && (temp & 2)) {
917 cellp = cm_FindCellByID(1);
919 if (!(temp & 1)) { /* if not fast, call server checker routine */
920 /* check down servers */
921 cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS | CM_FLAG_CHECKUPSERVERS,
925 /* now return the current down server list */
926 cp = ioctlp->outDatap;
927 lock_ObtainRead(&cm_serverLock);
928 for (tsp = cm_allServersp; tsp; tsp=tsp->allNextp) {
929 if (cellp && tsp->cellp != cellp) continue; /* cell spec'd and wrong */
930 if ((tsp->flags & CM_SERVERFLAG_DOWN)
931 && tsp->type == CM_SERVER_FILE) {
932 memcpy(cp, (char *)&tsp->addr.sin_addr.s_addr, sizeof(long));
936 lock_ReleaseRead(&cm_serverLock);
938 ioctlp->outDatap = cp;
942 long cm_IoctlGag(struct smb_ioctl *ioctlp, struct cm_user *userp)
944 /* we don't print anything superfluous, so we don't support the gag call */
945 return CM_ERROR_INVAL;
948 long cm_IoctlCheckVolumes(struct smb_ioctl *ioctlp, struct cm_user *userp)
954 long cm_IoctlSetCacheSize(struct smb_ioctl *ioctlp, struct cm_user *userp)
959 cm_SkipIoctlPath(ioctlp);
961 memcpy(&temp, ioctlp->inDatap, sizeof(temp));
963 temp = buf_nOrigBuffers;
965 /* temp is in 1K units, convert to # of buffers */
966 temp = temp / (buf_bufferSize / 1024);
969 /* now adjust the cache size */
970 code = buf_SetNBuffers(temp);
975 long cm_IoctlTraceControl(struct smb_ioctl *ioctlp, struct cm_user *userp)
979 cm_SkipIoctlPath(ioctlp);
981 memcpy(&inValue, ioctlp->inDatap, sizeof(long));
985 afsd_ForceTrace(FALSE);
989 /* set tracing value to low order bit */
990 if ((inValue & 1) == 0) {
991 /* disable tracing */
992 osi_LogDisable(afsd_logp);
996 osi_LogEnable(afsd_logp);
1000 /* see if we're supposed to do a reset, too */
1002 osi_LogReset(afsd_logp);
1005 /* and copy out tracing flag */
1006 inValue = afsd_logp->enabled; /* use as a temp vbl */
1007 memcpy(ioctlp->outDatap, &inValue, sizeof(long));
1008 ioctlp->outDatap += sizeof(long);
1012 long cm_IoctlGetCacheParms(struct smb_ioctl *ioctlp, struct cm_user *userp)
1014 cm_cacheParms_t parms;
1016 memset(&parms, 0, sizeof(parms));
1018 /* first we get, in 1K units, the cache size */
1019 parms.parms[0] = buf_nbuffers * (buf_bufferSize / 1024);
1021 /* and then the actual # of buffers in use (not in the free list, I guess,
1022 * will be what we do).
1024 parms.parms[1] = (buf_nbuffers - buf_CountFreeList()) * (buf_bufferSize / 1024);
1026 memcpy(ioctlp->outDatap, &parms, sizeof(parms));
1027 ioctlp->outDatap += sizeof(parms);
1032 long cm_IoctlGetCell(struct smb_ioctl *ioctlp, struct cm_user *userp)
1037 cm_serverRef_t *serverRefp;
1038 cm_server_t *serverp;
1044 cm_SkipIoctlPath(ioctlp);
1046 tp = ioctlp->inDatap;
1048 memcpy((char *)&whichCell, tp, sizeof(long));
1051 /* see if more than one long passed in, ignoring the null pathname (the -1) */
1052 if (ioctlp->inCopied-1 > sizeof(long)) {
1053 memcpy((char *)&magic, tp, sizeof(long));
1056 lock_ObtainRead(&cm_cellLock);
1057 for (tcellp = cm_allCellsp; tcellp; tcellp = tcellp->nextp) {
1058 if (whichCell == 0) break;
1061 lock_ReleaseRead(&cm_cellLock);
1065 cp = ioctlp->outDatap;
1067 if (magic == 0x12345678) {
1068 memcpy(cp, (char *)&magic, sizeof(long));
1071 memset(cp, 0, max * sizeof(long));
1073 lock_ObtainRead(&cm_serverLock); /* for going down server list */
1074 /* jaltman - do the reference counts to serverRefp contents need to be increased? */
1075 serverRefp = tcellp->vlServersp;
1076 for (i=0; i<max; i++) {
1077 if (!serverRefp) break;
1078 serverp = serverRefp->server;
1079 memcpy(cp, &serverp->addr.sin_addr.s_addr, sizeof(long));
1081 serverRefp = serverRefp->next;
1083 lock_ReleaseRead(&cm_serverLock);
1084 cp = basep + max * sizeof(afs_int32);
1085 strcpy(cp, tcellp->namep);
1086 cp += strlen(tcellp->namep)+1;
1087 ioctlp->outDatap = cp;
1093 return CM_ERROR_NOMORETOKENS; /* mapped to EDOM */
1096 extern long cm_AddCellProc(void *rockp, struct sockaddr_in *addrp, char *namep);
1098 long cm_IoctlNewCell(struct smb_ioctl *ioctlp, struct cm_user *userp)
1100 /* NT cache manager will read cell information from afsdcell.ini each time
1101 * cell is accessed. So, this call is necessary only if list of server for a cell
1102 * changes (or IP addresses of cell servers changes).
1103 * All that needs to be done is to refresh server information for all cells that
1104 * are already loaded.
1106 * cell list will be cm_CellLock and cm_ServerLock will be held for write.
1111 cm_SkipIoctlPath(ioctlp);
1112 lock_ObtainWrite(&cm_cellLock);
1114 for (cp = cm_allCellsp; cp; cp=cp->nextp)
1117 /* delete all previous server lists - cm_FreeServerList will ask for write on cm_ServerLock*/
1118 cm_FreeServerList(&cp->vlServersp);
1119 cp->vlServersp = NULL;
1120 code = cm_SearchCellFile(cp->namep, cp->namep, cm_AddCellProc, cp);
1121 #ifdef AFS_AFSDB_ENV
1123 if (cm_dnsEnabled) {
1125 code = cm_SearchCellByDNS(cp->namep, cp->namep, &ttl, cm_AddCellProc, cp);
1126 if ( code == 0 ) { /* got cell from DNS */
1127 cp->flags |= CM_CELLFLAG_DNS;
1128 cp->flags &= ~CM_CELLFLAG_VLSERVER_INVALID;
1129 cp->timeout = time(0) + ttl;
1134 cp->flags &= ~CM_CELLFLAG_DNS;
1136 #endif /* AFS_AFSDB_ENV */
1138 cp->flags |= CM_CELLFLAG_VLSERVER_INVALID;
1141 cp->flags &= ~CM_CELLFLAG_VLSERVER_INVALID;
1142 cm_RandomizeServer(&cp->vlServersp);
1146 lock_ReleaseWrite(&cm_cellLock);
1150 long cm_IoctlGetWsCell(smb_ioctl_t *ioctlp, cm_user_t *userp)
1152 /* if we don't know our default cell, return failure */
1153 if (cm_rootCellp == NULL) {
1154 return CM_ERROR_NOSUCHCELL;
1157 /* return the default cellname to the caller */
1158 strcpy(ioctlp->outDatap, cm_rootCellp->namep);
1159 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
1165 long cm_IoctlSysName(struct smb_ioctl *ioctlp, struct cm_user *userp)
1167 long setSysName, foundname = 0;
1168 char *cp, *cp2, inname[MAXSYSNAME], outname[MAXSYSNAME];
1169 int t, count, num = 0;
1170 char **sysnamelist[MAXSYSNAME];
1172 cm_SkipIoctlPath(ioctlp);
1174 memcpy(&setSysName, ioctlp->inDatap, sizeof(long));
1175 ioctlp->inDatap += sizeof(long);
1179 if ( setSysName < 0 || setSysName > MAXNUMSYSNAMES )
1181 cp2 = ioctlp->inDatap;
1182 for ( cp=ioctlp->inDatap, count = 0; count < setSysName; count++ ) {
1183 /* won't go past end of ioctlp->inDatap since maxsysname*num < ioctlp->inDatap length */
1185 if (t >= MAXSYSNAME || t <= 0)
1187 /* check for names that can shoot us in the foot */
1188 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
1194 /* inname gets first entry in case we're being a translator */
1195 /* (we are never a translator) */
1196 t = strlen(ioctlp->inDatap);
1197 memcpy(inname, ioctlp->inDatap, t + 1);
1198 ioctlp->inDatap += t + 1;
1202 /* Not xlating, so local case */
1204 osi_panic("cm_IoctlSysName: !cm_sysName\n", __FILE__, __LINE__);
1206 if (!setSysName) { /* user just wants the info */
1207 strcpy(outname, cm_sysName);
1208 foundname = cm_sysNameCount;
1209 *sysnamelist = cm_sysNameList;
1211 /* Local guy; only root can change sysname */
1212 /* clear @sys entries from the dnlc, once afs_lookup can
1213 * do lookups of @sys entries and thinks it can trust them */
1214 /* privs ok, store the entry, ... */
1215 strcpy(cm_sysName, inname);
1216 if (setSysName > 1) { /* ... or list */
1217 cp = ioctlp->inDatap;
1218 for (count = 1; count < setSysName; ++count) {
1219 if (!cm_sysNameList[count])
1220 osi_panic("cm_IoctlSysName: no cm_sysNameList entry to write\n",
1221 __FILE__, __LINE__);
1223 memcpy(cm_sysNameList[count], cp, t + 1); /* include null */
1227 cm_sysNameCount = setSysName;
1231 /* return the sysname to the caller */
1232 cp = ioctlp->outDatap;
1233 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
1234 cp += sizeof(afs_int32); /* skip found flag */
1236 strcpy(cp, outname);
1237 cp += strlen(outname) + 1; /* skip name and terminating null char */
1238 for ( count=1; count < foundname ; ++count) { /* ... or list */
1239 if ( !(*sysnamelist)[count] )
1240 osi_panic("cm_IoctlSysName: no cm_sysNameList entry to read\n",
1241 __FILE__, __LINE__);
1242 t = strlen((*sysnamelist)[count]);
1243 if (t >= MAXSYSNAME)
1244 osi_panic("cm_IoctlSysName: sysname entry garbled\n",
1245 __FILE__, __LINE__);
1246 strcpy(cp, (*sysnamelist)[count]);
1250 ioctlp->outDatap = cp;
1257 long cm_IoctlGetCellStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
1262 cm_SkipIoctlPath(ioctlp);
1264 cellp = cm_GetCell(ioctlp->inDatap, 0);
1266 return CM_ERROR_NOSUCHCELL;
1269 lock_ObtainMutex(&cellp->mx);
1270 if (cellp->flags & CM_CELLFLAG_SUID)
1271 temp |= CM_SETCELLFLAG_SUID;
1272 lock_ReleaseMutex(&cellp->mx);
1274 /* now copy out parm */
1275 memcpy(ioctlp->outDatap, &temp, sizeof(long));
1276 ioctlp->outDatap += sizeof(long);
1281 long cm_IoctlSetCellStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
1286 cm_SkipIoctlPath(ioctlp);
1288 cellp = cm_GetCell(ioctlp->inDatap + 2*sizeof(long), 0);
1290 return CM_ERROR_NOSUCHCELL;
1292 memcpy((char *)&temp, ioctlp->inDatap, sizeof(long));
1294 lock_ObtainMutex(&cellp->mx);
1295 if (temp & CM_SETCELLFLAG_SUID)
1296 cellp->flags |= CM_CELLFLAG_SUID;
1298 cellp->flags &= ~CM_CELLFLAG_SUID;
1299 lock_ReleaseMutex(&cellp->mx);
1304 long cm_IoctlSetSPrefs(struct smb_ioctl *ioctlp, struct cm_user *userp)
1306 cm_SSetPref_t *spin; /* input */
1307 cm_SPref_t *srvin; /* one input component */
1309 int i, vlonly, noServers, type;
1310 struct sockaddr_in tmp;
1311 unsigned short rank;
1313 cm_SkipIoctlPath(ioctlp); /* we don't care about the path */
1315 spin = (cm_SSetPref_t *)ioctlp->inDatap;
1316 noServers = spin->num_servers;
1317 vlonly = spin->flags;
1319 type = CM_SERVER_VLDB;
1321 type = CM_SERVER_FILE;
1323 for ( i=0; i < noServers; i++)
1325 srvin = &(spin->servers[i]);
1326 rank = srvin->rank + (rand() & 0x000f);
1327 tmp.sin_addr = srvin->host;
1328 tmp.sin_family = AF_INET;
1330 tsp = cm_FindServer(&tmp, type);
1331 if ( tsp ) /* an existing server - ref count increased */
1333 tsp->ipRank = rank; /* no need to protect by mutex*/
1335 if ( type == CM_SERVER_FILE) /* fileserver */
1337 /* find volumes which might have RO copy
1338 /* on server and change the ordering of
1340 cm_ChangeRankVolume(tsp);
1344 /* set preferences for an existing vlserver */
1345 cm_ChangeRankCellVLServer(tsp);
1347 cm_PutServer(tsp); /* decrease refcount */
1349 else /* add a new server without a cell */
1351 tsp = cm_NewServer(&tmp, type, NULL); /* refcount = 1 */
1358 long cm_IoctlGetSPrefs(struct smb_ioctl *ioctlp, struct cm_user *userp)
1360 cm_SPrefRequest_t *spin; /* input */
1361 cm_SPrefInfo_t *spout; /* output */
1362 cm_SPref_t *srvout; /* one output component */
1364 int i, vlonly, noServers;
1366 cm_SkipIoctlPath(ioctlp); /* we don't care about the path */
1368 spin = (cm_SPrefRequest_t *)ioctlp->inDatap;
1369 spout = (cm_SPrefInfo_t *) ioctlp->outDatap;
1370 srvout = spout->servers;
1371 noServers = spin->num_servers;
1372 vlonly = spin->flags & CM_SPREF_VLONLY;
1373 spout->num_servers = 0;
1375 lock_ObtainRead(&cm_serverLock); /* get server lock */
1377 for (tsp=cm_allServersp, i=0; tsp && noServers; tsp=tsp->allNextp,i++){
1378 if (spin->offset > i) {
1379 continue; /* catch up to where we left off */
1382 if ( vlonly && (tsp->type == CM_SERVER_FILE) )
1383 continue; /* ignore fileserver for -vlserver option*/
1384 if ( !vlonly && (tsp->type == CM_SERVER_VLDB) )
1385 continue; /* ignore vlservers */
1387 srvout->host = tsp->addr.sin_addr;
1388 srvout->rank = tsp->ipRank;
1390 spout->num_servers++;
1393 lock_ReleaseRead(&cm_serverLock); /* release server lock */
1395 if ( tsp ) /* we ran out of space in the output buffer */
1396 spout->next_offset = i;
1398 spout->next_offset = 0;
1399 ioctlp->outDatap += sizeof(cm_SPrefInfo_t) +
1400 (spout->num_servers -1 ) * sizeof(cm_SPref_t) ;
1404 long cm_IoctlStoreBehind(struct smb_ioctl *ioctlp, struct cm_user *userp)
1406 /* we ignore default asynchrony since we only have one way
1407 * of doing this today.
1412 long cm_IoctlCreateMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp)
1428 code = cm_ParseIoctlParent(ioctlp, userp, &req, &dscp, leaf);
1429 if (code) return code;
1431 /* Translate chars for the mount point name */
1432 TranslateExtendedChars(leaf);
1435 * The fs command allows the user to specify partial cell names on NT. These must
1436 * be expanded to the full cell name for mount points so that the mount points will
1437 * work on UNIX clients.
1440 /* Extract the possibly partial cell name */
1441 strcpy(cell, ioctlp->inDatap + 1); /* Skip the mp type character */
1443 if (cp = strchr(cell, ':')) {
1444 /* Extract the volume name */
1446 strcpy(volume, cp + 1);
1448 /* Get the full name for this cell */
1449 code = cm_SearchCellFile(cell, fullCell, 0, 0);
1450 #ifdef AFS_AFSDB_ENV
1451 if (code && cm_dnsEnabled)
1452 code = cm_SearchCellByDNS(cell, fullCell, &ttl, 0, 0);
1455 return CM_ERROR_NOSUCHCELL;
1457 sprintf(mpInfo, "%c%s:%s", *ioctlp->inDatap, fullCell, volume);
1459 /* No cell name specified */
1460 strcpy(mpInfo, ioctlp->inDatap);
1463 #ifdef AFS_FREELANCE_CLIENT
1464 if (cm_freelanceEnabled && dscp == cm_rootSCachep) {
1465 /* we are adding the mount point to the root dir., so call
1466 * the freelance code to do the add. */
1467 osi_Log0(afsd_logp,"IoctlCreateMountPoint within Freelance root dir");
1468 code = cm_FreelanceAddMount(leaf, fullCell, volume,
1469 *ioctlp->inDatap == '%', NULL);
1473 /* create the symlink with mode 644. The lack of X bits tells
1474 * us that it is a mount point.
1476 tattr.mask = CM_ATTRMASK_UNIXMODEBITS | CM_ATTRMASK_CLIENTMODTIME;
1477 tattr.unixModeBits = 0644;
1478 tattr.clientModTime = time(NULL);
1480 code = cm_SymLink(dscp, leaf, mpInfo, 0, &tattr, userp, &req);
1481 if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
1482 smb_NotifyChange(FILE_ACTION_ADDED,
1483 FILE_NOTIFY_CHANGE_DIR_NAME,
1484 dscp, leaf, NULL, TRUE);
1486 cm_ReleaseSCache(dscp);
1490 long cm_IoctlSymlink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1501 code = cm_ParseIoctlParent(ioctlp, userp, &req, &dscp, leaf);
1502 if (code) return code;
1504 /* Translate chars for the link name */
1505 TranslateExtendedChars(leaf);
1507 /* Translate chars for the linked to name */
1508 TranslateExtendedChars(ioctlp->inDatap);
1510 cp = ioctlp->inDatap; /* contents of link */
1512 /* Create symlink with mode 0755. */
1513 tattr.mask = CM_ATTRMASK_UNIXMODEBITS;
1514 tattr.unixModeBits = 0755;
1516 code = cm_SymLink(dscp, leaf, cp, 0, &tattr, userp, &req);
1517 if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
1518 smb_NotifyChange(FILE_ACTION_ADDED,
1519 FILE_NOTIFY_CHANGE_FILE_NAME
1520 | FILE_NOTIFY_CHANGE_DIR_NAME,
1521 dscp, leaf, NULL, TRUE);
1523 cm_ReleaseSCache(dscp);
1528 extern long cm_AssembleLink(cm_scache_t *linkScp, char *pathSuffixp,
1529 cm_scache_t **newRootScpp, cm_space_t **newSpaceBufferp,
1530 cm_user_t *userp, cm_req_t *reqp);
1532 long cm_IoctlListlink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1539 cm_scache_t *newRootScp;
1544 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
1545 if (code) return code;
1547 cp = ioctlp->inDatap;
1549 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
1550 cm_ReleaseSCache(dscp);
1551 if (code) return code;
1553 /* Check that it's a real symlink */
1554 if (scp->fileType != CM_SCACHETYPE_SYMLINK){
1555 cm_ReleaseSCache(scp);
1556 return CM_ERROR_INVAL;
1559 code = cm_AssembleLink(scp, "", &newRootScp, &spacep, userp, &req);
1560 cm_ReleaseSCache(scp);
1562 cp = ioctlp->outDatap;
1563 if (newRootScp != NULL) {
1564 strcpy(cp, cm_mountRoot);
1568 strcpy(cp, spacep->data);
1569 cp += strlen(cp) + 1;
1570 ioctlp->outDatap = cp;
1571 cm_FreeSpace(spacep);
1572 if (newRootScp != NULL)
1573 cm_ReleaseSCache(newRootScp);
1579 long cm_IoctlIslink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1580 {/*CHECK FOR VALID SYMLINK*/
1589 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
1590 if (code) return code;
1592 cp = ioctlp->inDatap;
1593 osi_LogEvent("cm_IoctlListlink",NULL," name[%s]",cp);
1595 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
1596 cm_ReleaseSCache(dscp);
1597 if (code) return code;
1599 /* Check that it's a real symlink */
1600 if (scp->fileType != CM_SCACHETYPE_SYMLINK)
1601 code = CM_ERROR_INVAL;
1602 cm_ReleaseSCache(scp);
1606 long cm_IoctlDeletelink(struct smb_ioctl *ioctlp, struct cm_user *userp)
1616 code = cm_ParseIoctlPath(ioctlp, userp, &req, &dscp);
1617 if (code) return code;
1619 cp = ioctlp->inDatap;
1621 code = cm_Lookup(dscp, cp, CM_FLAG_NOMOUNTCHASE, userp, &req, &scp);
1623 /* if something went wrong, bail out now */
1628 lock_ObtainMutex(&scp->mx);
1629 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1630 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1632 lock_ReleaseMutex(&scp->mx);
1633 cm_ReleaseSCache(scp);
1637 /* now check that this is a real symlink */
1638 if (scp->fileType != CM_SCACHETYPE_SYMLINK) {
1639 lock_ReleaseMutex(&scp->mx);
1640 cm_ReleaseSCache(scp);
1641 code = CM_ERROR_INVAL;
1645 /* time to make the RPC, so drop the lock */
1646 lock_ReleaseMutex(&scp->mx);
1647 cm_ReleaseSCache(scp);
1649 /* easier to do it this way */
1650 code = cm_Unlink(dscp, cp, userp, &req);
1651 if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
1652 smb_NotifyChange(FILE_ACTION_REMOVED,
1653 FILE_NOTIFY_CHANGE_FILE_NAME
1654 | FILE_NOTIFY_CHANGE_DIR_NAME,
1655 dscp, cp, NULL, TRUE);
1658 cm_ReleaseSCache(dscp);
1662 long cm_IoctlSetToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
1669 struct ClearToken ct;
1678 saveDataPtr = ioctlp->inDatap;
1680 cm_SkipIoctlPath(ioctlp);
1682 tp = ioctlp->inDatap;
1685 memcpy(&ticketLen, tp, sizeof(ticketLen));
1686 tp += sizeof(ticketLen);
1687 if (ticketLen < MINKTCTICKETLEN || ticketLen > MAXKTCTICKETLEN)
1688 return CM_ERROR_INVAL;
1690 /* remember ticket and skip over it for now */
1694 /* clear token size */
1695 memcpy(&ctSize, tp, sizeof(ctSize));
1696 tp += sizeof(ctSize);
1697 if (ctSize != sizeof(struct ClearToken))
1698 return CM_ERROR_INVAL;
1701 memcpy(&ct, tp, ctSize);
1703 if (ct.AuthHandle == -1)
1704 ct.AuthHandle = 999; /* more rxvab compat stuff */
1706 /* more stuff, if any */
1707 if (ioctlp->inCopied > tp - saveDataPtr) {
1708 /* flags: logon flag */
1709 memcpy(&flags, tp, sizeof(int));
1713 cellp = cm_GetCell(tp, CM_FLAG_CREATE);
1714 if (!cellp) return CM_ERROR_NOSUCHCELL;
1715 tp += strlen(tp) + 1;
1719 tp += strlen(tp) + 1;
1721 if (flags & PIOCTL_LOGON) {
1722 /* SMB user name with which to associate tokens */
1724 osi_Log2(smb_logp,"cm_IoctlSetToken for user [%s] smbname [%s]",
1725 osi_LogSaveString(smb_logp,uname), osi_LogSaveString(smb_logp,smbname));
1726 fprintf(stderr, "SMB name = %s\n", smbname);
1727 tp += strlen(tp) + 1;
1729 osi_Log1(smb_logp,"cm_IoctlSetToken for user [%s]",
1730 osi_LogSaveString(smb_logp,uname));
1733 #ifndef DJGPP /* for win95, session key is back in pioctl */
1735 memcpy(&uuid, tp, sizeof(uuid));
1736 if (!cm_FindTokenEvent(uuid, sessionKey))
1737 return CM_ERROR_INVAL;
1740 cellp = cm_rootCellp;
1741 osi_Log0(smb_logp,"cm_IoctlSetToken - no name specified");
1744 if (flags & PIOCTL_LOGON) {
1745 userp = smb_FindCMUserByName(smbname, ioctlp->fidp->vcp->rname);
1748 /* store the token */
1749 lock_ObtainMutex(&userp->mx);
1750 ucellp = cm_GetUCell(userp, cellp);
1751 osi_Log1(smb_logp,"cm_IoctlSetToken ucellp %lx", ucellp);
1752 ucellp->ticketLen = ticketLen;
1753 if (ucellp->ticketp)
1754 free(ucellp->ticketp); /* Discard old token if any */
1755 ucellp->ticketp = malloc(ticketLen);
1756 memcpy(ucellp->ticketp, ticket, ticketLen);
1759 * Get the session key from the RPC, rather than from the pioctl.
1762 memcpy(&ucellp->sessionKey, ct.HandShakeKey, sizeof(ct.HandShakeKey));
1764 memcpy(ucellp->sessionKey.data, sessionKey, sizeof(sessionKey));
1766 /* for win95, we are getting the session key from the pioctl */
1767 memcpy(&ucellp->sessionKey, ct.HandShakeKey, sizeof(ct.HandShakeKey));
1769 ucellp->kvno = ct.AuthHandle;
1770 ucellp->expirationTime = ct.EndTimestamp;
1772 if (uname) strcpy(ucellp->userName, uname);
1773 ucellp->flags |= CM_UCELLFLAG_RXKAD;
1774 lock_ReleaseMutex(&userp->mx);
1776 if (flags & PIOCTL_LOGON) {
1777 ioctlp->flags |= SMB_IOCTLFLAG_LOGON;
1780 cm_ResetACLCache(userp);
1785 long cm_IoctlGetTokenIter(struct smb_ioctl *ioctlp, struct cm_user *userp)
1791 struct ClearToken ct;
1793 cm_SkipIoctlPath(ioctlp);
1795 tp = ioctlp->inDatap;
1796 cp = ioctlp->outDatap;
1799 memcpy(&iterator, tp, sizeof(iterator));
1800 tp += sizeof(iterator);
1802 lock_ObtainMutex(&userp->mx);
1804 /* look for token */
1805 for (;;iterator++) {
1806 ucellp = cm_FindUCell(userp, iterator);
1808 lock_ReleaseMutex(&userp->mx);
1809 return CM_ERROR_NOMORETOKENS;
1811 if (ucellp->flags & CM_UCELLFLAG_RXKAD)
1816 temp = ucellp->iterator + 1;
1817 memcpy(cp, &temp, sizeof(temp));
1821 memcpy(cp, &ucellp->ticketLen, sizeof(ucellp->ticketLen));
1822 cp += sizeof(ucellp->ticketLen);
1825 memcpy(cp, ucellp->ticketp, ucellp->ticketLen);
1826 cp += ucellp->ticketLen;
1828 /* clear token size */
1830 memcpy(cp, &temp, sizeof(temp));
1834 ct.AuthHandle = ucellp->kvno;
1837 * Don't give out a real session key here
1840 memcpy(ct.HandShakeKey, &ucellp->sessionKey, sizeof(ct.HandShakeKey));
1842 memset(ct.HandShakeKey, 0, sizeof(ct.HandShakeKey));
1844 memcpy(ct.HandShakeKey, &ucellp->sessionKey, sizeof(ct.HandShakeKey));
1846 ct.ViceId = 37; /* XXX */
1847 ct.BeginTimestamp = 0; /* XXX */
1848 ct.EndTimestamp = ucellp->expirationTime;
1849 memcpy(cp, &ct, sizeof(ct));
1852 /* Primary flag (unused) */
1854 memcpy(cp, &temp, sizeof(temp));
1858 strcpy(cp, ucellp->cellp->namep);
1859 cp += strlen(cp) + 1;
1862 strcpy(cp, ucellp->userName);
1863 cp += strlen(cp) + 1;
1865 ioctlp->outDatap = cp;
1867 lock_ReleaseMutex(&userp->mx);
1872 long cm_IoctlGetToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
1878 struct ClearToken ct;
1884 cm_SkipIoctlPath(ioctlp);
1886 tp = ioctlp->inDatap;
1888 cp = ioctlp->outDatap;
1890 /* cell name is right here */
1891 cellp = cm_GetCell(tp, 0);
1892 if (!cellp) return CM_ERROR_NOSUCHCELL;
1893 tp += strlen(tp) + 1;
1897 memcpy(&uuid, tp, sizeof(uuid));
1900 lock_ObtainMutex(&userp->mx);
1902 ucellp = cm_GetUCell(userp, cellp);
1903 if (!ucellp || !(ucellp->flags & CM_UCELLFLAG_RXKAD)) {
1904 lock_ReleaseMutex(&userp->mx);
1905 return CM_ERROR_NOMORETOKENS;
1909 memcpy(cp, &ucellp->ticketLen, sizeof(ucellp->ticketLen));
1910 cp += sizeof(ucellp->ticketLen);
1913 memcpy(cp, ucellp->ticketp, ucellp->ticketLen);
1914 cp += ucellp->ticketLen;
1916 /* clear token size */
1918 memcpy(cp, &temp, sizeof(temp));
1922 ct.AuthHandle = ucellp->kvno;
1925 * Don't give out a real session key here
1928 memcpy(ct.HandShakeKey, &ucellp->sessionKey, sizeof(ct.HandShakeKey));
1930 memset(ct.HandShakeKey, 0, sizeof(ct.HandShakeKey));
1932 memcpy(ct.HandShakeKey, &ucellp->sessionKey, sizeof(ct.HandShakeKey));
1934 ct.ViceId = 37; /* XXX */
1935 ct.BeginTimestamp = 0; /* XXX */
1936 ct.EndTimestamp = ucellp->expirationTime;
1937 memcpy(cp, &ct, sizeof(ct));
1940 /* Primary flag (unused) */
1942 memcpy(cp, &temp, sizeof(temp));
1946 strcpy(cp, ucellp->cellp->namep);
1947 cp += strlen(cp) + 1;
1950 strcpy(cp, ucellp->userName);
1951 cp += strlen(cp) + 1;
1953 ioctlp->outDatap = cp;
1955 lock_ReleaseMutex(&userp->mx);
1958 cm_RegisterNewTokenEvent(uuid, ucellp->sessionKey.data);
1964 long cm_IoctlDelToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
1970 cm_SkipIoctlPath(ioctlp);
1972 cp = ioctlp->outDatap;
1974 /* cell name is right here */
1975 cellp = cm_GetCell(ioctlp->inDatap, 0);
1976 if (!cellp) return CM_ERROR_NOSUCHCELL;
1978 lock_ObtainMutex(&userp->mx);
1980 ucellp = cm_GetUCell(userp, cellp);
1982 lock_ReleaseMutex(&userp->mx);
1983 return CM_ERROR_NOMORETOKENS;
1986 osi_Log1(smb_logp,"cm_IoctlDelToken ucellp %lx", ucellp);
1988 if (ucellp->ticketp) {
1989 free(ucellp->ticketp);
1990 ucellp->ticketp = NULL;
1992 ucellp->flags &= ~CM_UCELLFLAG_RXKAD;
1995 lock_ReleaseMutex(&userp->mx);
1997 cm_ResetACLCache(userp);
2002 long cm_IoctlDelAllToken(struct smb_ioctl *ioctlp, struct cm_user *userp)
2006 lock_ObtainMutex(&userp->mx);
2008 for (ucellp = userp->cellInfop; ucellp; ucellp = ucellp->nextp) {
2009 osi_Log1(smb_logp,"cm_IoctlDelAllToken ucellp %lx", ucellp);
2010 ucellp->flags &= ~CM_UCELLFLAG_RXKAD;
2014 lock_ReleaseMutex(&userp->mx);
2016 cm_ResetACLCache(userp);
2021 long cm_IoctlMakeSubmount(smb_ioctl_t *ioctlp, cm_user_t *userp)
2023 char afspath[MAX_PATH];
2025 int nextAutoSubmount;
2027 DWORD dwType, dwSize;
2032 cm_SkipIoctlPath(ioctlp);
2034 /* Serialize this one, to prevent simultaneous mods
2037 lock_ObtainMutex(&cm_Afsdsbmt_Lock);
2039 /* Parse the input parameters--first the required afs path,
2040 * then the requested submount name (which may be "").
2042 cm_NormalizeAfsPath (afspath, ioctlp->inDatap);
2043 submountreqp = ioctlp->inDatap + (strlen(ioctlp->inDatap)+1);
2045 /* If the caller supplied a suggested submount name, see if
2046 * that submount name is in use... if so, the submount's path
2047 * has to match our path.
2050 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
2051 "SOFTWARE\\OpenAFS\\Client\\Submounts",
2054 REG_OPTION_NON_VOLATILE,
2055 KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
2060 if (submountreqp && *submountreqp) {
2061 char submountPathNormalized[MAX_PATH];
2062 char submountPath[MAX_PATH];
2064 dwSize = sizeof(submountPath);
2065 status = RegQueryValueEx( hkSubmounts, submountreqp, 0,
2066 &dwType, submountPath, &dwSize);
2068 if (status != ERROR_SUCCESS) {
2070 /* The suggested submount name isn't in use now--
2071 * so we can safely map the requested submount name
2072 * to the supplied path. Remember not to write the
2073 * leading "/afs" when writing out the submount.
2075 RegSetValueEx( hkSubmounts, submountreqp, 0,
2077 (strlen(&afspath[strlen(cm_mountRoot)])) ?
2078 &afspath[strlen(cm_mountRoot)]:"/",
2079 (strlen(&afspath[strlen(cm_mountRoot)])) ?
2080 strlen(&afspath[strlen(cm_mountRoot)])+1:2);
2082 RegCloseKey( hkSubmounts );
2083 strcpy(ioctlp->outDatap, submountreqp);
2084 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
2085 lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
2089 /* The suggested submount name is already in use--if the
2090 * supplied path matches the submount's path, we can still
2091 * use the suggested submount name.
2093 cm_NormalizeAfsPath (submountPathNormalized, submountPath);
2094 if (!strcmp (submountPathNormalized, afspath)) {
2095 strcpy(ioctlp->outDatap, submountreqp);
2096 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
2097 RegCloseKey( hkSubmounts );
2098 lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
2103 RegQueryInfoKey( hkSubmounts,
2105 NULL, /* lpcClass */
2106 NULL, /* lpReserved */
2107 NULL, /* lpcSubKeys */
2108 NULL, /* lpcMaxSubKeyLen */
2109 NULL, /* lpcMaxClassLen */
2110 &dwSubmounts, /* lpcValues */
2111 NULL, /* lpcMaxValueNameLen */
2112 NULL, /* lpcMaxValueLen */
2113 NULL, /* lpcbSecurityDescriptor */
2114 NULL /* lpftLastWriteTime */
2118 /* Having obtained a list of all available submounts, start
2119 * searching that list for a path which matches the requested
2120 * AFS path. We'll also keep track of the highest "auto15"/"auto47"
2121 * submount, in case we need to add a new one later.
2124 nextAutoSubmount = 1;
2126 for ( dwIndex = 0; dwIndex < dwSubmounts; dwIndex ++ ) {
2127 char submountPathNormalized[MAX_PATH];
2128 char submountPath[MAX_PATH] = "";
2129 DWORD submountPathLen = sizeof(submountPath);
2130 char submountName[MAX_PATH];
2131 DWORD submountNameLen = sizeof(submountName);
2134 RegEnumValue( hkSubmounts, dwIndex, submountName, &submountNameLen, NULL,
2135 &dwType, submountPath, &submountPathLen);
2136 if (dwType == REG_EXPAND_SZ) {
2138 StringCbCopyA(buf, MAX_PATH, submountPath);
2139 submountPathLen = ExpandEnvironmentStrings(buf, submountPath, MAX_PATH);
2140 if (submountPathLen > MAX_PATH)
2144 /* If this is an Auto### submount, remember its ### value */
2145 if ((!strnicmp (submountName, "auto", 4)) &&
2146 (isdigit (submountName[strlen("auto")]))) {
2147 int thisAutoSubmount;
2148 thisAutoSubmount = atoi (&submountName[strlen("auto")]);
2149 nextAutoSubmount = max (nextAutoSubmount,
2150 thisAutoSubmount+1);
2153 if ((submountPathLen == 0) ||
2154 (submountPathLen == sizeof(submountPath) - 1)) {
2158 /* See if the path for this submount matches the path
2159 * that our caller specified. If so, we can return
2162 cm_NormalizeAfsPath (submountPathNormalized, submountPath);
2163 if (!strcmp (submountPathNormalized, afspath)) {
2164 strcpy(ioctlp->outDatap, submountName);
2165 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
2166 RegCloseKey(hkSubmounts);
2167 lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
2173 /* We've been through the entire list of existing submounts, and
2174 * didn't find any which matched the specified path. So, we'll
2175 * just have to add one. Remember not to write the leading "/afs"
2176 * when writing out the submount.
2179 sprintf(ioctlp->outDatap, "auto%ld", nextAutoSubmount);
2181 RegSetValueEx( hkSubmounts,
2185 (strlen(&afspath[strlen(cm_mountRoot)])) ?
2186 &afspath[strlen(cm_mountRoot)]:"/",
2187 (strlen(&afspath[strlen(cm_mountRoot)])) ?
2188 strlen(&afspath[strlen(cm_mountRoot)])+1:2);
2190 ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
2191 RegCloseKey(hkSubmounts);
2192 lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
2196 long cm_IoctlGetRxkcrypt(smb_ioctl_t *ioctlp, cm_user_t *userp)
2198 memcpy(ioctlp->outDatap, &cryptall, sizeof(cryptall));
2199 ioctlp->outDatap += sizeof(cryptall);
2204 long cm_IoctlSetRxkcrypt(smb_ioctl_t *ioctlp, cm_user_t *userp)
2206 cm_SkipIoctlPath(ioctlp);
2208 memcpy(&cryptall, ioctlp->inDatap, sizeof(cryptall));
2214 extern int afsd_shutdown(int);
2215 extern int afs_shutdown;
2217 long cm_IoctlShutdown(smb_ioctl_t *ioctlp, cm_user_t *userp) {
2218 afs_shutdown = 1; /* flag to shut down */
2223 long cm_IoctlGetSMBName(smb_ioctl_t *ioctlp, cm_user_t *userp)
2225 smb_user_t *uidp = ioctlp->uidp;
2227 if (uidp && uidp->unp) {
2228 memcpy(ioctlp->outDatap, uidp->unp->name, strlen(uidp->unp->name));
2229 ioctlp->outDatap += strlen(uidp->unp->name);
2236 * functions to dump contents of various structures.
2237 * In debug build (linked with crt debug library) will dump allocated but not freed memory
2239 extern int cm_DumpSCache(FILE *outputFile, char *cookie);
2240 extern int cm_DumpBufHashTable(FILE *outputFile, char *cookie);
2241 extern int smb_DumpVCP(FILE *outputFile, char *cookie);
2243 long cm_IoctlMemoryDump(struct smb_ioctl *ioctlp, struct cm_user *userp)
2247 char logfileName[MAX_PATH+1];
2251 static _CrtMemState memstate;
2254 cm_SkipIoctlPath(ioctlp);
2255 memcpy(&inValue, ioctlp->inDatap, sizeof(long));
2259 strncpy(logfileName, getenv("TEMP"), MAX_PATH);
2260 logfileName[MAX_PATH] = '\0';
2264 GetWindowsDirectory(logfileName, sizeof(logfileName));
2266 strncat(logfileName, "\\afsd_alloc.log", sizeof(logfileName));
2268 hLogFile = CreateFile(logfileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
2274 memcpy(ioctlp->outDatap, &inValue, sizeof(long));
2275 ioctlp->outDatap += sizeof(long);
2280 SetFilePointer(hLogFile, 0, NULL, FILE_END);
2282 cookie = inValue ? "b" : "e";
2288 _CrtMemCheckpoint(&memstate);
2292 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
2293 _CrtSetReportFile(_CRT_WARN, hLogFile);
2294 _CrtMemDumpAllObjectsSince(&memstate);
2298 /* dump all interesting data */
2299 cm_DumpSCache(hLogFile, cookie);
2300 cm_DumpBufHashTable(hLogFile, cookie);
2301 smb_DumpVCP(hLogFile, cookie);
2303 CloseHandle(hLogFile);
2305 memcpy(ioctlp->outDatap, &inValue, sizeof(long));
2306 ioctlp->outDatap += sizeof(long);