summaryrefslogtreecommitdiffstats
path: root/usr.bin/at/privs.h
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1995-04-12 02:42:39 +0000
committerache <ache@FreeBSD.org>1995-04-12 02:42:39 +0000
commit3ec57b4b689ddd9845b2aa3fc49df92d4af934e5 (patch)
tree6cf28d2ee52a1c8127b4b9eb970fac96197d763f /usr.bin/at/privs.h
parent9d69b1d1123b6e165254dc11c02ef070402073f6 (diff)
downloadFreeBSD-src-3ec57b4b689ddd9845b2aa3fc49df92d4af934e5.zip
FreeBSD-src-3ec57b4b689ddd9845b2aa3fc49df92d4af934e5.tar.gz
Upgrade.
Diffstat (limited to 'usr.bin/at/privs.h')
-rw-r--r--usr.bin/at/privs.h84
1 files changed, 56 insertions, 28 deletions
diff --git a/usr.bin/at/privs.h b/usr.bin/at/privs.h
index e1ad1b4..34fd690 100644
--- a/usr.bin/at/privs.h
+++ b/usr.bin/at/privs.h
@@ -1,7 +1,6 @@
-/*
- * privs.h - header for privileged operations
- * Copyright (c) 1993 by Thomas Koenig
- * All rights reserved.
+/*
+ * privs.h - header for privileged operations
+ * Copyright (C) 1993 Thomas Koenig
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -22,31 +21,44 @@
* THEORY OF LIABILITY, WETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $Id: privs.h,v 1.1 1993/12/05 11:37:29 cgd Exp $
*/
#ifndef _PRIVS_H
#define _PRIVS_H
+#ifndef _USE_BSD
+#define _USE_BSD 1
+#include <unistd.h>
+#undef _USE_BSD
+#else
#include <unistd.h>
+#endif
-/* Relinquish privileges temporarily for a setuid program
+#ifdef __FreeBSD__
+/*
+ * setre[ug]id() not change r[ug]id for FreeBSD, but check it incorrectly
+ * for this program
+ */
+#define setreuid(r, e) seteuid(e)
+#define setregid(r, e) setegid(e)
+#endif
+
+/* Relinquish privileges temporarily for a setuid or setgid program
* with the option of getting them back later. This is done by swapping
* the real and effective userid BSD style. Call RELINQUISH_PRIVS once
* at the beginning of the main program. This will cause all operatons
* to be executed with the real userid. When you need the privileges
- * of the setuid invocation, call PRIV_START; when you no longer
+ * of the setuid/setgid invocation, call PRIV_START; when you no longer
* need it, call PRIV_END. Note that it is an error to call PRIV_START
* and not PRIV_END within the same function.
*
- * Use RELINQUISH_PRIVS_ROOT(a) if your program started out running
+ * Use RELINQUISH_PRIVS_ROOT(a,b) if your program started out running
* as root, and you want to drop back the effective userid to a
* and the effective group id to b, with the option to get them back
* later.
*
* If you no longer need root privileges, but those of some other
- * userid/groupid, you can call REDUCE_PRIV(a) when your effective
+ * userid/groupid, you can call REDUCE_PRIV(a,b) when your effective
* is the user's.
*
* Problems: Do not use return between PRIV_START and PRIV_END; this
@@ -65,28 +77,44 @@ extern
#endif
uid_t real_uid, effective_uid;
+#ifndef MAIN
+extern
+#endif
+gid_t real_gid, effective_gid;
+
#define RELINQUISH_PRIVS { \
- real_uid = getuid(); \
- effective_uid = geteuid(); \
- setreuid(effective_uid,real_uid); \
-}
+ real_uid = getuid(); \
+ effective_uid = geteuid(); \
+ real_gid = getgid(); \
+ effective_gid = getegid(); \
+ setregid(effective_gid, real_gid); \
+ setreuid(effective_uid, real_uid); \
+ }
-#define RELINQUISH_PRIVS_ROOT(a) { \
- real_uid = (a); \
- effective_uid = geteuid(); \
- setreuid(effective_uid,real_uid); \
-}
+#define RELINQUISH_PRIVS_ROOT(a,b) { \
+ real_uid = (a); \
+ effective_uid = geteuid(); \
+ real_gid = (b); \
+ effective_gid = getegid(); \
+ setregid(effective_gid, real_gid); \
+ setreuid(effective_uid, real_uid); \
+ }
-#define PRIV_START { \
- setreuid(real_uid,effective_uid);
+#define PRIV_START {\
+ setreuid(real_uid, effective_uid); \
+ setregid(real_gid, effective_gid);
#define PRIV_END \
- setreuid(effective_uid,real_uid); \
-}
+ setregid(effective_gid, real_gid); \
+ setreuid(effective_uid, real_uid); \
+ }
-#define REDUCE_PRIV(a) { \
- setreuid(real_uid,effective_uid); \
- effective_uid = (a); \
- setreuid(effective_uid,real_uid); \
-}
+#define REDUCE_PRIV(a,b) {\
+ setreuid(real_uid, effective_uid); \
+ setregid(real_gid, effective_gid); \
+ effective_uid = (a); \
+ effective_gid = (b); \
+ setregid(effective_gid, real_gid); \
+ setreuid(effective_uid, real_uid); \
+ }
#endif
OpenPOWER on IntegriCloud