2 * Modifications for Lustre
4 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
6 * Author: Eric Mei <ericm@clusterfs.com>
10 Copyright (c) 2004 The Regents of the University of Michigan.
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions
17 1. Redistributions of source code must retain the above copyright
18 notice, this list of conditions and the following disclaimer.
19 2. Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
22 3. Neither the name of the University nor the names of its
23 contributors may be used to endorse or promote products derived
24 from this software without specific prior written permission.
26 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
27 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
33 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 #include <gssapi/gssapi.h>
49 #define LGSS_SVC_MGS_STR "lustre_mgs"
50 #define LGSS_SVC_MDS_STR "lustre_mds"
51 #define LGSS_SVC_OSS_STR "lustre_oss"
52 #define LGSS_USR_ROOT_STR "lustre_root"
61 extern const char *lgss_svc_str[LGSS_SVC_MAX];
63 /****************************************
64 * inter-process locking *
65 ****************************************/
72 int lgss_mutex_lock(lgss_mutex_id_t mid);
73 int lgss_mutex_unlock(lgss_mutex_id_t mid);
75 /****************************************
77 ****************************************/
81 * LL_ERR: critical error messages
82 * LL_WARN: warning (default)
83 * LL_INFO: important infomation
85 * LL_TRACE: excessive tracing messages
96 extern loglevel_t g_log_level;
98 void lgss_set_loglevel(loglevel_t level);
100 void __logmsg(loglevel_t level, const char *func, const char *format, ...)
101 __attribute__((format(printf, 3, 4)));
103 void __logmsg_gss(loglevel_t level, const char *func, const gss_OID mech,
104 uint32_t major, uint32_t minor, const char *format, ...)
105 __attribute__((format(printf, 6, 7)));
107 #define logmsg(loglevel, format, args...) \
109 if (loglevel <= g_log_level) \
110 __logmsg(loglevel, __FUNCTION__, format, ##args); \
113 #define logmsg_gss(loglevel, mech, major, minor, format, args...) \
115 if (loglevel <= g_log_level) \
116 __logmsg_gss(loglevel, __FUNCTION__, mech, \
117 major, minor, format, ##args); \
120 #define lassert(exp) \
123 logmsg(LL_ERR, "ASSERTION FAILED: %s", #exp); \
129 * for compatible reason, we're using files (context_xxx.c) from nfs-utils
131 #define printerr(priority, format, args...) \
132 logmsg(priority, format, ##args)
134 #define pgsserr(msg, maj_stat, min_stat, mech) \
135 logmsg_gss(LL_ERR, mech, maj_stat, min_stat, msg)
137 /****************************************
139 ****************************************/
141 extern gss_OID_desc krb5oid;
142 extern gss_OID_desc spkm3oid;
143 extern gss_OID_desc nulloid;
144 extern gss_OID_desc skoid;
146 /****************************************
147 * client credentials *
148 ****************************************/
152 struct lgss_mech_type {
154 enum lgss_mech lmt_mech_n;
156 int (*lmt_init)(void);
157 void (*lmt_fini)(void);
158 int (*lmt_prepare_cred)(struct lgss_cred *cred);
159 void (*lmt_release_cred)(struct lgss_cred *cred);
160 int (*lmt_using_cred)(struct lgss_cred *cred);
161 int (*lmt_validate_cred)(struct lgss_cred *cred,
162 gss_buffer_desc *token,
163 gss_buffer_desc *ctx_token);
168 unsigned int lc_root_flags;
169 uint64_t lc_self_nid;
175 struct lgss_mech_type *lc_mech;
177 gss_buffer_desc lc_mech_token;
180 struct lgss_mech_type *lgss_name2mech(const char *mech_name);
181 int lgss_mech_initialize(struct lgss_mech_type *mech);
182 void lgss_mech_finalize(struct lgss_mech_type *mech);
184 struct lgss_cred * lgss_create_cred(struct lgss_mech_type *mech);
185 void lgss_destroy_cred(struct lgss_cred *cred);
186 int lgss_prepare_cred(struct lgss_cred *cred);
187 void lgss_release_cred(struct lgss_cred *cred);
188 int lgss_using_cred(struct lgss_cred *cred);
189 int lgss_validate_cred(struct lgss_cred *cred, gss_buffer_desc *token,
190 gss_buffer_desc *ctx_token);
192 int lgss_get_service_str(char **string, uint32_t lsvc, uint64_t tgt_nid);
195 int gss_OID_equal(gss_OID_desc *oid1, gss_OID_desc *oid2)
197 return (oid1->length == oid2->length &&
198 memcmp(oid1->elements, oid2->elements, oid1->length) == 0);
202 #define g_OID_equal(o1,o2) gss_OID_equal((o1), (o2))
205 #endif /* LGSS_UTILS_H */