123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- #ifdef HAVE_CONFIG_H
- #include <config.h>
- #endif
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/time.h>
- #include <sys/resource.h>
- #include <security/pam_appl.h>
- static int
- fake_conv (int num_msg, const struct pam_message **msgm UNUSED,
- struct pam_response **response, void *appdata_ptr UNUSED)
- {
- struct pam_response *reply;
- int count;
-
- if (num_msg <= 0)
- return PAM_CONV_ERR;
-
- reply = calloc (num_msg, sizeof (struct pam_response));
- if (reply == NULL)
- return PAM_CONV_ERR;
-
- for (count = 0; count < num_msg; ++count)
- {
- reply[count].resp_retcode = 0;
- reply[count].resp = strdup ("!!");
- }
-
- *response = reply;
- return PAM_SUCCESS;
- }
- static struct pam_conv conv = {
- fake_conv,
- NULL
- };
- int
- main(int argc, char *argv[])
- {
- pam_handle_t *pamh = NULL;
- const char *user="tstpamlimits";
- int retval;
- int debug = 0;
- if (argc > 1 && strcmp (argv[1], "-d") == 0)
- debug = 1;
- #ifdef RLIMIT_NICE
- retval = pam_start("tst-pam_limits1", user, &conv, &pamh);
- if (retval != PAM_SUCCESS)
- {
- if (debug)
- fprintf (stderr, "pam_limits1: pam_start returned %d\n", retval);
- return 1;
- }
- retval = pam_set_item (pamh, PAM_TTY, "/dev/tty1");
- if (retval != PAM_SUCCESS)
- {
- if (debug)
- fprintf (stderr,
- "pam_limits1: pam_set_item(PAM_TTY) returned %d\n",
- retval);
- return 1;
- }
- retval = pam_open_session (pamh, 0);
- if (retval != PAM_SUCCESS)
- {
- if (debug)
- fprintf (stderr, "pam_limits1: pam_open_session returned %d\n",
- retval);
- return 1;
- }
- struct rlimit rlim;
- getrlimit (RLIMIT_NICE, &rlim);
- if (rlim.rlim_cur != 1 && rlim.rlim_max != 40)
- {
- if (debug)
- fprintf (stderr, "pam_limits1: getrlimit failed, soft=%u, hard=%u\n",
- (unsigned int) rlim.rlim_cur, (unsigned int) rlim.rlim_max);
- return 1;
- }
- retval = pam_end (pamh,retval);
- if (retval != PAM_SUCCESS)
- {
- if (debug)
- fprintf (stderr, "pam_limits1: pam_end returned %d\n", retval);
- return 1;
- }
- return 0;
- #else
- if (debug)
- fprintf (stderr, "pam_limits1: RLIMIT_NICE does not exist)\n");
- return 77;
- #endif
- }
|