#include "afsd_init.h"
#include "smb.h"
+#include "cm_server.h"
#ifndef DJGPP
#include <rx/rxkad.h>
osi_mutex_t cm_Afsdsbmt_Lock;
extern afs_int32 cryptall;
+extern char cm_NetbiosName[];
void cm_InitIoctl(void)
{
{
long code;
cm_scache_t *substRootp;
+ char * relativePath = ioctlp->inDatap;
+
+ /* This is usually the file name, but for StatMountPoint it is the path. */
+ /* ioctlp->inDatap can be either of the form:
+ * \path\.
+ * \path\file
+ * \\netbios-name\submount\path\.
+ * \\netbios-name\submount\path\file
+ */
+ TranslateExtendedChars(relativePath);
- /* This is usually the file name, but for StatMountPoint it is the path. */
- TranslateExtendedChars(ioctlp->inDatap);
+ if (relativePath[0] == relativePath[1] &&
+ relativePath[1] == '\\' &&
+ !_strnicmp(cm_NetbiosName,relativePath+2,strlen(cm_NetbiosName)))
+ {
+ char shareName[256];
+ char *sharePath;
+ int shareFound, i;
+
+ /* We may have found a UNC path.
+ * If the first component is the NetbiosName,
+ * then throw out the second component (the submount)
+ * since it had better expand into the value of ioctl->tidPathp
+ */
+ char * p;
+ p = relativePath + 2 + strlen(cm_NetbiosName) + 1;
+ if ( !_strnicmp("all", p, 3) )
+ p += 4;
- code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
- CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
- userp, ioctlp->tidPathp, reqp, &substRootp);
- if (code) return code;
-
- code = cm_NameI(substRootp, ioctlp->inDatap, CM_FLAG_FOLLOW,
- userp, NULL, reqp, scpp);
- if (code) return code;
+ for (i = 0; *p && *p != '\\'; i++,p++ ) {
+ shareName[i] = *p;
+ }
+ p++; /* skip past trailing slash */
+ shareName[i] = 0; /* terminate string */
+
+ shareFound = smb_FindShare(ioctlp->fidp->vcp, ioctlp->uidp, shareName, &sharePath);
+ if ( shareFound ) {
+ /* we found a sharename, therefore use the resulting path */
+ code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
+ CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
+ userp, sharePath, reqp, &substRootp);
+ free(sharePath);
+ if (code) return code;
+
+ code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
+ userp, NULL, reqp, scpp);
+ if (code) return code;
+ } else {
+ /* otherwise, treat the name as a cellname mounted off the afs root.
+ * This requires that we reconstruct the shareName string with
+ * leading and trailing slashes.
+ */
+ p = relativePath + 2 + strlen(cm_NetbiosName) + 1;
+ if ( !_strnicmp("all", p, 3) )
+ p += 4;
+
+ shareName[0] = '/';
+ for (i = 1; *p && *p != '\\'; i++,p++ ) {
+ shareName[i] = *p;
+ }
+ p++; /* skip past trailing slash */
+ shareName[i++] = '/'; /* add trailing slash */
+ shareName[i] = 0; /* terminate string */
+
+
+ code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
+ CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
+ userp, shareName, reqp, &substRootp);
+ if (code) return code;
+
+ code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
+ userp, NULL, reqp, scpp);
+ if (code) return code;
+ }
+ } else {
+ code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
+ CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
+ userp, ioctlp->tidPathp, reqp, &substRootp);
+ if (code) return code;
+ code = cm_NameI(substRootp, relativePath, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
+ userp, NULL, reqp, scpp);
+ if (code) return code;
+ }
+
/* # of bytes of path */
- code = strlen(ioctlp->inDatap) + 1;
- ioctlp->inDatap += code;
+ code = strlen(ioctlp->inDatap) + 1;
+ ioctlp->inDatap += code;
- /* This is usually nothing, but for StatMountPoint it is the file name. */
- TranslateExtendedChars(ioctlp->inDatap);
+ /* This is usually nothing, but for StatMountPoint it is the file name. */
+ TranslateExtendedChars(ioctlp->inDatap);
/* and return success */
- return 0;
+ return 0;
}
void cm_SkipIoctlPath(smb_ioctl_t *ioctlp)
cm_scache_t **scpp, char *leafp)
{
long code;
- char tbuffer[1024];
- char *tp, *jp;
+ char tbuffer[1024];
+ char *tp, *jp;
cm_scache_t *substRootp;
strcpy(tbuffer, ioctlp->inDatap);
- tp = strrchr(tbuffer, '\\');
+ tp = strrchr(tbuffer, '\\');
jp = strrchr(tbuffer, '/');
if (!tp)
tp = jp;
else if (jp && (tp - tbuffer) < (jp - tbuffer))
tp = jp;
- if (!tp) {
- strcpy(tbuffer, "\\");
- if (leafp) strcpy(leafp, ioctlp->inDatap);
- }
- else {
- *tp = 0;
- if (leafp) strcpy(leafp, tp+1);
+ if (!tp) {
+ strcpy(tbuffer, "\\");
+ if (leafp)
+ strcpy(leafp, ioctlp->inDatap);
}
+ else {
+ *tp = 0;
+ if (leafp)
+ strcpy(leafp, tp+1);
+ }
+
+ if (tbuffer[0] == tbuffer[1] &&
+ tbuffer[1] == '\\' &&
+ !_strnicmp(cm_NetbiosName,tbuffer+2,strlen(cm_NetbiosName)))
+ {
+ char shareName[256];
+ char *sharePath;
+ int shareFound, i;
+
+ /* We may have found a UNC path.
+ * If the first component is the NetbiosName,
+ * then throw out the second component (the submount)
+ * since it had better expand into the value of ioctl->tidPathp
+ */
+ char * p;
+ p = tbuffer + 2 + strlen(cm_NetbiosName) + 1;
+ if ( !_strnicmp("all", p, 3) )
+ p += 4;
- code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
- CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
- userp, ioctlp->tidPathp, reqp, &substRootp);
- if (code) return code;
+ for (i = 0; *p && *p != '\\'; i++,p++ ) {
+ shareName[i] = *p;
+ }
+ p++; /* skip past trailing slash */
+ shareName[i] = 0; /* terminate string */
+
+ shareFound = smb_FindShare(ioctlp->fidp->vcp, ioctlp->uidp, shareName, &sharePath);
+ if ( shareFound ) {
+ /* we found a sharename, therefore use the resulting path */
+ code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
+ CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
+ userp, sharePath, reqp, &substRootp);
+ free(sharePath);
+ if (code) return code;
+
+ code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
+ userp, NULL, reqp, scpp);
+ if (code) return code;
+ } else {
+ /* otherwise, treat the name as a cellname mounted off the afs root.
+ * This requires that we reconstruct the shareName string with
+ * leading and trailing slashes.
+ */
+ p = tbuffer + 2 + strlen(cm_NetbiosName) + 1;
+ if ( !_strnicmp("all", p, 3) )
+ p += 4;
+
+ shareName[0] = '/';
+ for (i = 1; *p && *p != '\\'; i++,p++ ) {
+ shareName[i] = *p;
+ }
+ p++; /* skip past trailing slash */
+ shareName[i++] = '/'; /* add trailing slash */
+ shareName[i] = 0; /* terminate string */
+
+ code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
+ CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
+ userp, shareName, reqp, &substRootp);
+ if (code) return code;
+
+ code = cm_NameI(substRootp, p, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
+ userp, NULL, reqp, scpp);
+ if (code) return code;
+ }
+ } else {
+ code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data,
+ CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
+ userp, ioctlp->tidPathp, reqp, &substRootp);
+ if (code) return code;
code = cm_NameI(substRootp, tbuffer, CM_FLAG_FOLLOW,
- userp, NULL, reqp, scpp);
- if (code) return code;
-
+ userp, NULL, reqp, scpp);
+ if (code) return code;
+ }
+
/* # of bytes of path */
code = strlen(ioctlp->inDatap) + 1;
ioctlp->inDatap += code;
* cell list will be cm_CellLock and cm_ServerLock will be held for write.
*/
- cm_cell_t *tcellp;
+ cm_cell_t *cp;
cm_SkipIoctlPath(ioctlp);
lock_ObtainWrite(&cm_cellLock);
- for(tcellp = cm_allCellsp; tcellp; tcellp=tcellp->nextp)
+ for(cp = cm_allCellsp; cp; cp=cp->nextp)
{
+ long code;
/* delete all previous server lists - cm_FreeServerList will ask for write on cm_ServerLock*/
- cm_FreeServerList(&tcellp->vlServersp);
- tcellp->vlServersp = NULL;
- cm_SearchCellFile(tcellp->namep, tcellp->namep, cm_AddCellProc, tcellp);
- cm_RandomizeServer(&tcellp->vlServersp);
+ cm_FreeServerList(&cp->vlServersp);
+ cp->vlServersp = NULL;
+ code = cm_SearchCellFile(cp->namep, cp->namep, cm_AddCellProc, cp);
+#ifdef AFS_AFSDB_ENV
+ if (code) {
+ if (cm_dnsEnabled) {
+ int ttl;
+ code = cm_SearchCellByDNS(cp->namep, cp->namep, &ttl, cm_AddCellProc, cp);
+ if ( code == 0 ) { /* got cell from DNS */
+ cp->flags |= CM_CELLFLAG_DNS;
+ cp->flags &= ~CM_CELLFLAG_VLSERVER_INVALID;
+ cp->timeout = time(0) + ttl;
+ }
+ }
+ }
+ else {
+ cp->flags &= ~CM_CELLFLAG_DNS;
+ }
+#endif /* AFS_AFSDB_ENV */
+ if (code) {
+ cp->flags |= CM_CELLFLAG_VLSERVER_INVALID;
+ }
+ else {
+ cp->flags &= ~CM_CELLFLAG_VLSERVER_INVALID;
+ cm_RandomizeServer(&cp->vlServersp);
+ }
}
lock_ReleaseWrite(&cm_cellLock);
long cm_IoctlSysName(struct smb_ioctl *ioctlp, struct cm_user *userp)
{
- long setSysName;
- char *cp;
+ long setSysName, foundname = 0;
+ char *cp, *cp2, inname[MAXSYSNAME], outname[MAXSYSNAME];
+ int t, count, num = 0;
+ char **sysnamelist[MAXSYSNAME];
cm_SkipIoctlPath(ioctlp);
- memcpy(&setSysName, ioctlp->inDatap, sizeof(long));
- ioctlp->inDatap += sizeof(long);
+ memcpy(&setSysName, ioctlp->inDatap, sizeof(long));
+ ioctlp->inDatap += sizeof(long);
- if (setSysName) {
- strcpy(cm_sysName, ioctlp->inDatap);
+ if (setSysName) {
+ /* check my args */
+ if ( setSysName < 0 || setSysName > MAXNUMSYSNAMES )
+ return EINVAL;
+ cp2 = ioctlp->inDatap;
+ for ( cp=ioctlp->inDatap, count = 0; count < setSysName; count++ ) {
+ /* won't go past end of ioctlp->inDatap since maxsysname*num < ioctlp->inDatap length */
+ t = strlen(cp);
+ if (t >= MAXSYSNAME || t <= 0)
+ return EINVAL;
+ /* check for names that can shoot us in the foot */
+ if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
+ return EINVAL;
+ cp += t + 1;
}
- else {
+ /* args ok */
+
+ /* inname gets first entry in case we're being a translator */
+ /* (we are never a translator) */
+ t = strlen(ioctlp->inDatap);
+ memcpy(inname, ioctlp->inDatap, t + 1);
+ ioctlp->inDatap += t + 1;
+ num = count;
+ }
+
+ /* Not xlating, so local case */
+ if (!cm_sysName)
+ osi_panic("cm_IoctlSysName: !cm_sysName\n", __FILE__, __LINE__);
+
+ if (!setSysName) { /* user just wants the info */
+ strcpy(outname, cm_sysName);
+ foundname = cm_sysNameCount;
+ *sysnamelist = cm_sysNameList;
+ } else { /* Local guy; only root can change sysname */
+ /* clear @sys entries from the dnlc, once afs_lookup can
+ * do lookups of @sys entries and thinks it can trust them */
+ /* privs ok, store the entry, ... */
+ strcpy(cm_sysName, inname);
+ if (setSysName > 1) { /* ... or list */
+ cp = ioctlp->inDatap;
+ for (count = 1; count < setSysName; ++count) {
+ if (!cm_sysNameList[count])
+ osi_panic
+ ("cm_IoctlSysName: no cm_sysNameList entry to write\n"
+ , __FILE__, __LINE__);
+ t = strlen(cp);
+ memcpy(cm_sysNameList[count], cp, t + 1); /* include null */
+ cp += t + 1;
+ }
+ }
+ cm_sysNameCount = setSysName;
+ }
+
+ if (!setSysName) {
/* return the sysname to the caller */
- setSysName = 1; /* really means "found sys name */
cp = ioctlp->outDatap;
- memcpy(cp, &setSysName, sizeof(long));
- cp += sizeof(long); /* skip found flag */
- strcpy(cp, cm_sysName);
- cp += strlen(cp) + 1; /* skip name and terminating null char */
- ioctlp->outDatap = cp;
+ memcpy(cp, (char *)&foundname, sizeof(afs_int32));
+ cp += sizeof(afs_int32); /* skip found flag */
+ if (foundname) {
+ strcpy(cp, outname);
+ cp += strlen(outname) + 1; /* skip name and terminating null char */
+ for ( count=1; count < foundname ; ++count) { /* ... or list */
+ if ( !(*sysnamelist)[count] )
+ osi_panic("cm_IoctlSysName: no cm_sysNameList entry to read\n"
+ , __FILE__, __LINE__);
+ t = strlen((*sysnamelist)[count]);
+ if (t >= MAXSYSNAME)
+ osi_panic("cm_IoctlSysName: sysname entry garbled\n"
+ , __FILE__, __LINE__);
+ strcpy(cp, (*sysnamelist)[count]);
+ cp += t + 1;
+ }
}
+ ioctlp->outDatap = cp;
+ }
/* done: success */
- return 0;
+ return 0;
}
long cm_IoctlGetCellStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
if (cm_freelanceEnabled && dscp == cm_rootSCachep) {
/* we are adding the mount point to the root dir., so call
the freelance code to do the add. */
- code = cm_FreelanceAddMount(leaf, fullCell, volume, NULL);
+ osi_Log0(afsd_logp,"IoctlCreateMountPoint within Freelance root dir");
+ code = cm_FreelanceAddMount(leaf, fullCell, volume,
+ *ioctlp->inDatap == '%', NULL);
return code;
}
#endif
char afspath[MAX_PATH];
char *submountreqp;
int iteration;
- int submountDataSize;
- char *submountData;
- char *submountName;
int nextAutoSubmount;
+ HKEY hkSubmounts;
+ DWORD dwType, dwSize;
+ DWORD status;
+ DWORD dwIndex;
+ DWORD dwSubmounts;
cm_SkipIoctlPath(ioctlp);
* that submount name is in use... if so, the submount's path
* has to match our path.
*/
- if (submountreqp && *submountreqp) {
+
+ RegCreateKeyEx( HKEY_LOCAL_MACHINE,
+ "SOFTWARE\\OpenAFS\\Client\\Submounts",
+ 0,
+ "AFS",
+ REG_OPTION_NON_VOLATILE,
+ KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
+ NULL,
+ &hkSubmounts,
+ NULL );
+
+ if (submountreqp && *submountreqp) {
char submountPathNormalized[MAX_PATH];
char submountPath[MAX_PATH];
int submountPathLen;
- submountPathLen = GetPrivateProfileString("AFS Submounts",
- submountreqp, "", submountPath,
- sizeof(submountPath), "afsdsbmt.ini");
+ dwSize = sizeof(submountPath);
+ status = RegQueryValueEx( hkSubmounts, submountreqp, 0,
+ &dwType, submountPath, &dwSize);
- if ((submountPathLen == 0) ||
- (submountPathLen == sizeof(submountPath) - 1)) {
+ if (status != ERROR_SUCCESS) {
/* The suggested submount name isn't in use now--
* so we can safely map the requested submount name
* to the supplied path. Remember not to write the
* leading "/afs" when writing out the submount.
*/
- WritePrivateProfileString("AFS Submounts",
- submountreqp,
- (strlen(&afspath[strlen(cm_mountRoot)])) ?
- &afspath[strlen(cm_mountRoot)]:"/",
- "afsdsbmt.ini");
-
+ RegSetValueEx( hkSubmounts, submountreqp, 0,
+ REG_SZ,
+ (strlen(&afspath[strlen(cm_mountRoot)])) ?
+ &afspath[strlen(cm_mountRoot)]:"/",
+ (strlen(&afspath[strlen(cm_mountRoot)])) ?
+ strlen(&afspath[strlen(cm_mountRoot)])+1:2);
+
+ RegCloseKey( hkSubmounts );
strcpy(ioctlp->outDatap, submountreqp);
ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
- return 0;
+ return 0;
}
/* The suggested submount name is already in use--if the
if (!strcmp (submountPathNormalized, afspath)) {
strcpy(ioctlp->outDatap, submountreqp);
ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
+ RegCloseKey( hkSubmounts );
lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
- return 0;
+ return 0;
}
}
- /* At this point, the user either didn't request a particular
- * submount name, or that submount name couldn't be used.
- * Look through afsdsbmt.ini to see if there are any submounts
- * already associated with the specified path. The first
- * step in doing that search is to load the AFS Submounts
- * section of afsdsbmt.ini into memory.
- */
-
- submountDataSize = 1024;
- submountData = malloc (submountDataSize);
-
- for (iteration = 0; iteration < 5; ++iteration) {
-
- int sectionSize;
- sectionSize = GetPrivateProfileString("AFS Submounts",
- NULL, "", submountData,
- submountDataSize, "afsdsbmt.ini");
- if (sectionSize < submountDataSize-2)
- break;
+ RegQueryInfoKey( hkSubmounts,
+ NULL, /* lpClass */
+ NULL, /* lpcClass */
+ NULL, /* lpReserved */
+ NULL, /* lpcSubKeys */
+ NULL, /* lpcMaxSubKeyLen */
+ NULL, /* lpcMaxClassLen */
+ &dwSubmounts, /* lpcValues */
+ NULL, /* lpcMaxValueNameLen */
+ NULL, /* lpcMaxValueLen */
+ NULL, /* lpcbSecurityDescriptor */
+ NULL /* lpftLastWriteTime */
+ );
- free (submountData);
- submountDataSize *= 2;
- submountData = malloc (submountDataSize);
- }
/* Having obtained a list of all available submounts, start
* searching that list for a path which matches the requested
nextAutoSubmount = 1;
- for (submountName = submountData;
- submountName && *submountName;
- submountName += 1+strlen(submountName)) {
-
+ for ( dwIndex = 0; dwIndex < dwSubmounts; dwIndex ++ ) {
char submountPathNormalized[MAX_PATH];
char submountPath[MAX_PATH] = "";
- int submountPathLen;
+ DWORD submountPathLen = sizeof(submountPath);
+ char submountName[256];
+ DWORD submountNameLen = sizeof(submountName);
+
+ RegEnumValue( hkSubmounts, dwIndex, submountName, &submountNameLen, NULL,
+ &dwType, submountPath, &submountPathLen);
/* If this is an Auto### submount, remember its ### value */
thisAutoSubmount+1);
}
- /* We have the name of a submount in the AFS Submounts
- * section; read that entry to find out what path it
- * maps to.
- */
- submountPathLen = GetPrivateProfileString("AFS Submounts",
- submountName, "", submountPath,
- sizeof(submountPath), "afsdsbmt.ini");
-
if ((submountPathLen == 0) ||
(submountPathLen == sizeof(submountPath) - 1)) {
continue;
*/
cm_NormalizeAfsPath (submountPathNormalized, submountPath);
if (!strcmp (submountPathNormalized, afspath)) {
-
strcpy(ioctlp->outDatap, submountName);
ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
- free (submountData);
+ RegCloseKey(hkSubmounts);
lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
- return 0;
+ return 0;
}
}
- free (submountData);
-
/* We've been through the entire list of existing submounts, and
* didn't find any which matched the specified path. So, we'll
* just have to add one. Remember not to write the leading "/afs"
sprintf(ioctlp->outDatap, "auto%ld", nextAutoSubmount);
- WritePrivateProfileString("AFS Submounts", ioctlp->outDatap,
- (strlen(&afspath[lstrlen(cm_mountRoot)])) ?
- &afspath[lstrlen(cm_mountRoot)]:"/",
- "afsdsbmt.ini");
+ RegSetValueEx( hkSubmounts,
+ ioctlp->outDatap,
+ 0,
+ REG_SZ,
+ (strlen(&afspath[strlen(cm_mountRoot)])) ?
+ &afspath[strlen(cm_mountRoot)]:"/",
+ (strlen(&afspath[strlen(cm_mountRoot)])) ?
+ strlen(&afspath[strlen(cm_mountRoot)])+1:2);
ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
+ RegCloseKey(hkSubmounts);
lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
return 0;
}
cm_SkipIoctlPath(ioctlp);
memcpy(&inValue, ioctlp->inDatap, sizeof(long));
- GetWindowsDirectory(logfileName, sizeof(logfileName));
+ if (getenv("TEMP"))
+ {
+ strncpy(logfileName, getenv("TEMP"), MAX_PATH);
+ logfileName[MAX_PATH] = '\0';
+ }
+ else
+ {
+ GetWindowsDirectory(logfileName, sizeof(logfileName));
+ }
strncat(logfileName, "\\afsd_alloc.log", sizeof(logfileName));
hLogFile = CreateFile(logfileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);