Whamcloud - gitweb
LU-17744 ldiskfs: mballoc stats fixes
[fs/lustre-release.git] / lustre / utils / gss / lsupport.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 021110-1307, USA
20  *
21  * GPL HEADER END
22  */
23 /*
24  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
25  * Use is subject to license terms.
26  *
27  * Copyright (c) 2014, Intel Corporation.
28  */
29 /*
30  * This file is part of Lustre, http://www.lustre.org/
31  *
32  * lustre/utils/gss/lsupport.h
33  */
34
35 #ifndef __LSUPPORT_H__
36 #define __LSUPPORT_H__
37
38 #include <assert.h>
39 #include <unistd.h>
40 #include <stdbool.h>
41 #include <stdint.h>
42 #include <errno.h>
43 #include <stdio.h>
44
45 #include <libcfs/util/list.h>
46 #include <linux/lnet/lnet-types.h>
47 #include <linux/lnet/nidstr.h>
48 #include <uapi/linux/lustre/lgss.h>
49
50 #include <krb5.h>
51
52 #define GSSD_CLI        (0)
53 #define GSSD_SVC        (1)
54
55 void gssd_init_unique(int type);
56 void gssd_exit_unique(int type);
57
58 /*
59  * copied from lustre source
60  */
61
62 #define LUSTRE_GSS_SVC_MGS      0
63 #define LUSTRE_GSS_SVC_MDS      1
64 #define LUSTRE_GSS_SVC_OSS      2
65
66 #define LUSTRE_GSS_SVC_MASK     0x0000FFFF
67 #define LUSTRE_GSS_MECH_MASK    0xFFFF0000
68 #define LUSTRE_GSS_MECH_SHIFT   16
69
70 extern const char * lustre_svc_name[];
71 extern char *krb5_this_realm;
72
73 enum lgss_mech {
74         LGSS_MECH_KRB5  = 0,
75         LGSS_MECH_NULL  = 1,
76         LGSS_MECH_SK    = 2,
77 };
78
79 enum {
80         /* sec part flags */
81         LGSS_ROOT_CRED_ROOT     = 0x01,
82         LGSS_ROOT_CRED_MDT      = 0x02,
83         LGSS_ROOT_CRED_OST      = 0x04,
84         /* service type flags */
85         LGSS_SVC_NULL           = 0x10,
86         LGSS_SVC_AUTH           = 0x20,
87         LGSS_SVC_INTG           = 0x40,
88         LGSS_SVC_PRIV           = 0x80,
89 };
90
91 struct lgssd_upcall_data {
92         uint32_t        seq;
93         uint32_t        uid;
94         uint32_t        gid;
95         uint32_t        svc;
96         uint64_t        nid;
97         char            obd[64];
98 };
99
100 #define GSSD_INTERFACE_VERSION          GSSD_INTERFACE_VERSION_V2
101 #define GSSD_INTERFACE_VERSION_V2       (2)
102 #define GSSD_INTERFACE_VERSION_V1       (1)
103
104 #define GSSD_DEFAULT_GETHOSTNAME_EX     "/etc/lustre/nid2hostname"
105 #define MAPPING_DATABASE_FILE           "/etc/lustre/idmap.conf"
106
107 int getcanonname(const char *host, char *buf, int buflen);
108 int lnet_nid2hostname(lnet_nid_t nid, char *buf, int buflen);
109 void cleanup_mapping(void);
110 uid_t parse_uid(char *uidstr);
111 void load_mapping(void);
112 int mapping_empty(void);
113 int lookup_mapping(char *princ, lnet_nid_t nid, uid_t *uid);
114 int gss_get_realm(char *realm);
115
116 /*
117  * gss_buffer_write() - write some buffer to stream
118  */
119 static inline int gss_buffer_write_file(FILE *f, void *value, size_t length)
120 {
121         int rc = 0;
122
123         /* write size of data */
124         if (fwrite(&length, sizeof(__u32), 1, f) != 1) {
125                 rc = -errno;
126                 goto out;
127         }
128
129         if (!length || !value)
130                 goto out;
131
132         /* write data itself */
133         if (fwrite(value, length, 1, f) != 1) {
134                 rc = -errno;
135                 goto out;
136         }
137
138 out:
139         return rc;
140 }
141
142 #endif /* __LSUPPORT_H__ */