src/server/daemon/auth.h

Sat, 13 Jan 2018 18:48:19 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 13 Jan 2018 18:48:19 +0100
branch
aio
changeset 192
6a145e13d933
parent 91
fac51f87def0
child 254
4784c14aa639
permissions
-rw-r--r--

replaces eventfd with pipe and closes aio branch

66
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2013 Olaf Wintermann. All rights reserved.
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #ifndef AUTH_H
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #define AUTH_H
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <sys/types.h>
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
33 #include <inttypes.h>
66
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "../public/auth.h"
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #ifdef __cplusplus
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 extern "C" {
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #endif
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 typedef struct {
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 User user;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 char *authdb;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 sstr_t *groups;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 size_t numgroups;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 char *password;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 uint32_t ref;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 } CachedUser;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 typedef struct user_cache_elm UserCacheElm;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 struct user_cache_elm {
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 CachedUser *user;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 UserCacheElm *next_user; // next elm in the cached user list
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 UcxKey key; // key to access this element
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 size_t slot; // slot in the map
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 UserCacheElm *next_elm; // next element in this map slot
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 time_t created;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 };
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 typedef struct {
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 UserCacheElm **map;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 size_t size;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 size_t count;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 size_t max_users;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 UserCacheElm *head;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 UserCacheElm *trail;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 } UserCache;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 void auth_cache_init();
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 User* auth_cache_get(char *authdb, char *user);
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 void auth_cache_add(
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 char *authdb,
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 User *user,
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 char *password,
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 char **groups,
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 size_t numgroups);
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 void auth_cache_remove_from_map(UserCacheElm *elm);
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 int cached_user_verify_password(CachedUser *user, char *password);
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 int cached_user_check_group(CachedUser *user, char *group);
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 void cached_user_unref(CachedUser *user);
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 void cached_user_delete(CachedUser *user);
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 #ifdef __cplusplus
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 }
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 #endif
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 #endif /* AUTH_H */
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90

mercurial