static gpointer thread_create_user (gpointer data) { struct PasswdHandler *handler = (struct PasswdHandler *) data; if (!add_user (handler->username)) { g_warning ("create user:add user failed\n"); emit_progress ("user", "terminate"); return NULL; } if (!set_user_home (handler->username)) { g_warning ("create user:set user home failed\n"); emit_progress ("user", "terminate"); return NULL; } if (!set_group (handler->username)) { g_warning ("create user:set group failed\n"); emit_progress ("user", "terminate"); return NULL; } if (!write_hostname (handler->hostname)) { g_warning ("create user:write hostname failed\n"); emit_progress ("user", "terminate"); return NULL; } if (!set_user_password (handler)) { g_warning ("create user:set user password failed\n"); emit_progress ("user", "terminate"); return NULL; } emit_progress ("user", "finish"); return NULL; }
/* uses the global executable var */ int main(int argc, char *argv[]) { struct stat fileinfo; char *path = getenv("PATH"); int len, found = 0; char *pathcounter, save; char *myname = argv[0]; char myname_augmented[MAXPATHLEN]; #ifndef WIN_NT int link_len; #endif set_user_home(); #ifndef WIN_NT #ifndef SIMPLESCALAR /* Unix */ /* if we can read symlink, then it is a symlink */ if ( (link_len = readlink(myname, myname_augmented, MAXPATHLEN)) > 0 ) { /* we can't assume that the value of the link is null-terminated */ if ( *(myname_augmented+link_len) != '\0' ) *(myname_augmented+link_len+1) = '\0'; } else strcpy(myname_augmented, myname); #endif #else /* Windows doesn't seem to have readlink() */ strcpy(myname_augmented, myname); /* if executable doesn't end with .exe, then add it */ if ( *(myname_augmented + strlen(myname) - 4) != '.' || tolower(*(myname_augmented + strlen(myname) - 3)) != 'e' || tolower(*(myname_augmented + strlen(myname) - 2)) != 'x' || tolower(*(myname_augmented + strlen(myname) - 1)) != 'e' ) snprintf(myname_augmented, MAXPATHLEN, "%s.exe", myname); #endif #ifdef WIN_NT /* CygWin32 uses absolute paths like this: //<drive letter>/dir1/dir2/... actually /cygdrive/<drive letter>/.... If we find such a path, we transform it to a windows-like pathname. This assumes that XSB has been compiled using the native Windows API, and is being run from CygWin32 bash (like from the test scripts). */ transform_cygwin_pathname(myname_augmented); #endif if (is_absolute_filename(myname_augmented)) strcpy(executable_path_gl, myname_augmented); else { snprintf(executable_path_gl, MAXPATHLEN, "%s%c%s", current_dir_gl, SLASH, myname_augmented); } /* found executable by prepending cwd. */ if ((!stat(executable_path_gl, &fileinfo)) && (S_ISREG(fileinfo.st_mode))) { printf("%s",get_flora_install_dir()); return FALSE; } /* Otherwise, search PATH environment var. This code is a modified "which" shell builtin */ pathcounter = path; while (*pathcounter != '\0' && found == 0) { len = 0; while (*pathcounter != PATH_SEPARATOR && *pathcounter != '\0') { len++; pathcounter++; } /* save the separator ':' (or ';' on NT and replace it with \0) */ save = *pathcounter; *pathcounter = '\0'; /* Now `len' holds the length of the PATH component we are currently looking at. `pathcounter' points to the end of this component. */ snprintf(executable_path_gl, MAXPATHLEN, "%s%c%s", pathcounter - len, SLASH, myname_augmented); /* restore the separator and addvance the pathcounter */ *pathcounter = save; if (*pathcounter) pathcounter++; #ifdef WIN_NT found = (0 == access(executable_path_gl, 02)); /* readable */ #else found = (0 == access(executable_path_gl, 01)); /* executable */ #endif if (found) printf("%s",get_flora_install_dir()); } return FALSE; }