1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Modifications for Lustre
5 * Copyright 2007, Cluster File Systems, Inc.
7 * Author: Eric Mei <ericm@clusterfs.com>
11 Copyright (c) 2004 The Regents of the University of Michigan.
14 Redistribution and use in source and binary forms, with or without
15 modification, are permitted provided that the following conditions
18 1. Redistributions of source code must retain the above copyright
19 notice, this list of conditions and the following disclaimer.
20 2. Redistributions in binary form must reproduce the above copyright
21 notice, this list of conditions and the following disclaimer in the
22 documentation and/or other materials provided with the distribution.
23 3. Neither the name of the University nor the names of its
24 contributors may be used to endorse or promote products derived
25 from this software without specific prior written permission.
27 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
28 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
29 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
34 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 #include <gssapi/gssapi.h>
47 #define likely(exp) (exp)
51 #define unlikely(exp) (exp)
54 #define LGSS_SVC_MDS_STR "lustre_mds"
55 #define LGSS_SVC_OST_STR "lustre_oss"
56 #define LGSS_SVC_MGS_STR "lustre_mgs"
57 #define LGSS_USR_ROOT_STR "lustre_root"
66 extern const char *lgss_svc_str[LGSS_SVC_MAX];
68 /****************************************
69 * inter-process locking *
70 ****************************************/
77 int lgss_mutex_lock(lgss_mutex_id_t mid);
78 int lgss_mutex_unlock(lgss_mutex_id_t mid);
80 /****************************************
82 ****************************************/
86 * LL_ERR: critical error messages
87 * LL_WARN: warning (default)
88 * LL_INFO: important infomation
90 * LL_TRACE: excessive tracing messages
101 extern loglevel_t g_log_level;
103 void __logmsg(loglevel_t level, const char *func, const char *format, ...);
104 void __logmsg_gss(loglevel_t level, const char *func, const gss_OID mech,
105 uint32_t major, uint32_t minor, const char *format, ...);
107 #define logmsg(loglevel, format, args...) \
109 if (unlikely(loglevel <= g_log_level)) \
110 __logmsg(loglevel, __FUNCTION__, format, ##args); \
113 #define logmsg_gss(loglevel, mech, major, minor, format, args...) \
115 if (unlikely(loglevel <= g_log_level)) \
116 __logmsg_gss(loglevel, __FUNCTION__, mech, \
117 major, minor, format, ##args); \
120 #define lassert(exp) \
122 if ((int)(exp) == 0) { \
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, "")
137 /****************************************
139 ****************************************/
141 extern gss_OID_desc krb5oid;
142 extern gss_OID_desc spkm3oid;
148 /****************************************
149 * client credentials *
150 ****************************************/
154 struct lgss_mech_type {
156 lgss_mech_t lmt_mech_n;
158 int (*lmt_init)(void);
159 void (*lmt_fini)(void);
160 int (*lmt_prepare_cred)(struct lgss_cred *cred);
161 void (*lmt_release_cred)(struct lgss_cred *cred);
162 int (*lmt_using_cred)(struct lgss_cred *cred);
167 unsigned int lc_fl_root:1,
172 struct lgss_mech_type *lc_mech;
176 struct lgss_mech_type *lgss_name2mech(const char *mech_name);
177 int lgss_mech_initialize(struct lgss_mech_type *mech);
178 void lgss_mech_finalize(struct lgss_mech_type *mech);
180 struct lgss_cred * lgss_create_cred(struct lgss_mech_type *mech);
181 void lgss_destroy_cred(struct lgss_cred *cred);
182 int lgss_prepare_cred(struct lgss_cred *cred);
183 void lgss_release_cred(struct lgss_cred *cred);
184 int lgss_using_cred(struct lgss_cred *cred);
186 int lgss_get_service_str(char **string, uint32_t lsvc, uint64_t tgt_nid);
189 extern gss_OID_desc krb5oid;
190 extern gss_OID_desc spkm3oid;
193 int gss_OID_equal(gss_OID_desc *oid1, gss_OID_desc *oid2)
195 return (oid1->length == oid2->length &&
196 memcmp(oid1->elements, oid2->elements, oid1->length) == 0);
200 #define g_OID_equal(o1,o2) gss_OID_equal((o1), (o2))
203 #endif /* LGSS_UTILS_H */