summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2006-07-28 22:56:41 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:38:24 -0500
commite4e2be0d8b5778ecc5c521b9e0e0b4c05ac87394 (patch)
tree9d0d4a562c543c0f5686e4c0c16f6c7853abb1fa /source3/lib
parenta093a76dc14303fd1c42fb2c0b87faf3748815e4 (diff)
downloadsamba-e4e2be0d8b5778ecc5c521b9e0e0b4c05ac87394.tar.gz
samba-e4e2be0d8b5778ecc5c521b9e0e0b4c05ac87394.tar.bz2
samba-e4e2be0d8b5778ecc5c521b9e0e0b4c05ac87394.zip
r17294: Make the code a little cleaner. Instead of using the two
calls make it : become_root_uid_only() operation unbecome_root_uid_only() saving errno across the second call. Most of our internal change calls can be replaced with these simple calls. Jeremy (This used to be commit 4143aa83c029848d8ec741d9218b3fa6e3fd28dd)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/messages.c11
-rw-r--r--source3/lib/util_sec.c32
2 files changed, 33 insertions, 10 deletions
diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index bae4052964..410e4af659 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -167,7 +167,6 @@ static TDB_DATA message_key_pid(struct process_id pid)
static BOOL message_notify(struct process_id procid)
{
pid_t pid = procid.pid;
- int saved_errno;
int ret;
uid_t euid = geteuid();
@@ -179,23 +178,21 @@ static BOOL message_notify(struct process_id procid)
SMB_ASSERT(pid > 0);
if (euid != 0) {
- save_re_uid();
- set_effective_uid(0);
+ become_root_uid_only();
}
ret = kill(pid, SIGUSR1);
- saved_errno = errno;
if (euid != 0) {
- restore_re_uid();
+ unbecome_root_uid_only();
}
if (ret == -1) {
- if (saved_errno == ESRCH) {
+ if (errno == ESRCH) {
DEBUG(2,("pid %d doesn't exist - deleting messages record\n", (int)pid));
tdb_delete(tdb, message_key_pid(procid));
} else {
- DEBUG(2,("message to process %d failed - %s\n", (int)pid, strerror(saved_errno)));
+ DEBUG(2,("message to process %d failed - %s\n", (int)pid, strerror(errno)));
}
return False;
}
diff --git a/source3/lib/util_sec.c b/source3/lib/util_sec.c
index c13b20ec92..3f8cb690cd 100644
--- a/source3/lib/util_sec.c
+++ b/source3/lib/util_sec.c
@@ -258,10 +258,9 @@ void save_re_uid(void)
/****************************************************************************
and restore them!
****************************************************************************/
-void restore_re_uid(void)
-{
- set_effective_uid(0);
+static void restore_re_uid_fromroot(void)
+{
#if USE_SETRESUID
setresuid(saved_ruid, saved_euid, -1);
#elif USE_SETREUID
@@ -280,6 +279,33 @@ void restore_re_uid(void)
assert_uid(saved_ruid, saved_euid);
}
+void restore_re_uid(void)
+{
+ set_effective_uid(0);
+ restore_re_uid_fromroot();
+}
+
+/****************************************************************************
+ Lightweight become root - no group change.
+****************************************************************************/
+
+void become_root_uid_only(void)
+{
+ save_re_uid();
+ set_effective_uid(0);
+}
+
+/****************************************************************************
+ Lightweight unbecome root - no group change. Expects we are root already,
+ saves errno across call boundary.
+****************************************************************************/
+
+void unbecome_root_uid_only(void)
+{
+ int saved_errno = errno;
+ restore_re_uid_fromroot();
+ errno = saved_errno;
+}
/****************************************************************************
save the real and effective gid for later restoration. Used by the