summaryrefslogtreecommitdiff
path: root/source3/lib/util_sec.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2001-06-25 00:46:34 +0000
committerAndrew Tridgell <tridge@samba.org>2001-06-25 00:46:34 +0000
commit8b79a473faf2ff25acb220500158920490c71576 (patch)
tree746af9446f50f1cc3403a6b10f8adb25291cd660 /source3/lib/util_sec.c
parentcc6bf9a06f0629f16ab455ad30b6c7b1a76ac0c2 (diff)
downloadsamba-8b79a473faf2ff25acb220500158920490c71576.tar.gz
samba-8b79a473faf2ff25acb220500158920490c71576.tar.bz2
samba-8b79a473faf2ff25acb220500158920490c71576.zip
- make the regresison test mode code build in by default. This should
allow us to have test targets without special configure options - fixed make proto so that it actually does something (This used to be commit 55109a752578e9389d853cb27ec17c2114ecff77)
Diffstat (limited to 'source3/lib/util_sec.c')
-rw-r--r--source3/lib/util_sec.c55
1 files changed, 40 insertions, 15 deletions
diff --git a/source3/lib/util_sec.c b/source3/lib/util_sec.c
index 164e6ab506..c62df82396 100644
--- a/source3/lib/util_sec.c
+++ b/source3/lib/util_sec.c
@@ -44,6 +44,31 @@ extern int DEBUGLEVEL;
#define smb_panic(x) exit(1)
#endif
+/* are we running as non-root? This is used by the regresison test code,
+ and potentially also for sites that want non-root smbd */
+static uid_t initial_uid;
+
+/****************************************************************************
+remember what uid we got started as - this allows us to run correctly
+as non-root while catching trapdoor systems
+****************************************************************************/
+void sec_init(void)
+{
+ initial_uid = geteuid();
+ if (initial_uid != (uid_t)0) {
+ /* the DEBUG() subsystem has not been initialised when this is called */
+ fprintf(stderr, "WARNING: running as non-root. Some functionality will be missing\n");
+ }
+}
+
+/****************************************************************************
+are we running in non-root mode?
+****************************************************************************/
+BOOL non_root_mode(void)
+{
+ return (initial_uid != (uid_t)0);
+}
+
/****************************************************************************
abort if we haven't set the uid correctly
****************************************************************************/
@@ -51,13 +76,13 @@ static void assert_uid(uid_t ruid, uid_t euid)
{
if ((euid != (uid_t)-1 && geteuid() != euid) ||
(ruid != (uid_t)-1 && getuid() != ruid)) {
-#ifndef SMB_REGRESSION_TEST
- DEBUG(0,("Failed to set uid privileges to (%d,%d) now set to (%d,%d)\n",
- (int)ruid, (int)euid,
- (int)getuid(), (int)geteuid()));
- smb_panic("failed to set uid\n");
- exit(1);
-#endif
+ if (!non_root_mode()) {
+ DEBUG(0,("Failed to set uid privileges to (%d,%d) now set to (%d,%d)\n",
+ (int)ruid, (int)euid,
+ (int)getuid(), (int)geteuid()));
+ smb_panic("failed to set uid\n");
+ exit(1);
+ }
}
}
@@ -68,14 +93,14 @@ static void assert_gid(gid_t rgid, gid_t egid)
{
if ((egid != (gid_t)-1 && getegid() != egid) ||
(rgid != (gid_t)-1 && getgid() != rgid)) {
-#ifndef SMB_REGRESSION_TEST
- DEBUG(0,("Failed to set gid privileges to (%d,%d) now set to (%d,%d) uid=(%d,%d)\n",
- (int)rgid, (int)egid,
- (int)getgid(), (int)getegid(),
- (int)getuid(), (int)geteuid()));
- smb_panic("failed to set gid\n");
- exit(1);
-#endif
+ if (!non_root_mode()) {
+ DEBUG(0,("Failed to set gid privileges to (%d,%d) now set to (%d,%d) uid=(%d,%d)\n",
+ (int)rgid, (int)egid,
+ (int)getgid(), (int)getegid(),
+ (int)getuid(), (int)geteuid()));
+ smb_panic("failed to set gid\n");
+ exit(1);
+ }
}
}