2 * Dolda Connect - Modular multiuser Direct Connect-style client
3 * Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com)
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.
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.
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
30 struct authmech *mechs = NULL;
32 static int authless_inithandle(struct authhandle *auth, char *username)
37 static void authless_release(struct authhandle *auth)
41 static int authless_authenticate(struct authhandle *auth, struct socket *sk, char *data)
46 static int authless_succeed_1param(struct authhandle *auth)
51 static struct authmech 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
62 static struct authhandle *newhandle(void)
64 struct authhandle *auth;
66 auth = smalloc(sizeof(*auth));
70 auth->mechdata = NULL;
74 void authgethandle(struct authhandle *auth)
79 void authputhandle(struct authhandle *auth)
83 if(auth->text != NULL)
85 if(auth->mechdata != NULL)
86 auth->mech->release(auth);
90 struct authhandle *initauth(wchar_t *mechname, char *username)
92 struct authmech *mech;
93 struct authhandle *auth;
95 for(mech = mechs; mech != NULL; mech = mech->next)
97 if(mech->enabled && !wcscmp(mechname, mech->name))
107 if(mech->inithandle(auth, username))
115 int authenticate(struct authhandle *handle, struct socket *sk, char *data)
117 if(handle->mech == NULL)
119 return(handle->mech->authenticate(handle, sk, data));
122 int authavailable(struct authmech *mech, struct socket *sk)
124 if(mech->available == NULL)
126 return(mech->available(sk));
129 int authrenewcred(struct authhandle *handle)
131 if((handle->mech == NULL) || (handle->mech->renewcred == NULL))
132 return(AUTH_SUCCESS);
133 return(handle->mech->renewcred(handle));
136 int authopensess(struct authhandle *handle)
138 if((handle->mech == NULL) || (handle->mech->opensess == NULL))
139 return(AUTH_SUCCESS);
140 return(handle->mech->opensess(handle));
143 int authclosesess(struct authhandle *handle)
145 if((handle->mech == NULL) || (handle->mech->closesess == NULL))
146 return(AUTH_SUCCESS);
147 return(handle->mech->closesess(handle));
150 void regmech(struct authmech *mech)
156 static void preinit(int hup)
158 extern struct authmech authmech_pam;
163 regmech(&authmech_pam);
166 static int init(int hup)
168 authless.enabled = confgetint("auth", "authless");
172 static struct configvar myvars[] =
174 /** The name of the PAM service file to use. */
175 {CONF_VAR_STRING, "pamserv", {.str = L"doldacond"}},
176 /** Specifies whether insecure authentication is to be allowed. If
177 * you are not completely sure what you are doing, never turn this
178 * on without also turning on net.onlylocal. */
179 {CONF_VAR_BOOL, "authless", {.num = 0}},
183 static struct module me =