+
+int GetMachineName(char *MachineName)
+{
+ char *args[2];
+ char NewMachineName[1024];
+ char *szDot;
+ int rc = 0;
+ int i;
+ DWORD dwLen = 0;
+ char *call_args[2];
+
+ // If the address happens to be in the top-level MIT domain, great!
+ strcpy(NewMachineName, MachineName);
+ for (i = 0; i < (int)strlen(NewMachineName); i++)
+ NewMachineName[i] = toupper(NewMachineName[i]);
+ szDot = strchr(NewMachineName,'.');
+ if ((szDot) && (!strcasecmp(szDot+1, DOMAIN_SUFFIX)))
+ {
+ return(0);
+ }
+
+ // If not, see if it has a Moira alias in the top-level MIT domain.
+ memset(NewMachineName, '\0', sizeof(NewMachineName));
+ args[0] = "*";
+ args[1] = MachineName;
+ call_args[0] = NewMachineName;
+ call_args[1] = NULL;
+ if (rc = mr_query("get_hostalias", 2, args, ProcessMachineName, call_args))
+ {
+ com_err(whoami, 0, "couldn't resolve machine name %s : %s",
+ MachineName, error_message(rc));
+ strcpy(MachineName, "");
+ return(0);
+ }
+
+ if (strlen(NewMachineName) != 0)
+ strcpy(MachineName, NewMachineName);
+ else
+ strcpy(MachineName, "");
+ return(0);
+
+}
+
+int ProcessMachineName(int ac, char **av, void *ptr)
+{
+ char **call_args;
+ char MachineName[1024];
+ char *szDot;
+ int i;
+
+ call_args = ptr;
+ if (strlen(call_args[0]) == 0)
+ {
+ strcpy(MachineName, av[0]);
+ for (i = 0; i < (int)strlen(MachineName); i++)
+ MachineName[i] = toupper(MachineName[i]);
+ szDot = strchr(MachineName,'.');
+ if ((szDot) && (!strcasecmp(szDot+1,DOMAIN_SUFFIX)))
+ {
+ strcpy(call_args[0], MachineName);
+ }
+ }
+ return(0);
+}
+
+void SwitchSFU(LDAPMod **mods, int *UseSFU30, int n)
+{
+ int i;
+
+ if (*UseSFU30)
+ {
+ for (i = 0; i < n; i++)
+ {
+ if (!strcmp(mods[i]->mod_type, "msSFU30UidNumber"))
+ mods[i]->mod_type = "uidNumber";
+ }
+ (*UseSFU30) = 0;
+ }
+ else
+ {
+ for (i = 0; i < n; i++)
+ {
+ if (!strcmp(mods[i]->mod_type, "uidNumber"))
+ mods[i]->mod_type = "msSFU30UidNumber";
+ }
+ (*UseSFU30) = 1;
+ }
+}
+
+int SetHomeDirectory(LDAP *ldap_handle, char *user_name, char *DistinguishedName,
+ char *WinHomeDir, char *WinProfileDir,
+ char **homedir_v, char **winProfile_v,
+ char **drives_v, LDAPMod **mods,
+ int OpType, int n)
+{
+ char **hp;
+ char cWeight[3];
+ char cPath[1024];
+ char path[1024];
+ char winPath[1024];
+ char winProfile[1024];
+ char homeDrive[8];
+ int last_weight;
+ int i;
+ int rc;
+ LDAPMod *DelMods[20];
+
+ memset(homeDrive, '\0', sizeof(homeDrive));
+ memset(path, '\0', sizeof(path));
+ memset(winPath, '\0', sizeof(winPath));
+ memset(winProfile, '\0', sizeof(winProfile));
+ hp = NULL;
+ if ((!strcasecmp(WinHomeDir, "[afs]")) || (!strcasecmp(WinProfileDir, "[afs]")))
+ {
+ if ((hp = hes_resolve(user_name, "filsys")) != NULL)
+ {
+ memset(cWeight, 0, sizeof(cWeight));
+ memset(cPath, 0, sizeof(cPath));
+ last_weight = 1000;
+ i = 0;
+ while (hp[i] != NULL)
+ {
+ if (sscanf(hp[i], "%*s %s", cPath))
+ {
+ if (strnicmp(cPath, AFS, strlen(AFS)) == 0)
+ {
+ if (sscanf(hp[i], "%*s %*s %*s %*s %s", cWeight))
+ {
+ if (atoi(cWeight) < last_weight)
+ {
+ strcpy(path, cPath);
+ last_weight = (int)atoi(cWeight);
+ }
+ }
+ else
+ strcpy(path, cPath);
+ }
+ }
+ ++i;
+ }
+ if (strlen(path))
+ {
+ if (!strnicmp(path, AFS, strlen(AFS)))
+ {
+ AfsToWinAfs(path, winPath);
+ strcpy(winProfile, winPath);
+ strcat(winProfile, "\\.winprofile");
+ }
+ }
+ }
+ }
+
+ if (hp != NULL)
+ {
+ i = 0;
+ while (hp[i])
+ {
+ free(hp[i]);
+ i++;
+ }
+ }
+
+ if (!strcasecmp(WinHomeDir, "[local]"))
+ memset(winPath, '\0', sizeof(winPath));
+ else if (!strcasecmp(WinHomeDir, "[afs]"))
+ {
+ strcpy(homeDrive, "H:");
+ }
+ else
+ {
+ strcpy(winPath, WinHomeDir);
+ if (!strncmp(WinHomeDir, "\\\\", 2))
+ {
+ strcpy(homeDrive, "H:");
+ }
+ }
+
+ // nothing needs to be done if WinProfileDir is [afs].
+ if (!strcasecmp(WinProfileDir, "[local]"))
+ memset(winProfile, '\0', sizeof(winProfile));
+ else if (strcasecmp(WinProfileDir, "[afs]"))
+ {
+ strcpy(winProfile, WinProfileDir);
+ }
+
+ if (strlen(winProfile) != 0)
+ {
+ if (winProfile[strlen(winProfile) - 1] == '\\')
+ winProfile[strlen(winProfile) - 1] = '\0';
+ }
+ if (strlen(winPath) != 0)
+ {
+ if (winPath[strlen(winPath) - 1] == '\\')
+ winPath[strlen(winPath) - 1] = '\0';
+ }
+
+ if ((winProfile[1] == ':') && (strlen(winProfile) == 2))
+ strcat(winProfile, "\\");
+ if ((winPath[1] == ':') && (strlen(winPath) == 2))
+ strcat(winPath, "\\");
+
+ if (strlen(winPath) == 0)
+ {
+ if (OpType == LDAP_MOD_REPLACE)
+ {
+ i = 0;
+ DEL_ATTR("homeDirectory", LDAP_MOD_DELETE);
+ DelMods[i] = NULL;
+ //unset homeDirectory attribute for user.
+ rc = ldap_modify_s(ldap_handle, DistinguishedName, DelMods);
+ free(DelMods[0]);
+ }
+ }
+ else
+ {
+ homedir_v[0] = strdup(winPath);
+ ADD_ATTR("homeDirectory", homedir_v, OpType);
+ }
+
+ if (strlen(winProfile) == 0)
+ {
+ if (OpType == LDAP_MOD_REPLACE)
+ {
+ i = 0;
+ DEL_ATTR("profilePath", LDAP_MOD_DELETE);
+ DelMods[i] = NULL;
+ //unset profilePate attribute for user.
+ rc = ldap_modify_s(ldap_handle, DistinguishedName, DelMods);
+ free(DelMods[0]);
+ }
+ }
+ else
+ {
+ winProfile_v[0] = strdup(winProfile);
+ ADD_ATTR("profilePath", winProfile_v, OpType);
+ }
+
+ if (strlen(homeDrive) == 0)
+ {
+ if (OpType == LDAP_MOD_REPLACE)
+ {
+ i = 0;
+ DEL_ATTR("homeDrive", LDAP_MOD_DELETE);
+ DelMods[i] = NULL;
+ //unset homeDrive attribute for user
+ rc = ldap_modify_s(ldap_handle, DistinguishedName, DelMods);
+ free(DelMods[0]);
+ }
+ }
+ else
+ {
+ drives_v[0] = strdup(homeDrive);
+ ADD_ATTR("homeDrive", drives_v, OpType);
+ }
+
+ return(n);
+}