1 /*
2  * Copyright (c) 2010, 2011, 2012, 2013
3  *      Inferno Nettverk A/S, Norway.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. The above copyright notice, this list of conditions and the following
9  *    disclaimer must appear in all copies of the software, derivative works
10  *    or modified versions, and any portions thereof, aswell as in all
11  *    supporting documentation.
12  * 2. All advertising materials mentioning features or use of this software
13  *    must display the following acknowledgement:
14  *      This product includes software developed by
15  *      Inferno Nettverk A/S, Norway.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * Inferno Nettverk A/S requests users of this software to return to
31  *
32  *  Software Distribution Coordinator  or  sdc@inet.no
33  *  Inferno Nettverk A/S
34  *  Oslo Research Park
35  *  Gaustadall�en 21
36  *  NO-0349 Oslo
37  *  Norway
38  *
39  * any improvements or extensions that they make and grant Inferno Nettverk A/S
40  * the rights to redistribute these changes.
41  *
42  */
43 
44 #include "common.h"
45 
46 #if HAVE_BSDAUTH
47 
48 static const char rcsid[] =
49 "$Id: auth_bsd.c,v 1.25 2013/10/27 15:24:42 karls Exp $";
50 
51 #include <login_cap.h>
52 #include <bsd_auth.h>
53 
54 int
bsdauth_passwordcheck(s,src,dst,auth,emsg,emsgsize)55 bsdauth_passwordcheck(s, src, dst, auth, emsg, emsgsize)
56    int s;
57    const struct sockaddr_storage *src, *dst;
58    authmethod_bsd_t *auth;
59    char *emsg;
60    size_t emsgsize;
61 {
62    const char *function = "bsdauth_passwordcheck()";
63    char password[MAXPWLEN], *style;
64    char visname[MAXNAMELEN * 4];
65 
66    int rc;
67 
68    if (*auth->style == NUL)
69       style = NULL;
70    else
71       style = auth->style;
72 
73    /* auth_userokay clears password parameter, pass a copy */
74    strncpy(password, (char *)auth->password, sizeof(password) - 1);
75    password[sizeof(password) - 1] = NUL;
76 
77    str2vis((char *)auth->name,
78            strlen((char *)auth->name),
79            visname, sizeof(visname));
80 
81    slog(LOG_DEBUG, "%s: bsdauth style to use for user \"%s\": %s",
82         function, visname, style == NULL ? "default" : style);
83 
84    /*
85     * note: NULL password would lead to libc requesting it interactively.
86     * if NULL, user can specify in username, e.g., uname:radius
87     */
88    sockd_priv(SOCKD_PRIV_BSDAUTH, PRIV_ON);
89    rc = auth_userokay((char *)auth->name, style, "auth-sockd", password);
90    sockd_priv(SOCKD_PRIV_BSDAUTH, PRIV_OFF);
91 
92    if (rc == 0) {
93       slog(LOG_DEBUG, "%s: bsdauth method failed for user \"%s\": (%s)",
94            function, visname, style == NULL ? "default" : style);
95 
96       snprintf(emsg, emsgsize, "%s: auth_userokay failed: %s",
97                function, strerror(errno));
98 
99       return -1;
100    }
101 
102    return 0;
103 }
104 
105 #endif /* HAVE_BSDAUTH */
106