src/server/daemon/auth.h

Sun, 08 May 2022 12:27:43 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 08 May 2022 12:27:43 +0200
branch
webdav
changeset 344
70a9b945206a
parent 254
4784c14aa639
child 400
d814b29e8d96
permissions
-rw-r--r--

fix webdav_mkcol response and add error handling

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
254
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
36 #include <ucx/map.h>
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
37
66
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #ifdef __cplusplus
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 extern "C" {
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #endif
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 typedef struct {
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 User user;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 char *authdb;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 sstr_t *groups;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 size_t numgroups;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 char *password;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 uint32_t ref;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 } CachedUser;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 typedef struct user_cache_elm UserCacheElm;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 struct user_cache_elm {
254
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
53 CachedUser *user;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
54 UserCacheElm *next_user; // next elm in the cached user list
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
55 UcxKey key; // key to access this element
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
56 size_t slot; // slot in the map
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
57 UserCacheElm *next_elm; // next element in this map slot
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
58 time_t created;
66
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 };
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 typedef struct {
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 UserCacheElm **map;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 size_t size;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 size_t count;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 size_t max_users;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 UserCacheElm *head;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 UserCacheElm *trail;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 } UserCache;
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 void auth_cache_init();
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 User* auth_cache_get(char *authdb, char *user);
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 void auth_cache_add(
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 char *authdb,
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 User *user,
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 char *password,
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 char **groups,
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 size_t numgroups);
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 void auth_cache_remove_from_map(UserCacheElm *elm);
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 int cached_user_verify_password(CachedUser *user, char *password);
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 int cached_user_check_group(CachedUser *user, char *group);
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 void cached_user_unref(CachedUser *user);
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 void cached_user_delete(CachedUser *user);
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 #ifdef __cplusplus
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
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 #endif /* AUTH_H */
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92

mercurial