X-Git-Url: https://git.armaanb.net/?p=opendoas.git;a=blobdiff_plain;f=shadow.c;h=01509f03df15d25315b0de364fd40341bd2d51bb;hp=71c71c697dd644017a7d77bc8541f029c49038f2;hb=HEAD;hpb=38e072b353f5b1325bbf52dfb759fe49ff6ef0f7 diff --git a/shadow.c b/shadow.c index 71c71c6..01509f0 100644 --- a/shadow.c +++ b/shadow.c @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2020 Duncan Overbruck + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "config.h" + #if HAVE_CRYPT_H # include #endif @@ -5,10 +23,10 @@ #include #include #include -#ifdef HAVE_READPASSPHRASE_H +#ifdef HAVE_READPASSPHRASE # include #else -# include "readpassphrase.h" +# include "sys-readpassphrase.h" #endif #include #include @@ -17,8 +35,13 @@ #include #include "openbsd.h" +#include "doas.h" + +#ifndef HOST_NAME_MAX +#define HOST_NAME_MAX _POSIX_HOST_NAME_MAX +#endif -void +int shadowauth(const char *myname, int persist) { const char *hash; @@ -44,11 +67,12 @@ shadowauth(const char *myname, int persist) hash = pw->pw_passwd; if (hash[0] == 'x' && hash[1] == '\0') { struct spwd *sp; - if ((sp = getspnam(myname)) == NULL) - errx(1, "Authorization failed"); + if ((sp = getspnam(myname)) == NULL) { + return(5); + } hash = sp->sp_pwdp; } else if (hash[0] != '*') { - errx(1, "Authorization failed"); + return(5); } char host[HOST_NAME_MAX + 1]; @@ -68,12 +92,13 @@ shadowauth(const char *myname, int persist) err(1, "readpassphrase"); if ((encrypted = crypt(response, hash)) == NULL) { explicit_bzero(rbuf, sizeof(rbuf)); - errx(1, "Authorization failed"); + printf(getinsult()); + return(5); } explicit_bzero(rbuf, sizeof(rbuf)); if (strcmp(encrypted, hash) != 0) { syslog(LOG_AUTHPRIV | LOG_NOTICE, "failed auth for %s", myname); - errx(1, "Authorization failed"); + return(5); } #ifdef USE_TIMESTAMP @@ -83,4 +108,5 @@ good: close(fd); } #endif + return(0); }