summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
bedc78b)
Fix suggested by Gao Chan from Tsinghua.
void runas_slice_user(char *username)
{
void runas_slice_user(char *username)
{
+ struct passwd pwdd, *pwd = &pwdd, *result;
+ char *pwdBuffer;
char *home_env, *logname_env, *mail_env, *shell_env, *user_env;
int home_len, logname_len, mail_len, shell_len, user_len;
char *home_env, *logname_env, *mail_env, *shell_env, *user_env;
int home_len, logname_len, mail_len, shell_len, user_len;
- if ((pwd = getpwnam(username)) == NULL) {
+
+ pwdBuffer_len = sysconf(_SC_GETPW_R_SIZE_MAX);
+ if (pwdBuffer_len == -1) {
+ perror("vserver: _SC_GETPW_R_SIZE_MAX not defined ");
+ exit(1);
+ }
+
+ pwdBuffer = (char*)malloc(pwdBuffer_len);
+ if (pwdBuffer == NULL) {
+ perror("vserver: malloc error ");
+ exit(1);
+ }
+
+ errno = 0;
+ if ((getpwnam_r(username,pwd,pwdBuffer,pwdBuffer_len, &result) != 0) || (errno != 0)) {
perror("vserver: getpwnam error ");
exit(1);
}
perror("vserver: getpwnam error ");
exit(1);
}
void slice_enter(char *context)
{
void slice_enter(char *context)
{
+ struct passwd pwdd, *pwd = &pwdd, *result;
+ char *pwdBuffer;
+ long pwdBuffer_len;
unsigned remove_cap;
uid_t uid;
unsigned remove_cap;
uid_t uid;
- if ((pwd = getpwnam(context)) == NULL) {
+ pwdBuffer_len = sysconf(_SC_GETPW_R_SIZE_MAX);
+ if (pwdBuffer_len == -1) {
+ perror("vserver: _SC_GETPW_R_SIZE_MAX not defined ");
+ exit(1);
+ }
+
+ pwdBuffer = (char*)malloc(pwdBuffer_len);
+ if (pwdBuffer == NULL) {
+ perror("vserver: malloc error ");
+ exit(1);
+ }
+
+ errno = 0;
+ if ((getpwnam_r(context,pwd,pwdBuffer,pwdBuffer_len, &result) != 0) || (errno != 0)) {
fprintf(stderr,"vserver: getpwname(%s) failed",context);
fprintf(stderr,"vserver: getpwname(%s) failed",context);
-extern void slice_enter(char *);
-extern void runas_slice_user(char *);
-
int main(int argc, char **argv)
{
int main(int argc, char **argv)
{
- char *context, *username, *shell;
- struct passwd *pwd;
+ struct passwd pwdd, *pwd = &pwdd, *result;
+ char *context, *username, *shell, *pwdBuffer;
+ long pwdBuffer_len;
if (argv[0][0]=='-')
index = 1;
if (argv[0][0]=='-')
index = 1;
/* With the uid/gid appropriately set. Let's figure out what the
* shell in the vserver's /etc/passwd is for the given username.
*/
/* With the uid/gid appropriately set. Let's figure out what the
* shell in the vserver's /etc/passwd is for the given username.
*/
- if ((pwd = getpwnam(username)) == NULL) {
+
+ pwdBuffer_len = sysconf(_SC_GETPW_R_SIZE_MAX);
+ if (pwdBuffer_len == -1) {
+ perror("vserver: _SC_GETPW_R_SIZE_MAX not defined ");
+ exit(1);
+ }
+ pwdBuffer = (char*)malloc(pwdBuffer_len);
+ if (pwdBuffer == NULL) {
+ perror("vserver: malloc error ");
+ exit(1);
+ }
+
+ errno = 0;
+ if ((getpwnam_r(username,pwd,pwdBuffer,pwdBuffer_len, &result) != 0) || (errno != 0)) {
fprintf(stderr,"vsh: getpwnam error failed for %s\n",username);
exit(1);
}
fprintf(stderr,"vsh: getpwnam error failed for %s\n",username);
exit(1);
}