summaryrefslogtreecommitdiffstats
path: root/gl/idpriv-droptemp.c
diff options
context:
space:
mode:
Diffstat (limited to 'gl/idpriv-droptemp.c')
-rw-r--r--gl/idpriv-droptemp.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/gl/idpriv-droptemp.c b/gl/idpriv-droptemp.c
index eb882dea..993d25b6 100644
--- a/gl/idpriv-droptemp.c
+++ b/gl/idpriv-droptemp.c
@@ -1,5 +1,5 @@
1/* Dropping uid/gid privileges of the current process temporarily. 1/* Dropping uid/gid privileges of the current process temporarily.
2 Copyright (C) 2009-2024 Free Software Foundation, Inc. 2 Copyright (C) 2009-2026 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify 4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
@@ -25,18 +25,18 @@
25 25
26/* The privileged uid and gid that the process had earlier. */ 26/* The privileged uid and gid that the process had earlier. */
27#if HAVE_GETUID 27#if HAVE_GETUID
28static int saved_uid = -1; 28static uid_t saved_uid = -1;
29#endif 29#endif
30#if HAVE_GETGID 30#if HAVE_GETGID
31static int saved_gid = -1; 31static gid_t saved_gid = -1;
32#endif 32#endif
33 33
34int 34int
35idpriv_temp_drop (void) 35idpriv_temp_drop (void)
36{ 36{
37#if HAVE_GETEUID && HAVE_GETEGID && (HAVE_SETRESUID || HAVE_SETREUID) && (HAVE_SETRESGID || HAVE_SETREGID) 37#if HAVE_GETEUID && HAVE_GETEGID && (HAVE_SETRESUID || HAVE_SETREUID) && (HAVE_SETRESGID || HAVE_SETREGID)
38 int uid = getuid (); 38 uid_t uid = getuid ();
39 int gid = getgid (); 39 gid_t gid = getgid ();
40 40
41 /* Find out about the privileged uid and gid at the first call. */ 41 /* Find out about the privileged uid and gid at the first call. */
42 if (saved_uid == -1) 42 if (saved_uid == -1)
@@ -51,7 +51,7 @@ idpriv_temp_drop (void)
51# if HAVE_SETRESGID /* glibc, FreeBSD, OpenBSD, HP-UX */ 51# if HAVE_SETRESGID /* glibc, FreeBSD, OpenBSD, HP-UX */
52 if (setresgid (-1, gid, saved_gid) < 0) 52 if (setresgid (-1, gid, saved_gid) < 0)
53 return -1; 53 return -1;
54# else /* Mac OS X, NetBSD, AIX, IRIX, Solaris >= 2.5, OSF/1, Cygwin */ 54# else /* Mac OS X, NetBSD, AIX, Solaris >= 2.5, Cygwin */
55 if (setregid (-1, gid) < 0) 55 if (setregid (-1, gid) < 0)
56 return -1; 56 return -1;
57# endif 57# endif
@@ -64,7 +64,7 @@ idpriv_temp_drop (void)
64 figure 14. */ 64 figure 14. */
65 if (setresuid (-1, uid, saved_uid) < 0) 65 if (setresuid (-1, uid, saved_uid) < 0)
66 return -1; 66 return -1;
67# else /* Mac OS X, NetBSD, AIX, IRIX, Solaris >= 2.5, OSF/1, Cygwin */ 67# else /* Mac OS X, NetBSD, AIX, Solaris >= 2.5, Cygwin */
68 if (setreuid (-1, uid) < 0) 68 if (setreuid (-1, uid) < 0)
69 return -1; 69 return -1;
70# endif 70# endif
@@ -124,8 +124,8 @@ int
124idpriv_temp_restore (void) 124idpriv_temp_restore (void)
125{ 125{
126#if HAVE_GETEUID && HAVE_GETEGID && (HAVE_SETRESUID || HAVE_SETREUID) && (HAVE_SETRESGID || HAVE_SETREGID) 126#if HAVE_GETEUID && HAVE_GETEGID && (HAVE_SETRESUID || HAVE_SETREUID) && (HAVE_SETRESGID || HAVE_SETREGID)
127 int uid = getuid (); 127 uid_t uid = getuid ();
128 int gid = getgid (); 128 gid_t gid = getgid ();
129 129
130 if (saved_uid == -1 || saved_gid == -1) 130 if (saved_uid == -1 || saved_gid == -1)
131 /* Caller error: idpriv_temp_drop was never invoked. */ 131 /* Caller error: idpriv_temp_drop was never invoked. */
@@ -142,7 +142,7 @@ idpriv_temp_restore (void)
142 figure 14. */ 142 figure 14. */
143 if (setresuid (-1, saved_uid, -1) < 0) 143 if (setresuid (-1, saved_uid, -1) < 0)
144 return -1; 144 return -1;
145# else /* Mac OS X, NetBSD, AIX, IRIX, Solaris >= 2.5, OSF/1, Cygwin */ 145# else /* Mac OS X, NetBSD, AIX, Solaris >= 2.5, Cygwin */
146 if (setreuid (-1, saved_uid) < 0) 146 if (setreuid (-1, saved_uid) < 0)
147 return -1; 147 return -1;
148# endif 148# endif
@@ -151,7 +151,7 @@ idpriv_temp_restore (void)
151# if HAVE_SETRESGID /* glibc, FreeBSD, OpenBSD, HP-UX */ 151# if HAVE_SETRESGID /* glibc, FreeBSD, OpenBSD, HP-UX */
152 if (setresgid (-1, saved_gid, -1) < 0) 152 if (setresgid (-1, saved_gid, -1) < 0)
153 return -1; 153 return -1;
154# else /* Mac OS X, NetBSD, AIX, IRIX, Solaris >= 2.5, OSF/1, Cygwin */ 154# else /* Mac OS X, NetBSD, AIX, Solaris >= 2.5, Cygwin */
155 if (setregid (-1, saved_gid) < 0) 155 if (setregid (-1, saved_gid) < 0)
156 return -1; 156 return -1;
157# endif 157# endif