/* Become the user and group(s) specified by PW. */
-void change_identity ( const struct passwd *pw )
+const char *change_identity_e2str(const struct passwd *pw)
{
- if ( initgroups ( pw-> pw_name, pw-> pw_gid ) == -1 )
- bb_perror_msg_and_die ( "cannot set groups" );
- endgrent ( );
+ if (initgroups(pw->pw_name, pw->pw_gid) == -1)
+ return "cannot set groups";
+ endgrent();
- if ( setgid ( pw-> pw_gid ))
- bb_perror_msg_and_die ( "cannot set group id" );
- if ( setuid ( pw->pw_uid ))
- bb_perror_msg_and_die ( "cannot set user id" );
+ xsetgid(pw->pw_gid);
+ xsetuid(pw->pw_uid);
+ return NULL;
}
+void change_identity(const struct passwd *pw)
+{
+ const char *err_msg = change_identity_e2str(pw);
+
+ if(err_msg)
+ bb_perror_msg_and_die("%s", err_msg);
+}