pkgsrc/mail/majordomo/patches/patch-ak
spz 3eeeb54cbd make the wrapper use getpwnam to determine uid and gid of the majordomo user
adjust the Makefile to fit

package beautification and lint shutup (like eg comments for some patches)
2010-10-30 23:48:35 +00:00

61 lines
1.4 KiB
Text

$NetBSD: patch-ak,v 1.4 2010/10/30 23:48:36 spz Exp $
add necessary headers
make it use getpwnam to find uid and gid to set to instead of hardwiring these
--- wrapper.c.orig 1997-08-27 15:01:12.000000000 +0000
+++ wrapper.c
@@ -15,11 +15,16 @@ static char rcs_header[] = "$Header: /so
#include <stdio.h>
#include <sysexits.h>
+#include <pwd.h>
-#if defined(sun) && defined(sparc)
+#if (defined(sun) && defined(sparc)) || defined(__NetBSD__)
#include <stdlib.h>
#endif
+#ifdef __NetBSD__
+#include <sys/types.h>
+#include <unistd.h>
+#endif
#ifndef STRCHR
# include <string.h>
@@ -65,6 +70,9 @@ main(argc, argv, env)
{
char * prog;
int e, i;
+#ifdef MAJORDOMO_USER
+ struct passwd *majordomuser;
+#endif
if (argc < 2) {
fprintf(stderr, "USAGE: %s program [<arg> ...]\n", argv[0]);
@@ -123,7 +131,17 @@ main(argc, argv, env)
}
#endif
+#ifdef MAJORDOMO_USER
+ if ((majordomuser = getpwnam(MAJORDOMO_USER)) == NULL) {
+ extern int errno;
+ fprintf(stderr, "%s: error user %s not found, errno %d", argv[0],
+ MAJORDOMO_USER, errno);
+ } else {
+ setgid(majordomuser->pw_gid);
+ setuid(majordomuser->pw_uid);
+ }
+#else
#ifdef POSIX_GID
setgid(POSIX_GID);
#else
@@ -135,6 +153,7 @@ main(argc, argv, env)
#else
setuid(geteuid());
#endif
+#endif
if ((getuid() != geteuid()) || (getgid() != getegid())) {
fprintf(stderr, "%s: error: Not running with proper UID and GID.\n", argv[0]);