static boolean login_config_create(void) { char *home, *p; char tmp[80]; FILE *fp; home = get_user_home(); if (!home) return FALSE; debug_where(); snprintf(tmp, 80, "%s/."USER_CONFIG_DIR_NAME,home); if (access(tmp, F_OK) == -1) { if (mkdir(tmp, 0755) == -1) return FALSE; } strcat(tmp,"/config"); if (access(tmp, F_OK) == -1) { if (mkdir(tmp, 0755) == -1) return FALSE; } strcat(tmp, "/user.conf"); if (access(tmp,F_OK) == -1) { if ((fp = fopen(tmp, "w")) == NULL) return FALSE; fprintf(fp, "SERVERIP 0\nUSER 0\n"); fclose(fp); } p = strrchr(tmp, '/'); *p = '\0'; add_file_directory(tmp); return TRUE; }
static void read_path(InputStream * inp, char * path, int size) { int i = 0; char buf[FILE_PATH_SIZE]; json_read_string(inp, path, size); while (path[i] != 0) { if (path[i] == '\\') path[i] = '/'; i++; } #ifdef WIN32 if (path[0] != 0 && path[1] == ':' && path[2] == '/') return; #elif defined(_WRS_KERNEL) if (strncmp(path, FS_ROOT, strlen(FS_ROOT)) == 0) return; #endif if (path[0] == 0) { strncpy(path, get_user_home(), size - 1); path[size - 1] = 0; } else if (path[0] != '/') { snprintf(buf, sizeof(buf), "%s/%s", get_user_home(), path); strncpy(path, buf, size - 1); path[size - 1] = 0; } }
static void command_user(char * token, Channel * c) { if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX); write_stringz(&c->out, "R"); write_stringz(&c->out, token); json_write_long(&c->out, getuid()); write_stream(&c->out, 0); json_write_long(&c->out, geteuid()); write_stream(&c->out, 0); json_write_long(&c->out, getgid()); write_stream(&c->out, 0); json_write_long(&c->out, getegid()); write_stream(&c->out, 0); json_write_string(&c->out, get_user_home()); write_stream(&c->out, 0); write_stream(&c->out, MARKER_EOM); }
/****** read_defaults/get_user_home_file_path() ***************************** * NAME * get_user_home_file_path() -- get absolut path name to file in user * home * * SYNOPSIS * char *get_user_home_file_path (lList **answer_list) * * FUNCTION * This function returns the path to the file in the user's home * directory * * INPUTS * dstring - computed absoult filename * const char *filename - file name * const char *user - user name * lList* - answer list, AN_Type or NULL if everything ok * possible errors: * STATUS_ENOSUCHUSER - could not retrieve passwd info on me.user_name * STATUS_EDISK - home directory for user is missing or cwd * cannot be read or file could not be opened * (is just a warning) * STATUS_EEXIST - (parse_script_file), (is just a warning) * STATUS_EUNKNOWN - (parse_script_file), error opening or * reading from existing file, (is just a warning) * plus all other error stati returned by * parse_script_file, see there * * RETURNS * bool - true or false * * MT-NOTE: get_user_home_file_path() is MT safe *******************************************************************************/ bool get_user_home_file_path(dstring *absolut_filename, const char *filename, const char *user, lList **answer_list) { bool ret = false; DENTER (TOP_LAYER, "get_user_home_file_path"); if (absolut_filename != NULL && filename != NULL) { sge_dstring_clear(absolut_filename); if (get_user_home(absolut_filename, user, answer_list)) { sge_dstring_append(absolut_filename, "/"); sge_dstring_append(absolut_filename, filename); ret = true; } } DRETURN(ret); }
/* * 读取配置文件所在路径,如果正确读取,则返回TRUE */ static boolean login_config_set_path(struct login_config_struct *config) { char *p; debug_where(); login_config_error(config); p = get_user_home(); if (!p) { print_error(ESYSERR, "读取环境变量错误"); config->inited = FALSE; return FALSE; } if (!login_config_create()) { config->inited = FALSE; return TRUE; } snprintf(config->path, CONFIG_FILE_PATH_LEN, "%s/."USER_CONFIG_DIR_NAME"/config", p); add_file_directory(config->path); config->inited = TRUE; return TRUE; }