1 /* GNU Mailutils -- a suite of utilities for electronic mail 2 Copyright (C) 2002-2021 Free Software Foundation, Inc. 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 3 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General 15 Public License along with this library. If not, see 16 <http://www.gnu.org/licenses/>. */ 17 18 #ifndef _MAILUTILS_MU_AUTH_H 19 #define _MAILUTILS_MU_AUTH_H 20 21 #include <mailutils/types.h> 22 #include <mailutils/debug.h> 23 #include <mailutils/cli.h> 24 25 #define MU_AUTH_NAME "name" 26 #define MU_AUTH_PASSWD "passwd" 27 #define MU_AUTH_UID "uid" 28 #define MU_AUTH_GID "gid" 29 #define MU_AUTH_GECOS "gecos" 30 #define MU_AUTH_DIR "dir" 31 #define MU_AUTH_SHELL "shell" 32 #define MU_AUTH_MAILBOX "mailbox" 33 #define MU_AUTH_QUOTA "quota" 34 35 struct mu_auth_data 36 { 37 /* Where this info comes from: */ 38 const char *source; 39 40 /* These are from struct passwd */ 41 char *name; /* user name */ 42 char *passwd; /* user password */ 43 uid_t uid; /* user id */ 44 gid_t gid; /* group id */ 45 char *gecos; /* real name */ 46 char *dir; /* home directory */ 47 char *shell; /* shell program */ 48 49 /* Additional fields */ 50 char *mailbox; 51 mu_off_t quota; 52 53 int flags; 54 55 int change_uid; 56 }; 57 58 #define MU_AF_QUOTA 0x1 59 #define MU_HAS_QUOTA(a) ((a)->flags & MU_AF_QUOTA) 60 61 typedef int (*mu_auth_fp) (struct mu_auth_data **data, 62 const void *key, 63 void *func_data, 64 void *call_data); 65 66 enum mu_auth_mode 67 { 68 mu_auth_authenticate, 69 mu_auth_getpwnam, 70 mu_auth_getpwuid 71 }; 72 73 #define MU_AUTH_MODE_COUNT 3 74 75 struct mu_auth_module 76 { 77 char *name; 78 mu_auth_fp handler[MU_AUTH_MODE_COUNT]; 79 void *data[MU_AUTH_MODE_COUNT]; 80 81 struct mu_option *opt; 82 struct mu_cfg_param *cfg; 83 mu_cfg_section_fp parser; 84 mu_cli_capa_commit_fp commit; 85 }; 86 87 enum mu_auth_key_type 88 { 89 mu_auth_key_name = mu_auth_getpwnam, 90 mu_auth_key_uid = mu_auth_getpwuid 91 }; 92 93 void mu_auth_begin_setup (void); 94 void mu_auth_finish_setup (void); 95 void mu_auth_extend_settings (mu_list_t opts, mu_list_t commits); 96 97 int mu_auth_runlist (mu_list_t flist, 98 enum mu_auth_mode mode, 99 const void *key, void *data, 100 struct mu_auth_data **return_data); 101 102 extern int mu_get_auth (struct mu_auth_data **auth, enum mu_auth_key_type type, 103 const void *key); 104 105 extern struct mu_auth_data * 106 mu_get_auth_by_name (const char *username); 107 108 extern struct mu_auth_data * 109 mu_get_auth_by_uid (uid_t uid); 110 111 extern int 112 mu_authenticate (struct mu_auth_data *auth_data, const char *pass); 113 114 extern int mu_auth_nosupport (struct mu_auth_data **return_data, 115 const void *key, 116 void *func_data, 117 void *call_data); 118 119 120 extern void mu_auth_register_module (struct mu_auth_module *mod); 121 122 extern int mu_authorization_add_module (const char *modname); 123 extern void mu_authorization_add_module_list (const char *modlist); 124 extern int mu_authentication_add_module (const char *modname); 125 extern void mu_authentication_add_module_list (const char *modlist); 126 extern void mu_authentication_clear_list (void); 127 extern void mu_authorization_clear_list (void); 128 129 extern int mu_auth_data_alloc (struct mu_auth_data **ptr, 130 const char *name, 131 const char *passwd, 132 uid_t uid, 133 gid_t gid, 134 const char *gecos, 135 const char *dir, 136 const char *shell, 137 const char *mailbox, 138 int change_uid); 139 extern void mu_auth_data_set_quota (struct mu_auth_data *ptr, mu_off_t q); 140 extern void mu_auth_data_free (struct mu_auth_data *ptr); 141 extern void mu_auth_data_destroy (struct mu_auth_data **ptr); 142 143 extern struct mu_auth_module mu_auth_system_module; 144 extern struct mu_auth_module mu_auth_generic_module; 145 extern struct mu_auth_module mu_auth_pam_module; 146 extern struct mu_auth_module mu_auth_sql_module; 147 extern struct mu_auth_module mu_auth_virtual_module; 148 extern struct mu_auth_module mu_auth_radius_module; 149 extern struct mu_auth_module mu_auth_ldap_module; 150 extern struct mu_auth_module mu_auth_gsasl_module; 151 extern struct mu_auth_module mu_auth_tls_module; 152 153 #define MU_AUTH_REGISTER_ALL_MODULES() do {\ 154 mu_auth_register_module (&mu_auth_generic_module); \ 155 mu_auth_register_module (&mu_auth_system_module); \ 156 mu_auth_register_module (&mu_auth_pam_module);\ 157 mu_auth_register_module (&mu_auth_sql_module);\ 158 mu_auth_register_module (&mu_auth_virtual_module);\ 159 mu_auth_register_module (&mu_auth_radius_module);\ 160 mu_auth_register_module (&mu_auth_ldap_module);\ 161 mu_auth_register_module (&mu_auth_gsasl_module);\ 162 mu_auth_register_module (&mu_auth_tls_module);\ 163 } while (0) 164 165 #endif 166