More translations.
[doldaconnect.git] / daemon / auth.c
CommitLineData
d3372da9 1/*
2 * Dolda Connect - Modular multiuser Direct Connect-style client
3 * Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19#include <wchar.h>
20#include <errno.h>
21
22#ifdef HAVE_CONFIG_H
23#include <config.h>
24#endif
25#include "auth.h"
26#include "utils.h"
27#include "module.h"
28#include "conf.h"
29
30struct authmech *mechs = NULL;
31
32static int authless_inithandle(struct authhandle *auth, char *username)
33{
34 return(0);
35}
36
37static void authless_release(struct authhandle *auth)
38{
39}
40
41static int authless_authenticate(struct authhandle *auth, char *data)
42{
43 return(AUTH_SUCCESS);
44}
45
46static int authless_succeed_1param(struct authhandle *auth)
47{
48 return(AUTH_SUCCESS);
49}
50
51static struct authmech authless =
52{
53 .name = L"authless",
54 .inithandle = authless_inithandle,
55 .release = authless_release,
56 .authenticate = authless_authenticate,
57 .renewcred = authless_succeed_1param,
58 .opensess = authless_succeed_1param,
59 .closesess = authless_succeed_1param
60};
61
62static struct authhandle *newhandle(void)
63{
64 struct authhandle *auth;
65
66 auth = smalloc(sizeof(*auth));
67 auth->refcount = 1;
68 auth->mech = NULL;
69 auth->text = NULL;
70 auth->mechdata = NULL;
71 return(auth);
72}
73
74void authgethandle(struct authhandle *auth)
75{
76 auth->refcount++;
77}
78
79void authputhandle(struct authhandle *auth)
80{
81 if(--auth->refcount)
82 return;
83 if(auth->text != NULL)
84 free(auth->text);
85 if(auth->mechdata != NULL)
86 auth->mech->release(auth);
87 free(auth);
88}
89
90struct authhandle *initauth(wchar_t *mechname, char *username)
91{
92 struct authmech *mech;
93 struct authhandle *auth;
94
95 for(mech = mechs; mech != NULL; mech = mech->next)
96 {
97 if(mech->enabled && !wcscmp(mechname, mech->name))
98 break;
99 }
100 if(mech == NULL)
101 {
102 errno = ENOENT;
103 return(NULL);
104 }
105 auth = newhandle();
106 auth->mech = mech;
107 if(mech->inithandle(auth, username))
108 {
109 authputhandle(auth);
110 return(NULL);
111 }
112 return(auth);
113}
114
115int authenticate(struct authhandle *handle, char *data)
116{
117 if(handle->mech == NULL)
118 return(AUTH_ERR);
119 return(handle->mech->authenticate(handle, data));
120}
121
122int authrenewcred(struct authhandle *handle)
123{
124 if((handle->mech == NULL) || (handle->mech->renewcred == NULL))
125 return(AUTH_SUCCESS);
126 return(handle->mech->renewcred(handle));
127}
128
129int authopensess(struct authhandle *handle)
130{
131 if((handle->mech == NULL) || (handle->mech->opensess == NULL))
132 return(AUTH_SUCCESS);
133 return(handle->mech->opensess(handle));
134}
135
136int authclosesess(struct authhandle *handle)
137{
138 if((handle->mech == NULL) || (handle->mech->closesess == NULL))
139 return(AUTH_SUCCESS);
140 return(handle->mech->closesess(handle));
141}
142
143void regmech(struct authmech *mech)
144{
145 mech->next = mechs;
146 mechs = mech;
147}
148
149static void preinit(int hup)
150{
151 extern struct authmech authmech_pam;
152
153 if(hup)
154 return;
155 regmech(&authless);
156 regmech(&authmech_pam);
157}
158
159static int init(int hup)
160{
161 authless.enabled = confgetint("auth", "authless");
162 return(0);
163}
164
165static struct configvar myvars[] =
166{
167 {CONF_VAR_STRING, "pamserv", {.str = L"doldacond"}},
168 {CONF_VAR_BOOL, "authless", {.num = 1}},
169 {CONF_VAR_END}
170};
171
172static struct module me =
173{
174 .name = "auth",
175 .conf =
176 {
177 .vars = myvars
178 },
179 .preinit = preinit,
180 .init = init
181};
182
183MODULE(me)