static krb5_error_code get_from_os_buffer(char *name_buf, unsigned int name_size) { char *prefix = krb5_cc_dfl_ops->prefix; unsigned int size; char *p; DWORD gle; SetLastError(0); GetEnvironmentVariable(KRB5_ENV_CCNAME, name_buf, name_size); gle = GetLastError(); if (gle == 0) return 0; else if (gle != ERROR_ENVVAR_NOT_FOUND) return ENOMEM; if (get_from_registry(HKEY_CURRENT_USER, name_buf, name_size) != 0) return 0; if (get_from_registry(HKEY_LOCAL_MACHINE, name_buf, name_size) != 0) return 0; if (get_from_registry_indirect(name_buf, name_size) != 0) return 0; strncpy(name_buf, prefix, name_size - 1); name_buf[name_size - 1] = 0; size = name_size - strlen(prefix); if (size > 0) strcat(name_buf, ":"); size--; p = name_buf + name_size - size; if (!strcmp(prefix, "API")) { strncpy(p, "krb5cc", size); } else if (!strcmp(prefix, "FILE") || !strcmp(prefix, "STDIO")) { if (!try_dir(getenv("TEMP"), p, size) && !try_dir(getenv("TMP"), p, size)) { unsigned int len = GetWindowsDirectory(p, size); name_buf[name_size - 1] = 0; if (len < size - sizeof(APPEND_KRB5CC)) strcat(p, APPEND_KRB5CC); } } else { strncpy(p, "default_cache_name", size); } name_buf[name_size - 1] = 0; return 0; }
const void *subsurface_get_conf(char *name, pref_type_t type) { LONG success; char *string; int len; switch (type) { case PREF_BOOL: return get_from_registry(hkey, name) ? (void *) 1 : NULL; case PREF_STRING: string = malloc(80); len = 80; success = RegQueryValueEx(hkey, (LPCTSTR)TEXT(name), NULL, NULL, (LPBYTE) string, (LPDWORD)&len ); if (success != ERROR_SUCCESS) { /* that's what happens the first time we start - just return NULL */ free(string); return NULL; } return string; } /* we shouldn't get here */ return NULL; }
/* This function is needed by KfM's KerberosPreferences API * because it needs to be able to specify "secure" */ krb5_error_code os_get_default_config_files(profile_filespec_t **pfiles, krb5_boolean secure) { profile_filespec_t* files; #if defined(_WIN32) krb5_error_code retval = 0; char *name = 0; if (!secure) { char *env = getenv("KRB5_CONFIG"); if (env) { name = strdup(env); if (!name) return ENOMEM; } } if (!name && !secure) { /* HKCU */ retval = get_from_registry(&name, HKEY_CURRENT_USER); if (retval) return retval; } if (!name) { /* HKLM */ retval = get_from_registry(&name, HKEY_LOCAL_MACHINE); if (retval) return retval; } if (!name && !secure) { /* module dir */ retval = get_from_module_dir(&name); if (retval) return retval; } if (!name) { /* windows dir */ retval = get_from_windows_dir(&name); } if (retval) return retval; if (!name) return KRB5_CONFIG_CANTOPEN; /* should never happen */ files = malloc(2 * sizeof(char *)); if (!files) return ENOMEM; files[0] = name; files[1] = 0; #else /* !_WIN32 */ char* filepath = 0; int n_entries, i; unsigned int ent_len; const char *s, *t; #ifdef USE_KIM /* If kim_library_allow_home_directory_access() == FALSE, we are probably * trying to authenticate to a fileserver for the user's homedir. */ if (!kim_library_allow_home_directory_access ()) secure = 1; #endif if (secure) { filepath = DEFAULT_SECURE_PROFILE_PATH; } else { filepath = getenv("KRB5_CONFIG"); if (!filepath) filepath = DEFAULT_PROFILE_PATH; } /* count the distinct filename components */ for(s = filepath, n_entries = 1; *s; s++) { if (*s == ':') n_entries++; } /* the array is NULL terminated */ files = (char**) malloc((n_entries+1) * sizeof(char*)); if (files == 0) return ENOMEM; /* measure, copy, and skip each one */ for(s = filepath, i=0; (t = strchr(s, ':')) || (t=s+strlen(s)); s=t+1, i++) { ent_len = t-s; files[i] = (char*) malloc(ent_len + 1); if (files[i] == 0) { /* if malloc fails, free the ones that worked */ while(--i >= 0) free(files[i]); free(files); return ENOMEM; } strncpy(files[i], s, ent_len); files[i][ent_len] = 0; if (*t == 0) { i++; break; } } /* cap the array */ files[i] = 0; #endif /* !_WIN32 */ *pfiles = (profile_filespec_t *)files; return 0; }
int subsurface_get_conf_bool(char *name) { return get_from_registry(hkey, name); }