]> granicus.if.org Git - linux-pam/blob - modules/pam_limits/pam_limits.c
Relevant BUGIDs:
[linux-pam] / modules / pam_limits / pam_limits.c
1 /*
2  * pam_limits - impose resource limits when opening a user session
3  *
4  * 1.6 - modified for PLD (added process priority settings)
5  *       by Marcin Korzonek <mkorz@shadow.eu.org>
6  * 1.5 - Elliot Lee's "max system logins patch"
7  * 1.4 - addressed bug in configuration file parser
8  * 1.3 - modified the configuration file format
9  * 1.2 - added 'debug' and 'conf=' arguments
10  * 1.1 - added @group support
11  * 1.0 - initial release - Linux ONLY
12  *
13  * See end for Copyright information
14  */
15
16 #if !(defined(linux))
17 #error THIS CODE IS KNOWN TO WORK ONLY ON LINUX !!!
18 #endif
19
20 #include "config.h"
21
22 #include <stdio.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include <ctype.h>
26 #include <stdlib.h>
27 #include <errno.h>
28 #include <syslog.h>
29 #include <stdarg.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #include <sys/resource.h>
33 #include <limits.h>
34
35 #include <utmp.h>
36 #ifndef UT_USER  /* some systems have ut_name instead of ut_user */
37 #define UT_USER ut_user
38 #endif
39
40 #include <grp.h>
41 #include <pwd.h>
42
43 /* Module defines */
44 #define LINE_LENGTH 1024
45
46 #define LIMITS_DEF_USER     0 /* limit was set by an user entry */
47 #define LIMITS_DEF_GROUP    1 /* limit was set by a group entry */
48 #define LIMITS_DEF_ALLGROUP 2 /* limit was set by a group entry */
49 #define LIMITS_DEF_ALL      3 /* limit was set by an default entry */
50 #define LIMITS_DEF_DEFAULT  4 /* limit was set by an default entry */
51 #define LIMITS_DEF_NONE     5 /* this limit was not set yet */
52
53 static const char *limits_def_names[] = {
54        "USER",
55        "GROUP",
56        "ALLGROUP",
57        "ALL",
58        "DEFAULT",
59        "NONE",
60        NULL
61 };
62
63 struct user_limits_struct {
64     int supported;
65     int src_soft;
66     int src_hard;
67     struct rlimit limit;
68 };
69
70 /* internal data */
71 struct pam_limit_s {
72     int login_limit;     /* the max logins limit */
73     int login_limit_def; /* which entry set the login limit */
74     int flag_numsyslogins; /* whether to limit logins only for a
75                               specific user or to count all logins */
76     int priority;        /* the priority to run user process with */
77     struct user_limits_struct limits[RLIM_NLIMITS];
78     char conf_file[BUFSIZ];
79     int utmp_after_pam_call;
80     char login_group[LINE_LENGTH];
81 };
82
83 #define LIMIT_LOGIN RLIM_NLIMITS+1
84 #define LIMIT_NUMSYSLOGINS RLIM_NLIMITS+2
85
86 #define LIMIT_PRI RLIM_NLIMITS+3
87
88 #define LIMIT_SOFT  1
89 #define LIMIT_HARD  2
90
91 #define PAM_SM_SESSION
92
93 #include <security/pam_modules.h>
94 #include <security/_pam_macros.h>
95 #include <security/pam_modutil.h>
96 #include <security/pam_ext.h>
97
98 /* argument parsing */
99
100 #define PAM_DEBUG_ARG       0x0001
101 #define PAM_DO_SETREUID     0x0002
102 #define PAM_UTMP_EARLY      0x0004
103
104 static int
105 _pam_parse (const pam_handle_t *pamh, int argc, const char **argv,
106             struct pam_limit_s *pl)
107 {
108     int ctrl=0;
109
110     /* step through arguments */
111     for (ctrl=0; argc-- > 0; ++argv) {
112
113         /* generic options */
114
115         if (!strcmp(*argv,"debug")) {
116             ctrl |= PAM_DEBUG_ARG;
117         } else if (!strncmp(*argv,"conf=",5)) {
118             strncpy(pl->conf_file,*argv+5,sizeof(pl->conf_file)-1);
119         } else if (!strncmp(*argv,"change_uid",10)) {
120             ctrl |= PAM_DO_SETREUID;
121         } else if (!strcmp(*argv,"utmp_early")) {
122             ctrl |= PAM_UTMP_EARLY;
123         } else {
124             pam_syslog(pamh, LOG_ERR, "unknown option: %s", *argv);
125         }
126     }
127     pl->conf_file[sizeof(pl->conf_file) - 1] = '\0';
128
129     return ctrl;
130 }
131
132
133 #define LIMITED_OK 0 /* limit setting appeared to work */
134 #define LIMIT_ERR  1 /* error setting a limit */
135 #define LOGIN_ERR  2 /* too many logins err */
136
137 /* Counts the number of user logins and check against the limit*/
138 static int
139 check_logins (pam_handle_t *pamh, const char *name, int limit, int ctrl,
140               struct pam_limit_s *pl)
141 {
142     struct utmp *ut;
143     int count;
144
145     if (ctrl & PAM_DEBUG_ARG) {
146         pam_syslog(pamh, LOG_DEBUG,
147                    "checking logins for '%s' (maximum of %d)", name, limit);
148     }
149
150     if (limit < 0)
151         return 0; /* no limits imposed */
152     if (limit == 0) /* maximum 0 logins ? */ {
153         pam_syslog(pamh, LOG_WARNING, "No logins allowed for '%s'", name);
154         return LOGIN_ERR;
155     }
156
157     setutent();
158
159     /* Because there is no definition about when an application
160        actually adds a utmp entry, some applications bizarrely do the
161        utmp call before the have PAM authenticate them to the system:
162        you're logged it, sort of...? Anyway, you can use the
163        "utmp_early" module argument in your PAM config file to make
164        allowances for this sort of problem. (There should be a PAM
165        standard for this, since if a module wants to actually map a
166        username then any early utmp entry will be for the unmapped
167        name = broken.) */
168
169     if (ctrl & PAM_UTMP_EARLY) {
170         count = 0;
171     } else {
172         count = 1;
173     }
174
175     while((ut = getutent())) {
176 #ifdef USER_PROCESS
177         if (ut->ut_type != USER_PROCESS) {
178             continue;
179         }
180 #endif
181         if (ut->UT_USER[0] == '\0') {
182             continue;
183         }
184         if (!pl->flag_numsyslogins) {
185             if (((pl->login_limit_def == LIMITS_DEF_USER)
186                  || (pl->login_limit_def == LIMITS_DEF_GROUP)
187                  || (pl->login_limit_def == LIMITS_DEF_DEFAULT))
188                 && strncmp(name, ut->UT_USER, sizeof(ut->UT_USER)) != 0) {
189                 continue;
190             }
191             if ((pl->login_limit_def == LIMITS_DEF_ALLGROUP)
192                 && !pam_modutil_user_in_group_nam_nam(pamh, ut->UT_USER, pl->login_group)) {
193                 continue;
194             }
195         }
196         if (++count > limit) {
197             break;
198         }
199     }
200     endutent();
201     if (count > limit) {
202         if (name) {
203             pam_syslog(pamh, LOG_WARNING,
204                        "Too many logins (max %d) for %s", limit, name);
205         } else {
206             pam_syslog(pamh, LOG_WARNING, "Too many system logins (max %d)", limit);
207         }
208         return LOGIN_ERR;
209     }
210     return 0;
211 }
212
213 static int init_limits(struct pam_limit_s *pl)
214 {
215     int i;
216     int retval = PAM_SUCCESS;
217
218     D(("called."));
219
220     for(i = 0; i < RLIM_NLIMITS; i++) {
221         int r = getrlimit(i, &pl->limits[i].limit);
222         if (r == -1) {
223             pl->limits[i].supported = 0;
224             if (errno != EINVAL) {
225                 retval = !PAM_SUCCESS;
226             }
227         } else {
228             pl->limits[i].supported = 1;
229             pl->limits[i].src_soft = LIMITS_DEF_NONE;
230             pl->limits[i].src_hard = LIMITS_DEF_NONE;
231         }
232     }
233
234     errno = 0;
235     pl->priority = getpriority (PRIO_PROCESS, 0);
236     if (pl->priority == -1 && errno != 0)
237       retval = !PAM_SUCCESS;
238     pl->login_limit = -2;
239     pl->login_limit_def = LIMITS_DEF_NONE;
240
241     return retval;
242 }
243
244 static void
245 process_limit (const pam_handle_t *pamh, int source, const char *lim_type,
246                const char *lim_item, const char *lim_value,
247                int ctrl, struct pam_limit_s *pl)
248 {
249     int limit_item;
250     int limit_type = 0;
251     int int_value = 0;
252     rlim_t rlimit_value = 0;
253     char *endptr;
254     const char *value_orig = lim_value;
255
256     if (ctrl & PAM_DEBUG_ARG)
257          pam_syslog(pamh, LOG_DEBUG, "%s: processing %s %s %s for %s",
258                     __FUNCTION__, lim_type, lim_item, lim_value,
259                     limits_def_names[source]);
260
261     if (strcmp(lim_item, "cpu") == 0)
262         limit_item = RLIMIT_CPU;
263     else if (strcmp(lim_item, "fsize") == 0)
264         limit_item = RLIMIT_FSIZE;
265     else if (strcmp(lim_item, "data") == 0)
266         limit_item = RLIMIT_DATA;
267     else if (strcmp(lim_item, "stack") == 0)
268         limit_item = RLIMIT_STACK;
269     else if (strcmp(lim_item, "core") == 0)
270         limit_item = RLIMIT_CORE;
271     else if (strcmp(lim_item, "rss") == 0)
272         limit_item = RLIMIT_RSS;
273     else if (strcmp(lim_item, "nproc") == 0)
274         limit_item = RLIMIT_NPROC;
275     else if (strcmp(lim_item, "nofile") == 0)
276         limit_item = RLIMIT_NOFILE;
277     else if (strcmp(lim_item, "memlock") == 0)
278         limit_item = RLIMIT_MEMLOCK;
279     else if (strcmp(lim_item, "as") == 0)
280         limit_item = RLIMIT_AS;
281 #ifdef RLIMIT_LOCKS
282     else if (strcmp(lim_item, "locks") == 0)
283         limit_item = RLIMIT_LOCKS;
284 #endif
285 #ifdef RLIMIT_SIGPENDING
286     else if (strcmp(lim_item, "sigpending") == 0)
287         limit_item = RLIMIT_SIGPENDING;
288 #endif
289 #ifdef RLIMIT_MSGQUEUE
290     else if (strcmp(lim_item, "msgqueue") == 0)
291         limit_item = RLIMIT_MSGQUEUE;
292 #endif
293 #ifdef RLIMIT_NICE
294     else if (strcmp(lim_item, "nice") == 0)
295         limit_item = RLIMIT_NICE;
296 #endif
297 #ifdef RLIMIT_RTPRIO
298     else if (strcmp(lim_item, "rtprio") == 0)
299         limit_item = RLIMIT_RTPRIO;
300 #endif
301     else if (strcmp(lim_item, "maxlogins") == 0) {
302         limit_item = LIMIT_LOGIN;
303         pl->flag_numsyslogins = 0;
304     } else if (strcmp(lim_item, "maxsyslogins") == 0) {
305         limit_item = LIMIT_NUMSYSLOGINS;
306         pl->flag_numsyslogins = 1;
307     } else if (strcmp(lim_item, "priority") == 0) {
308         limit_item = LIMIT_PRI;
309     } else {
310         pam_syslog(pamh, LOG_DEBUG, "unknown limit item '%s'", lim_item);
311         return;
312     }
313
314     if (strcmp(lim_type,"soft")==0)
315         limit_type=LIMIT_SOFT;
316     else if (strcmp(lim_type, "hard")==0)
317         limit_type=LIMIT_HARD;
318     else if (strcmp(lim_type,"-")==0)
319         limit_type=LIMIT_SOFT | LIMIT_HARD;
320     else if (limit_item != LIMIT_LOGIN && limit_item != LIMIT_NUMSYSLOGINS) {
321         pam_syslog(pamh, LOG_DEBUG, "unknown limit type '%s'", lim_type);
322         return;
323     }
324         if (limit_item != LIMIT_PRI
325 #ifdef RLIMIT_NICE
326             && limit_item != RLIMIT_NICE
327 #endif
328             && (strcmp(lim_value, "-1") == 0
329                 || strcmp(lim_value, "-") == 0 || strcmp(lim_value, "unlimited") == 0
330                 || strcmp(lim_value, "infinity") == 0)) {
331                 int_value = -1;
332                 rlimit_value = RLIM_INFINITY;
333         } else if (limit_item == LIMIT_PRI || limit_item == LIMIT_LOGIN ||
334 #ifdef RLIMIT_NICE
335                 limit_item == RLIMIT_NICE ||
336 #endif
337                 limit_item == LIMIT_NUMSYSLOGINS) {
338                 long temp;
339                 temp = strtol (lim_value, &endptr, 10);
340                 temp = temp < INT_MAX ? temp : INT_MAX;
341                 int_value = temp > INT_MIN ? temp : INT_MIN;
342                 if (int_value == 0 && value_orig == endptr) {
343                         pam_syslog(pamh, LOG_DEBUG,
344                                    "wrong limit value '%s' for limit type '%s'",
345                                    lim_value, lim_type);
346             return;
347                 }
348         } else {
349 #ifdef __USE_FILE_OFFSET64
350                 rlimit_value = strtoull (lim_value, &endptr, 10);
351 #else
352                 rlimit_value = strtoul (lim_value, &endptr, 10);
353 #endif
354                 if (rlimit_value == 0 && value_orig == endptr) {
355                         pam_syslog(pamh, LOG_DEBUG,
356                                    "wrong limit value '%s' for limit type '%s'",
357                                    lim_value, lim_type);
358                         return;
359                 }
360         }
361
362     /* one more special case when limiting logins */
363     if ((source == LIMITS_DEF_ALL || source == LIMITS_DEF_ALLGROUP)
364                 && (limit_item != LIMIT_LOGIN)) {
365         if (ctrl & PAM_DEBUG_ARG)
366             pam_syslog(pamh, LOG_DEBUG,
367                        "'%%' domain valid for maxlogins type only");
368         return;
369     }
370
371     switch(limit_item) {
372         case RLIMIT_CPU:
373          if (rlimit_value != RLIM_INFINITY)
374             rlimit_value *= 60;
375          break;
376         case RLIMIT_FSIZE:
377         case RLIMIT_DATA:
378         case RLIMIT_STACK:
379         case RLIMIT_CORE:
380         case RLIMIT_RSS:
381         case RLIMIT_MEMLOCK:
382         case RLIMIT_AS:
383          if (rlimit_value != RLIM_INFINITY)
384             rlimit_value *= 1024;
385          break;
386 #ifdef RLIMIT_NICE
387         case RLIMIT_NICE:
388          if (int_value > 19)
389             int_value = 19;
390          rlimit_value = 19 - int_value;
391 #endif
392          break;
393     }
394
395     if ( (limit_item != LIMIT_LOGIN)
396          && (limit_item != LIMIT_NUMSYSLOGINS)
397          && (limit_item != LIMIT_PRI) ) {
398         if (limit_type & LIMIT_SOFT) {
399             if (pl->limits[limit_item].src_soft < source) {
400                 return;
401             } else {
402                 pl->limits[limit_item].limit.rlim_cur = rlimit_value;
403                 pl->limits[limit_item].src_soft = source;
404             }
405         }
406         if (limit_type & LIMIT_HARD) {
407             if (pl->limits[limit_item].src_hard < source) {
408                 return;
409             } else {
410                 pl->limits[limit_item].limit.rlim_max = rlimit_value;
411                 pl->limits[limit_item].src_hard = source;
412             }
413         }
414     } else {
415         /* recent kernels support negative priority limits (=raise priority) */
416
417         if (limit_item == LIMIT_PRI) {
418                 pl->priority = int_value;
419         } else {
420                 if (pl->login_limit_def < source) {
421                     return;
422                 } else {
423                     pl->login_limit = int_value;
424                     pl->login_limit_def = source;
425                 }
426         }
427     }
428     return;
429 }
430
431 static int parse_config_file(pam_handle_t *pamh, const char *uname, int ctrl,
432                              struct pam_limit_s *pl)
433 {
434     FILE *fil;
435     char buf[LINE_LENGTH];
436
437 #define CONF_FILE (pl->conf_file[0])?pl->conf_file:LIMITS_FILE
438     /* check for the LIMITS_FILE */
439     if (ctrl & PAM_DEBUG_ARG)
440         pam_syslog(pamh, LOG_DEBUG, "reading settings from '%s'", CONF_FILE);
441     fil = fopen(CONF_FILE, "r");
442     if (fil == NULL) {
443         pam_syslog (pamh, LOG_WARNING,
444                     "cannot read settings from %s: %m", CONF_FILE);
445         return PAM_SERVICE_ERR;
446     }
447 #undef CONF_FILE
448
449     /* init things */
450     memset(buf, 0, sizeof(buf));
451     /* start the show */
452     while (fgets(buf, LINE_LENGTH, fil) != NULL) {
453         char domain[LINE_LENGTH];
454         char ltype[LINE_LENGTH];
455         char item[LINE_LENGTH];
456         char value[LINE_LENGTH];
457         int i;
458         size_t j;
459         char *tptr;
460
461         tptr = buf;
462         /* skip the leading white space */
463         while (*tptr && isspace(*tptr))
464             tptr++;
465         strncpy(buf, tptr, sizeof(buf)-1);
466         buf[sizeof(buf)-1] = '\0';
467
468         /* Rip off the comments */
469         tptr = strchr(buf,'#');
470         if (tptr)
471             *tptr = '\0';
472         /* Rip off the newline char */
473         tptr = strchr(buf,'\n');
474         if (tptr)
475             *tptr = '\0';
476         /* Anything left ? */
477         if (!strlen(buf)) {
478             memset(buf, 0, sizeof(buf));
479             continue;
480         }
481
482         memset(domain, 0, sizeof(domain));
483         memset(ltype, 0, sizeof(ltype));
484         memset(item, 0, sizeof(item));
485         memset(value, 0, sizeof(value));
486
487         i = sscanf(buf,"%s%s%s%s", domain, ltype, item, value);
488         D(("scanned line[%d]: domain[%s], ltype[%s], item[%s], value[%s]",
489            i, domain, ltype, item, value));
490
491         for(j=0; j < strlen(ltype); j++)
492             ltype[j]=tolower(ltype[j]);
493         for(j=0; j < strlen(item); j++)
494             item[j]=tolower(item[j]);
495         for(j=0; j < strlen(value); j++)
496             value[j]=tolower(value[j]);
497
498         if (i == 4) { /* a complete line */
499             if (strcmp(uname, domain) == 0) /* this user have a limit */
500                 process_limit(pamh, LIMITS_DEF_USER, ltype, item, value, ctrl, pl);
501             else if (domain[0]=='@') {
502                     if (ctrl & PAM_DEBUG_ARG) {
503                         pam_syslog(pamh, LOG_DEBUG,
504                                    "checking if %s is in group %s",
505                                    uname, domain + 1);
506                     }
507                 if (pam_modutil_user_in_group_nam_nam(pamh, uname, domain+1))
508                     process_limit(pamh, LIMITS_DEF_GROUP, ltype, item, value, ctrl,
509                                   pl);
510             } else if (domain[0]=='%') {
511                     if (ctrl & PAM_DEBUG_ARG) {
512                         pam_syslog(pamh, LOG_DEBUG,
513                                    "checking if %s is in group %s",
514                                    uname, domain + 1);
515                     }
516                 if (strcmp(domain,"%") == 0)
517                     process_limit(pamh, LIMITS_DEF_ALL, ltype, item, value, ctrl,
518                                   pl);
519                 else if (pam_modutil_user_in_group_nam_nam(pamh, uname, domain+1)) {
520                     strcpy(pl->login_group, domain+1);
521                     process_limit(pamh, LIMITS_DEF_ALLGROUP, ltype, item, value, ctrl,
522                                   pl);
523                 }
524             } else if (strcmp(domain, "*") == 0)
525                 process_limit(pamh, LIMITS_DEF_DEFAULT, ltype, item, value, ctrl,
526                               pl);
527         } else if (i == 2 && ltype[0] == '-') { /* Probably a no-limit line */
528             if (strcmp(uname, domain) == 0) {
529                 if (ctrl & PAM_DEBUG_ARG) {
530                     pam_syslog(pamh, LOG_DEBUG, "no limits for '%s'", uname);
531                 }
532                 fclose(fil);
533                 return PAM_IGNORE;
534             } else if (domain[0] == '@' && pam_modutil_user_in_group_nam_nam(pamh, uname, domain+1)) {
535                 if (ctrl & PAM_DEBUG_ARG) {
536                     pam_syslog(pamh, LOG_DEBUG,
537                                "no limits for '%s' in group '%s'",
538                                uname, domain+1);
539                 }
540                 fclose(fil);
541                 return PAM_IGNORE;
542             }
543         } else {
544             pam_syslog(pamh, LOG_WARNING, "invalid line '%s' - skipped", buf);
545         }
546     }
547     fclose(fil);
548     return PAM_SUCCESS;
549 }
550
551 static int setup_limits(pam_handle_t *pamh,
552                         const char *uname, uid_t uid, int ctrl,
553                         struct pam_limit_s *pl)
554 {
555     int i;
556     int status;
557     int retval = LIMITED_OK;
558
559     for (i=0, status=LIMITED_OK; i<RLIM_NLIMITS; i++) {
560         if (!pl->limits[i].supported) {
561             /* skip it if its not known to the system */
562             continue;
563         }
564         if (pl->limits[i].src_soft == LIMITS_DEF_NONE &&
565             pl->limits[i].src_hard == LIMITS_DEF_NONE) {
566             /* skip it if its not initialized */
567             continue;
568         }
569         if (pl->limits[i].limit.rlim_cur > pl->limits[i].limit.rlim_max)
570             pl->limits[i].limit.rlim_cur = pl->limits[i].limit.rlim_max;
571         status |= setrlimit(i, &pl->limits[i].limit);
572     }
573
574     if (status) {
575         retval = LIMIT_ERR;
576     }
577
578     status = setpriority(PRIO_PROCESS, 0, pl->priority);
579     if (status != 0) {
580         retval = LIMIT_ERR;
581     }
582
583     if (uid == 0) {
584         D(("skip login limit check for uid=0"));
585     } else if (pl->login_limit > 0) {
586         if (check_logins(pamh, uname, pl->login_limit, ctrl, pl) == LOGIN_ERR) {
587             retval |= LOGIN_ERR;
588         }
589     } else if (pl->login_limit == 0) {
590         retval |= LOGIN_ERR;
591     }
592
593     return retval;
594 }
595
596 /* now the session stuff */
597 PAM_EXTERN int
598 pam_sm_open_session (pam_handle_t *pamh, int flags UNUSED,
599                      int argc, const char **argv)
600 {
601     int retval;
602     char *user_name;
603     struct passwd *pwd;
604     int ctrl;
605     struct pam_limit_s pl;
606
607     D(("called."));
608
609     memset(&pl, 0, sizeof(pl));
610
611     ctrl = _pam_parse(pamh, argc, argv, &pl);
612     retval = pam_get_item( pamh, PAM_USER, (void*) &user_name );
613     if ( user_name == NULL || retval != PAM_SUCCESS ) {
614         pam_syslog(pamh, LOG_CRIT, "open_session - error recovering username");
615         return PAM_SESSION_ERR;
616      }
617
618     pwd = getpwnam(user_name);
619     if (!pwd) {
620         if (ctrl & PAM_DEBUG_ARG)
621             pam_syslog(pamh, LOG_WARNING,
622                        "open_session username '%s' does not exist", user_name);
623         return PAM_USER_UNKNOWN;
624     }
625
626     retval = init_limits(&pl);
627     if (retval != PAM_SUCCESS) {
628         pam_syslog(pamh, LOG_WARNING, "cannot initialize");
629         return PAM_ABORT;
630     }
631
632     retval = parse_config_file(pamh, pwd->pw_name, ctrl, &pl);
633     if (retval == PAM_IGNORE) {
634         D(("the configuration file has an applicable '<domain> -' entry"));
635         return PAM_SUCCESS;
636     }
637     if (retval != PAM_SUCCESS) {
638         pam_syslog(pamh, LOG_WARNING, "error parsing the configuration file");
639         return retval;
640     }
641
642     if (ctrl & PAM_DO_SETREUID) {
643         setreuid(pwd->pw_uid, -1);
644     }
645     retval = setup_limits(pamh, pwd->pw_name, pwd->pw_uid, ctrl, &pl);
646     if (retval & LOGIN_ERR)
647         pam_error(pamh, _("Too many logins for '%s'."), pwd->pw_name);
648     if (retval != LIMITED_OK) {
649         return PAM_PERM_DENIED;
650     }
651
652     return PAM_SUCCESS;
653 }
654
655 PAM_EXTERN int
656 pam_sm_close_session (pam_handle_t *pamh UNUSED, int flags UNUSED,
657                       int argc UNUSED, const char **argv UNUSED)
658 {
659      /* nothing to do */
660      return PAM_SUCCESS;
661 }
662
663 #ifdef PAM_STATIC
664
665 /* static module data */
666
667 struct pam_module _pam_limits_modstruct = {
668      "pam_limits",
669      NULL,
670      NULL,
671      NULL,
672      pam_sm_open_session,
673      pam_sm_close_session,
674      NULL
675 };
676 #endif
677
678 /*
679  * Copyright (c) Cristian Gafton, 1996-1997, <gafton@redhat.com>
680  *                                              All rights reserved.
681  *
682  * Redistribution and use in source and binary forms, with or without
683  * modification, are permitted provided that the following conditions
684  * are met:
685  * 1. Redistributions of source code must retain the above copyright
686  *    notice, and the entire permission notice in its entirety,
687  *    including the disclaimer of warranties.
688  * 2. Redistributions in binary form must reproduce the above copyright
689  *    notice, this list of conditions and the following disclaimer in the
690  *    documentation and/or other materials provided with the distribution.
691  * 3. The name of the author may not be used to endorse or promote
692  *    products derived from this software without specific prior
693  *    written permission.
694  *
695  * ALTERNATIVELY, this product may be distributed under the terms of
696  * the GNU Public License, in which case the provisions of the GPL are
697  * required INSTEAD OF the above restrictions.  (This clause is
698  * necessary due to a potential bad interaction between the GPL and
699  * the restrictions contained in a BSD-style copyright.)
700  *
701  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
702  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
703  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
704  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
705  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
706  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
707  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
708  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
709  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
710  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
711  * OF THE POSSIBILITY OF SUCH DAMAGE.
712  */