Debian Codegraph @

src/auth.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2014 Joris Vink <[email protected]>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include <sys/param.h>
18 #include <sys/types.h>
19
20 #include <ctype.h>
21
22 #include "kore.h"cxx . . $ `<file>/include/kore/kore.h`/
23 #include "http.h"cxx . . $ `<file>/include/kore/http.h`/
24
25 TAILQ_HEADcxx . . $ `<external>/2546723208511035544/queue.h:372:9`!(, kore_auth) auth_listcxx . . $ auth_list.;
26
27 void
28 kore_auth_initcxx . . $ kore_auth_init(49f6e7a06ebc5aa8).(void)
29 {
30 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&auth_list);
31 }
32
33 int
34 kore_auth_newcxx . . $ kore_auth_new(5c4306d8553b3696).(const char *name)
35 {
36 struct kore_authcxx . . $ kore_auth# *auth;
37
38 if (kore_auth_lookupcxx . . $ kore_auth_lookup(89b26d483e8790fd).(name) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
39 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
40
41 auth = kore_malloccxx . . $ kore_malloc(bfcfa4d6b7f7ef64).(sizeof(*auth));
42 auth->typecxx . . $ kore_auth#type. = 0;
43 auth->valuecxx . . $ kore_auth#value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
44 auth->redirectcxx . . $ kore_auth#redirect. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
45 auth->validatorcxx . . $ kore_auth#validator. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
46 auth->namecxx . . $ kore_auth#name. = kore_strdupcxx . . $ kore_strdup(a8b8e32347182212).(name);
47
48 TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(&auth_list, auth, list);
49
50 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
51 }
52
53 int
54 kore_auth_runcxx . . $ kore_auth_run(117534b4248efb65).(struct http_requestcxx . . $ http_request# *req, struct kore_authcxx . . $ kore_auth# *auth)
55 {
56 int r;
57
58 switch (auth->typecxx . . $ kore_auth#type.) {
59 case KORE_AUTH_TYPE_COOKIEcxx . . $ `include/kore/kore.h:392:9`!:
60 r = kore_auth_cookiecxx . . $ kore_auth_cookie(117534b4248efb65).(req, auth);
61 break;
62 case KORE_AUTH_TYPE_HEADERcxx . . $ `include/kore/kore.h:393:9`!:
63 r = kore_auth_headercxx . . $ kore_auth_header(117534b4248efb65).(req, auth);
64 break;
65 case KORE_AUTH_TYPE_REQUESTcxx . . $ `include/kore/kore.h:394:9`!:
66 r = kore_auth_requestcxx . . $ kore_auth_request(117534b4248efb65).(req, auth);
67 break;
68 default:
69 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_NOTICEcxx . . $ `<external>/6168640806541382331/syslog.h:56:9`!, "unknown auth type %d", auth->typecxx . . $ kore_auth#type.);
70 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
71 }
72
73 switch (r) {
74 case KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!:
75 req->flagscxx . . $ http_request#flags. |= HTTP_REQUEST_AUTHEDcxx . . $ `include/kore/http.h:247:9`!;
76 /* FALLTHROUGH */
77 case KORE_RESULT_RETRYcxx . . $ `include/kore/kore.h:89:9`!:
78 return (r);
79 default:
80 break;
81 }
82
83 /* Authentication types of "request" send their own HTTP responses. */
84 if (auth->typecxx . . $ kore_auth#type. == KORE_AUTH_TYPE_REQUESTcxx . . $ `include/kore/kore.h:394:9`!)
85 return (r);
86
87 if (auth->redirectcxx . . $ kore_auth#redirect. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
88 http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, HTTP_STATUS_FORBIDDENcxx . . $ HTTP_STATUS_FORBIDDEN., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
89 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
90 }
91
92 http_response_headercxx . . $ http_response_header(84119343264ef6a5).(req, "location", auth->redirectcxx . . $ kore_auth#redirect.);
93 http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, HTTP_STATUS_FOUNDcxx . . $ HTTP_STATUS_FOUND., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
94
95 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
96 }
97
98 int
99 kore_auth_cookiecxx . . $ kore_auth_cookie(117534b4248efb65).(struct http_requestcxx . . $ http_request# *req, struct kore_authcxx . . $ kore_auth# *auth)
100 {
101 const char *hdr;
102 int i, v;
103 size_t len, slen;
104 char *value, *c, *cookie, *cookies[HTTP_MAX_COOKIEScxx . . $ `include/kore/http.h:43:9`!];
105
106 if (!http_request_headercxx . . $ http_request_header(8b4805cea1886632).(req, "cookie", &hdr))
107 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
108
109 cookie = kore_strdupcxx . . $ kore_strdup(a8b8e32347182212).(hdr);
110
111 slen = strlencxx . . $ strlen(751346f8406fd082).(auth->valuecxx . . $ kore_auth#value.);
112 v = kore_split_stringcxx . . $ kore_split_string(87b756e43bd5489c).(cookie, ";", cookies, HTTP_MAX_COOKIEScxx . . $ `include/kore/http.h:43:9`!);
113 for (i = 0; i < v; i++) {
114 for (c = cookies[i]; isspacecxx . . $ `<external>/17904084882347303253/ctype.h:197:10`!(*(unsigned char *)c); c++)
115 ;
116
117 len = MINcxx . . $ `<external>/1231830743887005719/param.h:102:9`!(slen, strlen(cookies[i]));
118 if (!strncmpcxx . . $ strncmp(fd278af2f295fa2e).(c, auth->valuecxx . . $ kore_auth#value., len))
119 break;
120 }
121
122 if (i == v) {
123 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(cookie);
124 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
125 }
126
127 c = cookies[i];
128 if ((value = strchrcxx . . $ strchr(2050848944e00d54).(c, '=')) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
129 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(cookie);
130 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
131 }
132
133 i = kore_validator_checkcxx . . $ kore_validator_check(a50dfed4c9bd2b00).(req, auth->validatorcxx . . $ kore_auth#validator., ++value);
134 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(cookie);
135
136 return (i);
137 }
138
139 int
140 kore_auth_headercxx . . $ kore_auth_header(117534b4248efb65).(struct http_requestcxx . . $ http_request# *req, struct kore_authcxx . . $ kore_auth# *auth)
141 {
142 const char *header;
143
144 if (!http_request_headercxx . . $ http_request_header(8b4805cea1886632).(req, auth->valuecxx . . $ kore_auth#value., &header))
145 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
146
147 return (kore_validator_checkcxx . . $ kore_validator_check(a50dfed4c9bd2b00).(req, auth->validatorcxx . . $ kore_auth#validator., header));
148 }
149
150 int
151 kore_auth_requestcxx . . $ kore_auth_request(117534b4248efb65).(struct http_requestcxx . . $ http_request# *req, struct kore_authcxx . . $ kore_auth# *auth)
152 {
153 int ret;
154
155 req->flagscxx . . $ http_request#flags. |= HTTP_VALIDATOR_IS_REQUESTcxx . . $ `include/kore/http.h:252:9`!;
156 ret = kore_validator_checkcxx . . $ kore_validator_check(a50dfed4c9bd2b00).(req, auth->validatorcxx . . $ kore_auth#validator., req);
157 req->flagscxx . . $ http_request#flags. &= ~HTTP_VALIDATOR_IS_REQUESTcxx . . $ `include/kore/http.h:252:9`!;
158
159 return (ret);
160 }
161
162 struct kore_authcxx . . $ kore_auth# *
163 kore_auth_lookupcxx . . $ kore_auth_lookup(89b26d483e8790fd).(const char *name)
164 {
165 struct kore_authcxx . . $ kore_auth# *auth;
166
167 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(auth, &auth_list, list) {
168 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(auth->namecxx . . $ kore_auth#name., name))
169 return (auth);
170 }
171
172 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
173 }