[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r1693 - GNUnet/src/server
From: |
durner |
Subject: |
[GNUnet-SVN] r1693 - GNUnet/src/server |
Date: |
Tue, 16 Aug 2005 12:16:50 -0700 (PDT) |
Author: durner
Date: 2005-08-16 12:16:45 -0700 (Tue, 16 Aug 2005)
New Revision: 1693
Modified:
GNUnet/src/server/gnunetd.c
GNUnet/src/server/startup.c
GNUnet/src/server/startup.h
Log:
run as user specified in .conf
Modified: GNUnet/src/server/gnunetd.c
===================================================================
--- GNUnet/src/server/gnunetd.c 2005-08-16 19:16:01 UTC (rev 1692)
+++ GNUnet/src/server/gnunetd.c 2005-08-16 19:16:45 UTC (rev 1693)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2001, 2002, 2004 Christian Grothoff (and other contributing authors)
+ (C) 2001, 2002, 2004, 2005 Christian Grothoff (and other contributing
authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -100,6 +100,13 @@
*/
void gnunet_main() {
int filedes[2]; /* pipe between client and parent */
+
+ /* init 0: change user */
+#ifndef MINGW
+ char *user = getConfigurationString("GNUNETD", "USER");
+ if (user && strlen(user))
+ changeUser(user);
+#endif
/* init 1: version management for GNUnet core,
essentially forces running gnunet-update
Modified: GNUnet/src/server/startup.c
===================================================================
--- GNUnet/src/server/startup.c 2005-08-16 19:16:01 UTC (rev 1692)
+++ GNUnet/src/server/startup.c 2005-08-16 19:16:45 UTC (rev 1693)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2001, 2002, 2004 Christian Grothoff (and other contributing authors)
+ (C) 2001, 2002, 2004, 2005 Christian Grothoff (and other contributing
authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -399,7 +399,31 @@
help);
}
+#ifndef MINGW
+/**
+ * @brief Change user ID
+ */
+void changeUser(const char *user) {
+ struct passwd * pws;
+ pws = getpwnam(user);
+ if(pws == NULL) {
+ LOG(LOG_WARNING,
+ _("User '%s' not known, cannot change UID to it.\n"), user);
+ return;
+ }
+ if((0 != setgid(pws->pw_gid)) ||
+ (0 != setegid(pws->pw_gid)) ||
+ (0 != setuid(pws->pw_uid)) || (0 != seteuid(pws->pw_uid))) {
+ if((0 != setregid(pws->pw_gid, pws->pw_gid)) ||
+ (0 != setreuid(pws->pw_uid, pws->pw_uid)))
+ LOG(LOG_WARNING,
+ _("Cannot change user/group to '%s': %s\n"),
+ user, STRERROR(errno));
+ }
+}
+#endif
+
/**
* Perform option parsing from the command line.
*/
@@ -407,9 +431,6 @@
char * argv[]) {
int cont = OK;
int c;
-#ifndef MINGW
- struct passwd * pws;
-#endif
/* set the 'magic' code that indicates that
this process is 'gnunetd' (and not any of
@@ -482,24 +503,7 @@
break;
#ifndef MINGW /* not supported */
case 'u':
- pws = getpwnam(GNoptarg);
- if (pws == NULL) {
- LOG(LOG_WARNING,
- _("User '%s' not known, cannot change UID to it."),
- GNoptarg);
- break;
- }
- if ( (0 != setgid(pws->pw_gid)) ||
- (0 != setegid(pws->pw_gid)) ||
- (0 != setuid(pws->pw_uid)) ||
- (0 != seteuid(pws->pw_uid)) ) {
- if ( (0 != setregid(pws->pw_gid, pws->pw_gid)) ||
- (0 != setreuid(pws->pw_uid, pws->pw_uid)) )
- LOG(LOG_WARNING,
- _("Cannot change user/group to '%s': %s"),
- GNoptarg,
- STRERROR(errno));
- }
+ changeUser(GNoptarg);
break;
#endif
#ifdef MINGW
Modified: GNUnet/src/server/startup.h
===================================================================
--- GNUnet/src/server/startup.h 2005-08-16 19:16:01 UTC (rev 1692)
+++ GNUnet/src/server/startup.h 2005-08-16 19:16:45 UTC (rev 1693)
@@ -84,6 +84,12 @@
*/
void loadApplicationModules();
+#ifndef MINGW
+/**
+ * @brief Change user ID
+ */
+void changeUser(const char *user);
+#endif
#ifdef MINGW
BOOL WINAPI win_shutdown_gnunetd(DWORD dwCtrlType);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r1693 - GNUnet/src/server,
durner <=