dom0: Allow UID as parameter to qfile-dom0-unpacker

This commit is contained in:
Marek Marczykowski 2011-07-17 00:35:34 +02:00
parent 4f10835d83
commit 79d593e191

View File

@ -19,15 +19,20 @@
int prepare_creds_return_uid(char *username) int prepare_creds_return_uid(char *username)
{ {
struct passwd *pwd; struct passwd *pwd;
// First try name
pwd = getpwnam(username); pwd = getpwnam(username);
if (!pwd) { if (!pwd) {
perror("getpwnam"); // Then try UID
exit(1); pwd = getpwuid(atoi(username));
if (!pwd) {
perror("getpwuid");
exit(1);
}
} }
setenv("HOME", pwd->pw_dir, 1); setenv("HOME", pwd->pw_dir, 1);
setenv("USER", username, 1); setenv("USER", pwd->pw_name, 1);
setgid(pwd->pw_gid); setgid(pwd->pw_gid);
initgroups(username, pwd->pw_gid); initgroups(pwd->pw_name, pwd->pw_gid);
setfsuid(pwd->pw_uid); setfsuid(pwd->pw_uid);
return pwd->pw_uid; return pwd->pw_uid;
} }