1 /*- 2 * Copyright 2001 Mark R V Murray 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27 #include <sys/cdefs.h> 28 __FBSDID("$FreeBSD$"); 29 30 #include <stddef.h> 31 32 #define PAM_SM_AUTH 33 #define PAM_SM_ACCOUNT 34 #define PAM_SM_SESSION 35 #define PAM_SM_PASSWORD 36 37 #include <security/pam_appl.h> 38 #include <security/pam_modules.h> 39 #include <security/pam_mod_misc.h> 40 41 #define NOBODY "nobody" 42 43 PAM_EXTERN int 44 pam_sm_authenticate(pam_handle_t *pamh, int flags __unused, int argc, const char **argv) 45 { 46 struct options options; 47 int retval; 48 const char *user; 49 50 pam_std_option(&options, NULL, argc, argv); 51 52 PAM_LOG("Options processed"); 53 54 /* We always need to know who the user is */ 55 user = NULL; 56 retval = pam_get_user(pamh, &user, NULL); 57 if (retval != PAM_SUCCESS) 58 PAM_RETURN(retval); 59 60 PAM_LOG("Got user: %s", user); 61 62 if (user == NULL || *user == '\0') 63 pam_set_item(pamh, PAM_USER, (const void *)NOBODY); 64 user = NULL; 65 66 PAM_RETURN(PAM_SUCCESS); 67 } 68 69 PAM_EXTERN int 70 pam_sm_setcred(pam_handle_t *pamh __unused, int flags __unused, int argc, const char **argv) 71 { 72 struct options options; 73 74 pam_std_option(&options, NULL, argc, argv); 75 76 PAM_LOG("Options processed"); 77 78 PAM_RETURN(PAM_SUCCESS); 79 } 80 81 PAM_EXTERN int 82 pam_sm_acct_mgmt(pam_handle_t *pamh __unused, int flags __unused, int argc ,const char **argv) 83 { 84 struct options options; 85 86 pam_std_option(&options, NULL, argc, argv); 87 88 PAM_LOG("Options processed"); 89 90 PAM_RETURN(PAM_SUCCESS); 91 } 92 93 PAM_EXTERN int 94 pam_sm_chauthtok(pam_handle_t *pamh __unused, int flags __unused, int argc, const char **argv) 95 { 96 struct options options; 97 98 pam_std_option(&options, NULL, argc, argv); 99 100 PAM_LOG("Options processed"); 101 102 PAM_RETURN(PAM_SUCCESS); 103 } 104 105 PAM_EXTERN int 106 pam_sm_open_session(pam_handle_t *pamh __unused, int flags __unused, int argc, const char **argv) 107 { 108 struct options options; 109 110 pam_std_option(&options, NULL, argc, argv); 111 112 PAM_LOG("Options processed"); 113 114 PAM_RETURN(PAM_SUCCESS); 115 } 116 117 PAM_EXTERN int 118 pam_sm_close_session(pam_handle_t *pamh __unused, int flags __unused, int argc, const char **argv) 119 { 120 struct options options; 121 122 pam_std_option(&options, NULL, argc, argv); 123 124 PAM_LOG("Options processed"); 125 126 PAM_RETURN(PAM_SUCCESS); 127 } 128 129 PAM_MODULE_ENTRY("pam_permit"); 130