GSS_S_PROMPTING_NEEDED is a bit
[cyrus-sasl.git] / saslauthd / auth_getpwent.c
1 /* MODULE: auth_getpwent */
2
3 /* COPYRIGHT
4  * Copyright (c) 1997-2000 Messaging Direct Ltd.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY MESSAGING DIRECT LTD. ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL MESSAGING DIRECT LTD. OR
20  * ITS EMPLOYEES OR AGENTS BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
23  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
25  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
26  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27  * DAMAGE.
28  * END COPYRIGHT */
29
30 /* SYNOPSIS
31  * crypt(3) based passwd file validation
32  * END SYNOPSIS */
33
34 #ifdef __GNUC__
35 #ident "$Id: auth_getpwent.c,v 1.7 2005/01/27 04:39:52 shadow Exp $"
36 #endif
37
38 /* PUBLIC DEPENDENCIES */
39 #include "mechanisms.h"
40 #include <unistd.h>
41 #include <string.h>
42 #include <pwd.h>
43
44 # ifdef WITH_DES
45 #  ifdef WITH_SSL_DES
46 #   include <openssl/des.h>
47 #  else
48 #   include <des.h>
49 #  endif /* WITH_SSL_DES */
50 # endif /* WITH_DES */
51
52 #ifdef HAVE_CRYPT_H
53 #include <crypt.h>
54 #endif
55 /* END PUBLIC DEPENDENCIES */
56
57 #define RETURN(x) return strdup(x)
58 \f
59 /* FUNCTION: auth_getpwent */
60
61 char *                                  /* R: allocated response string */
62 auth_getpwent (
63   /* PARAMETERS */
64   const char *login,                    /* I: plaintext authenticator */
65   const char *password,                 /* I: plaintext password */
66   const char *service __attribute__((unused)),
67   const char *realm __attribute__((unused))
68   /* END PARAMETERS */
69   )
70 {
71     /* VARIABLES */
72     struct passwd *pw;                  /* pointer to passwd file entry */
73     /* END VARIABLES */
74   
75     pw = getpwnam(login);
76     endpwent();
77
78     if (pw == NULL) {
79         RETURN("NO");
80     }
81
82     if (strcmp(pw->pw_passwd, (const char *)crypt(password, pw->pw_passwd))) {
83         RETURN("NO");
84     }
85
86     RETURN("OK");
87 }
88
89 /* END FUNCTION: auth_getpwent */
90
91 /* END MODULE: auth_getpwent */