summaryrefslogtreecommitdiff
path: root/bin/autobuild.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/autobuild.c')
-rw-r--r--bin/autobuild.c54
1 files changed, 42 insertions, 12 deletions
diff --git a/bin/autobuild.c b/bin/autobuild.c
index 86d164c..4d0580f 100644
--- a/bin/autobuild.c
+++ b/bin/autobuild.c
@@ -14,13 +14,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#define _GNU_SOURCE /* for unsetenv(3) */
+#define _GNU_SOURCE /* for environment functions */
#include <alloca.h> /* for alloca(3) */
#include <errno.h> /* for errno */
#include <error.h> /* for error(3) */
#include <pwd.h> /* for getpwuid(3) */
#include <stdio.h> /* for printf(3) */
-#include <stdlib.h> /* for unsetenv(3) */
+#include <stdlib.h> /* for environment functions */
#include <string.h> /* for strlen(3), strcpy(3) */
#include <unistd.h> /* for dup2(3), geteuid(3), execl(3) */
@@ -28,7 +28,17 @@ void
usage(const char *cmd)
{
printf("Usage: %s PACKAGE\n", cmd);
- printf("This command should be run from the git directory of the package source.");
+ printf("This command should be run from the git directory of the package source.\n");
+}
+
+void
+mysetenv(const char *name, const char *value)
+{
+ if (value != NULL) {
+ if (setenv(name, value, 1) != 0) {
+ error(127, errno, "could not set %s", name);
+ }
+ }
}
int
@@ -40,17 +50,37 @@ main(int argc, char **argv)
return 1;
}
- const char *home = getpwuid(geteuid())->pw_dir;
- const char *script_suffix = "/bin/autobuild.sh";
- char *script = alloca(strlen(home)+strlen(script_suffix));
- strcpy(script, home);
- strcpy(&(script[strlen(home)]), script_suffix);
+ struct passwd *user = getpwuid(geteuid());
+ setreuid(geteuid(), -1);
- unsetenv("IFS");
- unsetenv("PATH");
- unsetenv("LD_PRELOAD");
- unsetenv("BASH_ENV");
+ printf("ruid:%d\teuid:%d\n", getuid(), geteuid());
+ const char *env_term = getenv("TERM");
+ const char *env_lang = getenv("LANG");
+ const char *env_lc_all = getenv("LC_ALL");
+ const char *env_lc_collate = getenv("LC_COLLATE");
+ const char *env_lc_ctype = getenv("LC_CTIME");
+ const char *env_lc_messages = getenv("LC_MESSAGES");
+ const char *env_lc_monetary = getenv("LC_MONETARY");
+ const char *env_lc_numeric = getenv("LC_NUMERIC");
+ const char *env_lc_time = getenv("LC_TIME");
+ clearenv();
+ mysetenv("USER" , user->pw_name );
+ mysetenv("LOGNAME" , user->pw_name );
+ mysetenv("HOME" , user->pw_dir );
+ mysetenv("TERM" , env_term );
+ mysetenv("LANG" , env_lang );
+ mysetenv("LC_ALL" , env_lc_all );
+ mysetenv("LC_COLLATE" , env_lc_collate );
+ mysetenv("LC_CTIME" , env_lc_ctype );
+ mysetenv("LC_MESSAGES", env_lc_messages);
+ mysetenv("LC_MONETARY", env_lc_monetary);
+ mysetenv("LC_NUMERIC" , env_lc_numeric );
+ mysetenv("LC_TIME" , env_lc_time );
+ const char *script_suffix = "/bin/autobuild.sh";
+ char *script = alloca(strlen(user->pw_dir)+strlen(script_suffix));
+ strcpy(script, user->pw_dir);
+ strcpy(&(script[strlen(user->pw_dir)]), script_suffix);
execl(script, script, argv[1], NULL);
error(127, errno, "%s", script);
}