1 // Copyright 2018 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef OSLOGIN_COMPAT_H
16 #define OSLOGIN_COMPAT_H
17 
18 #if defined(__FreeBSD__) || defined(__DragonFly__)
19 
20 #include <nsswitch.h>
21 
22 #define DECLARE_NSS_METHOD_TABLE(name, ...)                     \
23     static ns_mtab name[] = {__VA_ARGS__};
24 
25 #define NSS_METHOD(method, func) {                              \
26     .database = NSDB_PASSWD,                                    \
27     .name = #method,                                            \
28     .method = __nss_compat_ ## method,                          \
29     .mdata = (void*)func                                        \
30 }
31 
32 #define NSS_REGISTER_METHODS(methods) ns_mtab *                 \
33 nss_module_register (const char *name, unsigned int *size,      \
34                         nss_module_unregister_fn *unregister)   \
35 {                                                               \
36     *size = sizeof (methods) / sizeof (methods[0]);             \
37     *unregister = NULL;                                         \
38     return (methods);                                           \
39 }
40 
41 #define OSLOGIN_PASSWD_CACHE_PATH "/usr/local/etc/oslogin_passwd.cache"
42 #define OSLOGIN_GROUP_CACHE_PATH "/usr/local/etc/oslogin_group.cache"
43 #define PASSWD_PATH "/usr/local/etc/passwd"
44 
45 #define K_DEFAULT_PFILE_PATH "/usr/local/etc/oslogin_passwd.cache"
46 #define K_DEFAULT_BACKUP_PFILE_PATH "/usr/local/etc/oslogin_passwd.cache.bak"
47 #define K_DEFAULT_GFILE_PATH "/usr/local/etc/oslogin_group.cache"
48 #define K_DEFAULT_BACKUP_GFILE_PATH "/usr/local/etc/oslogin_group.cache.bak"
49 
50 #define PAM_SYSLOG(pamh, ...) syslog(__VA_ARGS__)
51 #define DEFAULT_SHELL "/bin/sh"
52 
53 #else /* __FreeBSD__ */
54 
55 #include <security/pam_ext.h>
56 
57 #define OSLOGIN_PASSWD_CACHE_PATH "/etc/oslogin_passwd.cache"
58 #define OSLOGIN_GROUP_CACHE_PATH "/etc/oslogin_group.cache"
59 #define PASSWD_PATH "/etc/passwd"
60 
61 #define K_DEFAULT_PFILE_PATH "/etc/oslogin_passwd.cache"
62 #define K_DEFAULT_BACKUP_PFILE_PATH "/etc/oslogin_passwd.cache.bak"
63 #define K_DEFAULT_GFILE_PATH "/etc/oslogin_group.cache"
64 #define K_DEFAULT_BACKUP_GFILE_PATH "/etc/oslogin_group.cache.bak"
65 
66 #define PAM_SYSLOG pam_syslog
67 #define DEFAULT_SHELL "/bin/bash"
68 
69 #define DECLARE_NSS_METHOD_TABLE(name, ...)
70 #define NSS_METHOD_PROTOTYPE(m)
71 #define NSS_REGISTER_METHODS(methods)
72 
73 #endif /* __FreeBSD__ */
74 
75 #endif /* OSLOGIN_COMPAT_H */
76