{
char wdir[257];
int tlen;
- FILE *tfilep, *bestp, *tempp;
+ FILE *tfilep = NULL, *bestp, *tempp;
char *tp;
char lineBuffer[257];
struct hostent *thp;
char *valuep;
struct sockaddr_in vlSockAddr;
int inRightCell;
- int foundCell;
+ int foundCell = 0;
long code;
int tracking = 1, partial = 0;
#if defined(DJGPP) || defined(AFS_WIN95_ENV)
char *afsconf_path;
#endif
+#if !defined(DJGPP)
+ HKEY hkClient;
+ PBYTE pFilename;
+ DWORD dwType, dwSize;
+#endif
- foundCell = 0;
+#if !defined(DJGPP)
+ /* First attempt to find the CellServDB file via the registry */
+ if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
+ "SOFTWARE\\OpenAFS\\Client",
+ 0,
+ NULL,
+ REG_OPTION_NON_VOLATILE,
+ KEY_READ|KEY_WRITE,
+ NULL,
+ &hkClient,
+ NULL) == ERROR_SUCCESS) {
+ if (RegQueryValueEx( hkClient, "CellServDB", 0, &dwType, NULL, &dwSize) == ERROR_SUCCESS) {
+ pFilename = malloc(dwSize);
+ RegQueryValueEx( hkClient, "CellServDB", 0, &dwType, pFilename, &dwSize);
+ tfilep = fopen(pFilename, "r");
+ }
+ RegCloseKey(hkClient);
+ }
+#endif
+ /* If not found, fallback to old behavior */
+ if (!tfilep) {
#if !defined(DJGPP)
- code = GetWindowsDirectory(wdir, sizeof(wdir));
- if (code == 0 || code > sizeof(wdir))
- return -1;
+ code = GetWindowsDirectory(wdir, sizeof(wdir));
+ if (code == 0 || code > sizeof(wdir))
+ return -1;
- /* add trailing backslash, if required */
- tlen = strlen(wdir);
- if (wdir[tlen-1] != '\\') strcat(wdir, "\\");
+ /* add trailing backslash, if required */
+ tlen = strlen(wdir);
+ if (wdir[tlen-1] != '\\') strcat(wdir, "\\");
#else
- strcpy(wdir, cm_confDir);
- strcat(wdir,"/");
+ strcpy(wdir, cm_confDir);
+ strcat(wdir,"/");
#endif /* !DJGPP */
- strcat(wdir, AFS_CELLSERVDB);
-
- tfilep = fopen(wdir, "r");
+ strcat(wdir, AFS_CELLSERVDB);
+ tfilep = fopen(wdir, "r");
+ }
#if defined(DJGPP) || defined(AFS_WIN95_ENV)
if (!tfilep) {
#if !defined(DJGPP) && !defined(AFS_WIN95_ENV)
code = GetWindowsDirectory(wdir, sizeof(wdir));
- if (code == 0 || code > sizeof(wdir)) wdir[0] = 0;
+ if (code == 0 || code > sizeof(wdir)) wdir[0] = 0;
/* add trailing backslash, if required */
- tlen = strlen(wdir);
- if (wdir[tlen-1] != '\\') strcat(wdir, "\\");
+ tlen = strlen(wdir);
+ if (wdir[tlen-1] != '\\') strcat(wdir, "\\");
#else
#ifdef DJGPP
- strcpy(wdir,cm_confDir);
+ strcpy(wdir,cm_confDir);
#else
- afsconf_path = getenv("AFSCONF");
- if (!afsconf_path)
- strcpy(wdir, AFSDIR_CLIENT_ETC_DIRPATH);
- else
- strcpy(wdir, afsconf_path);
+ afsconf_path = getenv("AFSCONF");
+ if (!afsconf_path)
+ strcpy(wdir, AFSDIR_CLIENT_ETC_DIRPATH);
+ else
+ strcpy(wdir, afsconf_path);
#endif /* !DJGPP */
- strcat(wdir,"\\");
+ strcat(wdir,"\\");
#endif /* DJGPP || WIN95 */
- strcpy(dir, wdir);
+ strcpy(dir, wdir);
}
#ifndef DJGPP
#include <windows.h>
+#include <winreg.h>
#include <winsock2.h>
#else
#include <netdb.h>
void cm_InitFakeRootDir();
void cm_InitFreelance() {
-
-#ifdef COMMENT
- while ( !IsDebuggerPresent() ) {
- Sleep(1000);
- }
-#endif
-
lock_InitializeMutex(&cm_Freelance_Lock, "Freelance Lock");
// yj: first we make a call to cm_initLocalMountPoints
// process for the freelance client.
/* to be called while holding freelance lock unless during init. */
long cm_InitLocalMountPoints() {
-
FILE *fp;
char line[512];
int i;
char* t;
cm_localMountPoint_t* aLocalMountPoint;
char hdir[120];
+ long code;
+ char rootCellName[256];
+#if !defined(DJGPP)
+ HKEY hkFreelance = 0;
+ DWORD dwType, dwSize;
+ DWORD dwMountPoints;
+ DWORD dwIndex;
+#endif
+
+#if !defined(DJGPP)
+ if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
+ "SOFTWARE\\OpenAFS\\Client\\Freelance",
+ 0,
+ KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
+ &hkFreelance) == ERROR_SUCCESS) {
+
+ RegQueryInfoKey( hkFreelance,
+ NULL, /* lpClass */
+ NULL, /* lpcClass */
+ NULL, /* lpReserved */
+ NULL, /* lpcSubKeys */
+ NULL, /* lpcMaxSubKeyLen */
+ NULL, /* lpcMaxClassLen */
+ &dwMountPoints, /* lpcValues */
+ NULL, /* lpcMaxValueNameLen */
+ NULL, /* lpcMaxValueLen */
+ NULL, /* lpcbSecurityDescriptor */
+ NULL /* lpftLastWriteTime */
+ );
+
+ if ( dwMountPoints == 0 ) {
+ sprintf(line,"%s#%s:root.cell.\n",rootCellName,rootCellName);
+ dwType = REG_SZ;
+ dwSize = strlen(line) + 1;
+ RegSetValueEx( hkFreelance, "0", 0, dwType, line, dwSize);
+ sprintf(line,".%s%%%s:root.cell.\n",rootCellName,rootCellName);
+ dwSize = strlen(line) + 1;
+ RegSetValueEx( hkFreelance, "1", 0, dwType, line, dwSize);
+ dwMountPoints = 2;
+ }
+
+ // get the number of entries there are from the first line
+ // that we read
+ cm_noLocalMountPoints = dwMountPoints;
+
+ // create space to store the local mount points
+ cm_localMountPoints = malloc(sizeof(cm_localMountPoint_t) * cm_noLocalMountPoints);
+ aLocalMountPoint = cm_localMountPoints;
+
+ // now we read n lines and parse them into local mount points
+ // where n is the number of local mount points there are, as
+ // determined above.
+ // Each line in the ini file represents 1 local mount point and
+ // is in the format xxx#yyy:zzz, where xxx is the directory
+ // entry name, yyy is the cell name and zzz is the volume name.
+ // #yyy:zzz together make up the mount point.
+ for ( dwIndex = 0 ; dwIndex < dwMountPoints; dwIndex++ ) {
+ TCHAR szValueName[16];
+ DWORD dwValueSize = 16;
+ dwSize = sizeof(line);
+ RegEnumValue( hkFreelance, dwIndex, szValueName, &dwValueSize, NULL,
+ &dwType, line, &dwSize);
+
+ // line is not empty, so let's parse it
+ t = strchr(line, '#');
+ if (!t)
+ t = strchr(line, '%');
+ // make sure that there is a '#' or '%' separator in the line
+ if (!t) {
+ afsi_log("error occurred while parsing entry in %s: no # or %% separator in line %d", AFS_FREELANCE_INI, i);
+ fprintf(stderr, "error occurred while parsing entry in afs_freelance.ini: no # or %% separator in line %d", i);
+ return -1;
+ }
+ aLocalMountPoint->namep=malloc(t-line+1);
+ memcpy(aLocalMountPoint->namep, line, t-line);
+ *(aLocalMountPoint->namep + (t-line)) = 0;
+
+ aLocalMountPoint->mountPointStringp=malloc(strlen(line) - (t-line) + 1);
+ memcpy(aLocalMountPoint->mountPointStringp, t, strlen(line)-(t-line)-2);
+ *(aLocalMountPoint->mountPointStringp + (strlen(line)-(t-line)-2)) = 0;
+
+ osi_Log2(afsd_logp,"found mount point: name %s, string %s",
+ aLocalMountPoint->namep,
+ aLocalMountPoint->mountPointStringp);
+
+ aLocalMountPoint++;
+ }
+
+ RegCloseKey(hkFreelance);
+ return 0;
+ }
+#endif
cm_GetConfigDir(hdir);
strcat(hdir, AFS_FREELANCE_INI);
// if we fail to open the file, create an empty one
if (!fp) {
- long code;
- char rootCellName[256];
fp = fopen(hdir, "w");
code = cm_GetRootCellName(rootCellName);
if (code == 0) {
// we successfully opened the file
osi_Log0(afsd_logp,"opened afs_freelance.ini");
+
+#if !defined(DJGPP)
+ RegCreateKeyEx( HKEY_LOCAL_MACHINE,
+ "SOFTWARE\\OpenAFS\\Client\\Freelance",
+ 0,
+ NULL,
+ REG_OPTION_NON_VOLATILE,
+ KEY_READ|KEY_WRITE,
+ NULL,
+ &hkFreelance,
+ NULL);
+ dwIndex = 0;
+#endif
+
// now we read the first line to see how many entries
// there are
fgets(line, sizeof(line), fp);
fprintf(stderr, "error occurred while parsing entry in afs_freelance.ini: empty line in line %d", i);
return -1;
}
+
+#if !defined(DJGPP)
+ if ( hkFreelance ) {
+ char szIndex[16];
+ /* we are migrating to the registry */
+ sprintf(szIndex,"%d",dwIndex++);
+ dwType = REG_SZ;
+ dwSize = strlen(line) + 1;
+ RegSetValueEx( hkFreelance, szIndex, 0, dwType, line, dwSize);
+ }
+#endif
+
// line is not empty, so let's parse it
t = strchr(line, '#');
if (!t)
aLocalMountPoint++;
}
fclose(fp);
+#if !defined(DJGPP)
+ if ( hkFreelance ) {
+ RegCloseKey(hkFreelance);
+ DeleteFile(hdir);
+ }
+#endif
return 0;
}
char fullname[200];
int n;
int alias = 0;
+#if !defined(DJGPP)
+ HKEY hkFreelance = 0;
+ DWORD dwType, dwSize;
+ DWORD dwMountPoints;
+ DWORD dwIndex;
+#endif
/* before adding, verify the cell name; if it is not a valid cell,
don't add the mount point.
lock_ObtainMutex(&cm_Freelance_Lock);
- cm_GetConfigDir(hfile);
- strcat(hfile, AFS_FREELANCE_INI);
- fp = fopen(hfile, "r+");
- if (!fp)
- return CM_ERROR_INVAL;
- fgets(line, sizeof(line), fp);
- n = atoi(line);
- n++;
- fseek(fp, 0, SEEK_SET);
- fprintf(fp, "%d", n);
- fseek(fp, 0, SEEK_END);
- if (rw)
- fprintf(fp, "%s%%%s:%s\n", filename, fullname, volume);
- else
- fprintf(fp, "%s#%s:%s\n", filename, fullname, volume);
- fclose(fp);
+#if !defined(DJGPP)
+ if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
+ "SOFTWARE\\OpenAFS\\Client\\Freelance",
+ 0,
+ KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
+ &hkFreelance) == ERROR_SUCCESS) {
+
+ RegQueryInfoKey( hkFreelance,
+ NULL, /* lpClass */
+ NULL, /* lpcClass */
+ NULL, /* lpReserved */
+ NULL, /* lpcSubKeys */
+ NULL, /* lpcMaxSubKeyLen */
+ NULL, /* lpcMaxClassLen */
+ &dwMountPoints, /* lpcValues */
+ NULL, /* lpcMaxValueNameLen */
+ NULL, /* lpcMaxValueLen */
+ NULL, /* lpcbSecurityDescriptor */
+ NULL /* lpftLastWriteTime */
+ );
+
+ if (rw)
+ sprintf(line, "%s%%%s:%s\n", filename, fullname, volume);
+ else
+ sprintf(line, "%s#%s:%s\n", filename, fullname, volume);
+
+ /* If we are adding a new value, there must be an unused name
+ * within the range 0 to dwMountPoints
+ */
+ for ( dwIndex = 0; dwIndex <= dwMountPoints; dwIndex++ ) {
+ char szIndex[16];
+ sprintf(szIndex, "%d", dwIndex);
+ if (RegQueryValueEx( hkFreelance, szIndex, 0, &dwType, NULL, &dwSize) != ERROR_SUCCESS) {
+ /* found an unused value */
+ dwType = REG_SZ;
+ dwSize = strlen(line) + 1;
+ RegSetValueEx( hkFreelance, szIndex, 0, dwType, line, dwSize);
+ break;
+ }
+ }
+ RegCloseKey(hkFreelance);
+ } else
+#endif
+ {
+ cm_GetConfigDir(hfile);
+ strcat(hfile, AFS_FREELANCE_INI);
+ fp = fopen(hfile, "r+");
+ if (!fp)
+ return CM_ERROR_INVAL;
+ fgets(line, sizeof(line), fp);
+ n = atoi(line);
+ n++;
+ fseek(fp, 0, SEEK_SET);
+ fprintf(fp, "%d", n);
+ fseek(fp, 0, SEEK_END);
+ if (rw)
+ fprintf(fp, "%s%%%s:%s\n", filename, fullname, volume);
+ else
+ fprintf(fp, "%s#%s:%s\n", filename, fullname, volume);
+ fclose(fp);
+ }
lock_ReleaseMutex(&cm_Freelance_Lock);
/* cm_reInitLocalMountPoints(); */
long cm_FreelanceRemoveMount(char *toremove)
{
- int i, n;
- char* cp;
- char line[512];
- char shortname[200];
- char hfile[120], hfile2[120];
- FILE *fp1, *fp2;
- int found=0;
+ int i, n;
+ char* cp;
+ char line[512];
+ char shortname[200];
+ char hfile[120], hfile2[120];
+ FILE *fp1, *fp2;
+ int found=0;
+#if !defined(DJGPP)
+ HKEY hkFreelance = 0;
+ DWORD dwType, dwSize;
+ DWORD dwMountPoints;
+ DWORD dwIndex;
+#endif
lock_ObtainMutex(&cm_Freelance_Lock);
- cm_GetConfigDir(hfile);
- strcat(hfile, AFS_FREELANCE_INI);
- strcpy(hfile2, hfile);
- strcat(hfile2, "2");
- fp1=fopen(hfile, "r+");
- if (!fp1)
- return CM_ERROR_INVAL;
- fp2=fopen(hfile2, "w+");
- if (!fp2) {
- fclose(fp1);
- return CM_ERROR_INVAL;
- }
-
- fgets(line, sizeof(line), fp1);
- n=atoi(line);
- fprintf(fp2, "%d\n", n-1);
-
- for (i=0; i<n; i++) {
- fgets(line, sizeof(line), fp1);
- cp=strchr(line, '#');
- if (!cp)
- cp=strchr(line, '%');
- memcpy(shortname, line, cp-line);
- shortname[cp-line]=0;
-
- if (strcmp(shortname, toremove)==0) {
-
- } else {
- found = 1;
- fputs(line, fp2);
- }
- }
-
- fclose(fp1);
- fclose(fp2);
- if (!found)
- return CM_ERROR_NOSUCHFILE;
-
- unlink(hfile);
- rename(hfile2, hfile);
- lock_ReleaseMutex(&cm_Freelance_Lock);
+#if !defined(DJGPP)
+ if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
+ "SOFTWARE\\OpenAFS\\Client\\Freelance",
+ 0,
+ KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
+ &hkFreelance) == ERROR_SUCCESS) {
+
+ RegQueryInfoKey( hkFreelance,
+ NULL, /* lpClass */
+ NULL, /* lpcClass */
+ NULL, /* lpReserved */
+ NULL, /* lpcSubKeys */
+ NULL, /* lpcMaxSubKeyLen */
+ NULL, /* lpcMaxClassLen */
+ &dwMountPoints, /* lpcValues */
+ NULL, /* lpcMaxValueNameLen */
+ NULL, /* lpcMaxValueLen */
+ NULL, /* lpcbSecurityDescriptor */
+ NULL /* lpftLastWriteTime */
+ );
+
+ for ( dwIndex = 0; dwIndex < dwMountPoints; dwIndex++ ) {
+ TCHAR szValueName[16];
+ DWORD dwValueSize = 16;
+ dwSize = sizeof(line);
+ RegEnumValue( hkFreelance, dwIndex, szValueName, &dwValueSize, NULL,
+ &dwType, line, &dwSize);
+
+ cp=strchr(line, '#');
+ if (!cp)
+ cp=strchr(line, '%');
+ memcpy(shortname, line, cp-line);
+ shortname[cp-line]=0;
+
+ if (!strcmp(shortname, toremove)) {
+ RegDeleteValue( hkFreelance, szValueName );
+ break;
+ }
+ }
+ RegCloseKey(hkFreelance);
+ } else
+#endif
+ {
+ cm_GetConfigDir(hfile);
+ strcat(hfile, AFS_FREELANCE_INI);
+ strcpy(hfile2, hfile);
+ strcat(hfile2, "2");
+ fp1=fopen(hfile, "r+");
+ if (!fp1)
+ return CM_ERROR_INVAL;
+ fp2=fopen(hfile2, "w+");
+ if (!fp2) {
+ fclose(fp1);
+ return CM_ERROR_INVAL;
+ }
+
+ fgets(line, sizeof(line), fp1);
+ n=atoi(line);
+ fprintf(fp2, "%d\n", n-1);
+
+ for (i=0; i<n; i++) {
+ fgets(line, sizeof(line), fp1);
+ cp=strchr(line, '#');
+ if (!cp)
+ cp=strchr(line, '%');
+ memcpy(shortname, line, cp-line);
+ shortname[cp-line]=0;
+
+ if (strcmp(shortname, toremove)==0) {
+
+ } else {
+ found = 1;
+ fputs(line, fp2);
+ }
+ }
+
+ fclose(fp1);
+ fclose(fp2);
+ if (!found)
+ return CM_ERROR_NOSUCHFILE;
+ unlink(hfile);
+ rename(hfile2, hfile);
+ }
+
+ lock_ReleaseMutex(&cm_Freelance_Lock);
cm_noteLocalMountPointChange();
return 0;
}