|
|
d972f3 |
diff -up Linux-PAM-1.3.1/modules/pam_limits/limits.conf.5.xml.pam-limits-unlimited-value Linux-PAM-1.3.1/modules/pam_limits/limits.conf.5.xml
|
|
|
d972f3 |
--- Linux-PAM-1.3.1/modules/pam_limits/limits.conf.5.xml.pam-limits-unlimited-value 2022-01-28 09:45:41.431606850 +0100
|
|
|
d972f3 |
+++ Linux-PAM-1.3.1/modules/pam_limits/limits.conf.5.xml 2022-01-28 09:47:31.732430391 +0100
|
|
|
d972f3 |
@@ -275,6 +275,8 @@
|
|
|
d972f3 |
All items support the values <emphasis>-1</emphasis>,
|
|
|
d972f3 |
<emphasis>unlimited</emphasis> or <emphasis>infinity</emphasis> indicating no limit,
|
|
|
d972f3 |
except for <emphasis remap='B'>priority</emphasis> and <emphasis remap='B'>nice</emphasis>.
|
|
|
d972f3 |
+ If <emphasis remap='B'>nofile</emphasis> is to be set to one of these values,
|
|
|
d972f3 |
+ it will be set to the contents of /proc/sys/fs/nr_open instead (see setrlimit(3)).
|
|
|
d972f3 |
</para>
|
|
|
d972f3 |
<para>
|
|
|
d972f3 |
If a hard limit or soft limit of a resource is set to a valid value,
|
|
|
d972f3 |
diff -up Linux-PAM-1.3.1/modules/pam_limits/pam_limits.c.pam-limits-unlimited-value Linux-PAM-1.3.1/modules/pam_limits/pam_limits.c
|
|
|
d972f3 |
--- Linux-PAM-1.3.1/modules/pam_limits/pam_limits.c.pam-limits-unlimited-value 2022-01-28 09:45:41.415606731 +0100
|
|
|
d972f3 |
+++ Linux-PAM-1.3.1/modules/pam_limits/pam_limits.c 2022-01-28 09:45:41.431606850 +0100
|
|
|
d972f3 |
@@ -487,6 +487,41 @@ static int init_limits(pam_handle_t *pam
|
|
|
d972f3 |
return retval;
|
|
|
d972f3 |
}
|
|
|
d972f3 |
|
|
|
d972f3 |
+/*
|
|
|
d972f3 |
+ * Read the contents of <pathname> and return it in *valuep
|
|
|
d972f3 |
+ * return 1 if conversion succeeds, result is in *valuep
|
|
|
d972f3 |
+ * return 0 if conversion fails, *valuep is untouched.
|
|
|
d972f3 |
+ */
|
|
|
d972f3 |
+static int
|
|
|
d972f3 |
+value_from_file(const char *pathname, rlim_t *valuep)
|
|
|
d972f3 |
+{
|
|
|
d972f3 |
+ char buf[128];
|
|
|
d972f3 |
+ FILE *fp;
|
|
|
d972f3 |
+ int retval;
|
|
|
d972f3 |
+
|
|
|
d972f3 |
+ retval = 0;
|
|
|
d972f3 |
+
|
|
|
d972f3 |
+ if ((fp = fopen(pathname, "r")) != NULL) {
|
|
|
d972f3 |
+ if (fgets(buf, sizeof(buf), fp) != NULL) {
|
|
|
d972f3 |
+ char *endptr;
|
|
|
d972f3 |
+ unsigned long long value;
|
|
|
d972f3 |
+
|
|
|
d972f3 |
+ errno = 0;
|
|
|
d972f3 |
+ value = strtoull(buf, &endptr, 10);
|
|
|
d972f3 |
+ if (endptr != buf &&
|
|
|
d972f3 |
+ (value != ULLONG_MAX || errno == 0) &&
|
|
|
d972f3 |
+ (unsigned long long) (rlim_t) value == value) {
|
|
|
d972f3 |
+ *valuep = (rlim_t) value;
|
|
|
d972f3 |
+ retval = 1;
|
|
|
d972f3 |
+ }
|
|
|
d972f3 |
+ }
|
|
|
d972f3 |
+
|
|
|
d972f3 |
+ fclose(fp);
|
|
|
d972f3 |
+ }
|
|
|
d972f3 |
+
|
|
|
d972f3 |
+ return retval;
|
|
|
d972f3 |
+}
|
|
|
d972f3 |
+
|
|
|
d972f3 |
static void
|
|
|
d972f3 |
process_limit (const pam_handle_t *pamh, int source, const char *lim_type,
|
|
|
d972f3 |
const char *lim_item, const char *lim_value,
|
|
|
d972f3 |
@@ -652,6 +687,20 @@ process_limit (const pam_handle_t *pamh,
|
|
|
d972f3 |
rlimit_value = 20 - int_value;
|
|
|
d972f3 |
break;
|
|
|
d972f3 |
#endif
|
|
|
d972f3 |
+ case RLIMIT_NOFILE:
|
|
|
d972f3 |
+ /*
|
|
|
d972f3 |
+ * If nofile is to be set to "unlimited", try to set it to
|
|
|
d972f3 |
+ * the value in /proc/sys/fs/nr_open instead.
|
|
|
d972f3 |
+ */
|
|
|
d972f3 |
+ if (rlimit_value == RLIM_INFINITY) {
|
|
|
d972f3 |
+ if (!value_from_file("/proc/sys/fs/nr_open", &rlimit_value))
|
|
|
d972f3 |
+ pam_syslog(pamh, LOG_WARNING,
|
|
|
d972f3 |
+ "Cannot set \"nofile\" to a sensible value");
|
|
|
d972f3 |
+ else if (ctrl & PAM_DEBUG_ARG)
|
|
|
d972f3 |
+ pam_syslog(pamh, LOG_DEBUG, "Setting \"nofile\" limit to %llu",
|
|
|
d972f3 |
+ (unsigned long long) rlimit_value);
|
|
|
d972f3 |
+ }
|
|
|
d972f3 |
+ break;
|
|
|
d972f3 |
}
|
|
|
d972f3 |
|
|
|
d972f3 |
if ( (limit_item != LIMIT_LOGIN)
|