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