This repository was archived by the owner on Oct 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfnasso.h
More file actions
258 lines (217 loc) · 11.6 KB
/
Copy pathfnasso.h
File metadata and controls
258 lines (217 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
* File: fnasso.h - Library for Single Sign-On during Federated Network Access
* Author: Alejandro Abad Carrascosa <alejandroprimitivo.abad@um.es>
*
* Created on February 19, 2014, 8:09 PM
* Version 1.3 - March 14, 2014
*/
#ifndef FNASSO_H
#define FNASSO_H
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
FNASSO_ERR_NONE = 0,
FNASSO_ERR_EXTERNAL,
FNASSO_ERR_NO_CONTEXT_SUPPLIED,
FNASSO_ERR_NO_ROAMING_REALM,
FNASSO_ERR_NO_CCACHE_NAME,
FNASSO_ERR_NO_MSK,
FNASSO_ERR_CANT_GENERATE_MSK_HASH,
FNASSO_ERR_CANT_GENERATE_BASE64_PASSWORD,
FNASSO_ERR_NO_USERNAME_SUPPLIED,
FNASSO_ERR_BADFORMED_KERBEROS_USERNAME,
FNASSO_ERR_OUTPUT_PTR_NULL,
FNASSO_ERR_USER_DATA_NOT_SET,
FNASSO_ERR_CHLD_EXIT_SIGNAL,
FNASSO_ERR_CHLD_EXIT,
FNASSO_ERR_KADMIN_DATA_NOT_SET,
FNASSO_ERR_KADMIN_REALM_EMPTY,
FNASSO_ERR_KADMIN_SERVER_EMPTY,
FNASSO_ERR_KADMIN_USER_EMPTY
} fnasso_error;
typedef struct fnasso_context_t fnasso_ctx;
/**
* Returns a descriptive string of the library version and compilation date.
* @param v If not null, the integer pointed will store the current library version
* @return The descriptive string of the version and compilation date/time.
*/
char *fnasso_version(int *v);
/**
* Returns a pointer to the string representation of a given fnasso_error value.
* If the error code is undefined, a default "unknown error" string will be pointed as return value.
* Note: Returned pointer is statically defined and it's contents -MUST NOT- be modified.
*
* @param errno The error value.
* @return A pointer to the char array describing the given error.
*/
char *fnasso_strerror(fnasso_error errno);
/**
* Initialization of a kerberos based FNASSO context (fnasso_context).
* Note: The FNASSO context pointed MUST be deallocated using the provided fnasso_free_context() function.
*
* @context Pointer to where the context structure will be allocated. This pointer doesn't need to be allocated previously.
* @return FNASSO_ERR_NONE in case of success, an error value in case of failure.
*/
fnasso_error fnasso_context_init(fnasso_ctx **context);
/**
* Frees all data contained in a FNASSO context.
*
* @param Pointer to where the context structure is allocated.
* @return FNASSO_ERR_NONE in case of success, an error value in case of failure.
*/
fnasso_error fnasso_context_free(fnasso_ctx **context);
/**
* Sets the roaming realm that will be used in order to contact the local KDC and derivate user names. Usually, this realm is configured
* in '/etc/krb5.conf', nevertheless, this configuration won't be reliable in most cases where the user is in roaming.
* A NULL value for default_realm will restore the system's default value (if any).
* Note: Empty strings will return an error.
*
* @param context A pointer to the FNASSO context where the new roaming realm will be set.
* @param roaming_realm The pointer to the -null-ended- char array containing the value of the roaming realm or a NULL pointer to reset to the default value.
* @return FNASSO_ERR_NONE in case of success, an error value in case of failure.
*/
fnasso_error fnasso_context_set_roaming_realm(fnasso_ctx *context, const char* roaming_realm);
/**
* Sets the credentials cache name that will be used to store TGTs. If a NULL value is
* passed, the credential cache file will be the OS default file (ie. "/tmp/krb5cc_1000").
*
* Note: A cache name has the format "METHOD:residual" (ie. "FILE:/tmp/fnasso_cc"). Refer to
* mit.edu for more info about ccaches methods.
*
* @param context A pointer to the FNASSO context where the new ccache name will be set.
* @param ccache_filename The pointer to the -null-ended- where is stored the ccache name where to store the credential cache. If pointer is NULL, the default credential cache name will be used.
* @return FNASSO_ERR_NONE in case of success, an error value in case of failure.
*/
fnasso_error fnasso_context_set_cache_name(fnasso_ctx *context, const char* ccache_name);
//////////////////////////////////////
// User management
//////////////////////////////////////
/**
* Sets a new user in the FNASSO context whose name and password are generated with a deterministic algorithm
* in function of an octet array, usually a MSK (Master Session Key) derived in an EAP negotiation.
*
* @param context A pointer to the FNASSO context where the user will be set.
* @param msk An octet array with the input for the username and password algotimh generator.
* @param key_len The length of given octet array (in bytes).
* @return FNASSO_ERR_NONE in case of success, an error value in case of failure.
*/
fnasso_error fnasso_user_set_with_msk(fnasso_ctx *context, const unsigned char *msk, int key_len);
/**
* Sets the user of a FNASSO context with the name and password specified.
* Note: The function will automatically try to obtain a realm name from the username.
*
* @param context A pointer to the FNASSO context where the user will be set.
* @param username The username for the kerberos user.
* @param password The password for the kerberos user.
* @return FNASSO_ERR_NONE in case of success, an error value in case of failure.
*/
fnasso_error fnasso_user_set(fnasso_ctx *context, const char *username, const char *password);
/**
* Checks if the user stored in a FNASSO context is valid for autenticantion or user administration.
* The isset value will be set to TRUE or FALSE, determining if the context's user is set or not.
* Note: isset MUST be not NULL or an error will be raised.
*
* @param context A pointer to the FNASSO context with the user to be checked.
* @param isset A pointer to an integer that will be set to TRUE if the user is set, or FALSE if user is not set.
* @return FNASSO_ERR_NONE in case of success, an error value in case of failure.
*/
fnasso_error fnasso_user_isset(const fnasso_ctx *context, int *isset);
/**
* Frees all information related to the user in a given FNASSO context.
*
* @param context A pointer to the FNASSO context where the user will be cleared.
* @return FNASSO_ERR_NONE in case of success, an error value in case of failure.
*/
fnasso_error fnasso_user_free(fnasso_ctx *context);
////////////////////////////////////////////////
// Kerberos KDC client functions
////////////////////////////////////////////////
/**
* Performs an authentication against the kerberos KDC (roaming realm's KDC set) using the user in the FNASSO context supplied.
* After a successful authentication, a initial kerberos credentials will be available in the default credentials cache.
* If a previous TGT already exists in cache, it's replaced with the new one.
* If not NULL, the life_time pointer will store the time in seconds the TGT is valid.
*
* @param context A pointer to the FNASSO context where is set the user that will be authenticated against the KDC.
* @param life_time A pointer to an integer that will store the TGT's lifetime if the operation is successufully completed. This param can be NULL.
* @return FNASSO_ERR_NONE in case of success, an error value in case of failure.
*/
fnasso_error fnasso_kdc_get_tgt(fnasso_ctx *ctx, int *life_time);
/**
* Checks if a TGT exists in cache, and fills life_time with the TGT's lifetime in seconds. If no valid TGT is found
* in the current credentials cache, a value of -1 will be set.
* Note: life_time MUST be not NULL or an error will be raised.
*
* @param context A pointer to the FNASSO context where the TGT will be looked for.
* @param life_time A pointer to an integer that will store the TGT's lifetime (if any) or -1 if no valid TGT was found.
* @return FNASSO_ERR_NONE in case of success, an error value in case of failure.
*/
fnasso_error fnasso_kdc_check_tgt(fnasso_ctx *ctx, int *life_time);
/**
* Frees all information related to the KDC peer in a given FNASSO context.
*
* @param context A pointer to the FNASSO context where the KDC data will be wiped out.
* @return FNASSO_ERR_NONE in case of success, an error value in case of failure.
*/
fnasso_error fnasso_kdc_free(fnasso_ctx *ctx);
////////////////////////////////////////////////
// Kerberos Kadmin functions
////////////////////////////////////////////////
/**
* Checks wherever the kadmin context is set and ready to execute queries against a kadm server or not.
* @param context The FNASSO context where to check the kadmin data.
* @param isset A pointer to an integer that will be set to 0 if the kadmin context is not set, or non-zero in other case.
* @return FNASSO_ERR_NONE in case of success, an error value in case of failure.
*/
fnasso_error fnasso_kadmin_isset(fnasso_ctx *context, int *isset);
/**
* Sets the kerberos realm that will be administrated. A NULL value will unset any previous value.
* Note: Empty strings will return an error.
*
* @param context The FNASSO context where the changes may be applied.
* @param realm The realm name to be administrated using kadmin functions.
* @return FNASSO_ERR_NONE in case of success, an error value in case of failure.
*/
fnasso_error fnasso_kadmin_set_realm(fnasso_ctx *context, const char* realm);
/**
* Sets the hostname where the kadmin server is allocated. A NULL value will unset any previous value.
* Note: Empty strings will return an error.
*
* @param context The FNASSO context where the changes may be applied.
* @param realm The hostname where the kadmin server is allocated.
* @return FNASSO_ERR_NONE in case of success, an error value in case of failure.
*/
fnasso_error fnasso_kadmin_set_server(fnasso_ctx *context, const char* server);
/**
* Sets the username that will be used to login into the kadmin server.
* If either username or password. If either username or password are set to NULL,
* all kadmin user related information will be cleared.
* Note: Empty strings are only permitted in the password parameter, an empty string
* in the username will return an error.
*
* @param context The FNASSO context where the changes may be applied.
* @param username Username for login into the kadmin server.
* @param password Password supplied for the kadmin user.
* @return FNASSO_ERR_NONE in case of success, an error value in case of failure.
*/
fnasso_error fnasso_kadmin_set_admin(fnasso_ctx *context, const char* username, const char* password);
/**
* Asks the kadmin server to create a new user principal in the kerberos database. The user created data
* is retrieved from the user in the FNASSO context.
*
* @param context The FNASSO context where the changes may be applied.
* @return FNASSO_ERR_NONE in case of success, an error value in case of failure.
*/
fnasso_error fnasso_kadmin_create_user(fnasso_ctx *context);
/**
* Clears all kadmin data contained in the FNASSO context and frees unnecesary memory.
*
* @param context The FNASSO context where the changes may be applied.
* @return FNASSO_ERR_NONE in case of success, an error value in case of failure.
*/
fnasso_error fnasso_kadmin_free(fnasso_ctx *context);
#ifdef __cplusplus
}
#endif
#endif /* FNASSO_H */