#if defined(RLIMIT_CORE) && !defined(SUDO_DEVEL)
static struct rlimit corelimit;
#endif /* RLIMIT_CORE && !SUDO_DEVEL */
+#if defined(__linux__)
+static struct rlimit nproclimit;
+#endif
#ifdef HAVE_LOGIN_CAP_H
login_cap_t *lc;
#endif /* HAVE_LOGIN_CAP_H */
}
}
+ /*
+ * Restore nproc resource limit if pam_limits didn't do it for us.
+ * We must do this *after* the uid change to avoid potential EAGAIN
+ * from setuid().
+ */
+#if defined(__linux__)
+ {
+ struct rlimit rl;
+ if (getrlimit(RLIMIT_NPROC, &rl) == 0) {
+ if (rl.rlim_cur == RLIM_INFINITY && rl.rlim_max == RLIM_INFINITY)
+ (void) setrlimit(RLIMIT_NPROC, &nproclimit);
+ }
+ }
+#endif
+
rval = TRUE;
done:
* apply resource limits when changing uid and return EAGAIN if
* nproc would be violated by the uid switch.
*/
+ (void) getrlimit(RLIMIT_NPROC, &nproclimit);
rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
if (setrlimit(RLIMIT_NPROC, &rl)) {
- if (getrlimit(RLIMIT_NPROC, &rl) == 0) {
- rl.rlim_cur = rl.rlim_max;
- (void)setrlimit(RLIMIT_NPROC, &rl);
- }
+ memcpy(&rl, &nproclimit, sizeof(struct rlimit));
+ rl.rlim_cur = rl.rlim_max;
+ (void)setrlimit(RLIMIT_NPROC, &rl);
}
#endif /* __linux__ */
#if defined(RLIMIT_CORE) && !defined(SUDO_DEVEL)