~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to helpers/basic_auth/getpwnam/getpwnam_auth.c

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2009-09-24 14:51:06 UTC
  • mfrom: (1.1.12 upstream)
  • mto: (20.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20090924145106-38jgrzmj0d73pha5
Tags: 3.1.0.13-1
* Upload to experimental

* New upstream release
  - Fixes Follow-X-Forwarded-For support (Closes: #523943)
  - Adds IPv6 support (Closes: #432351)

* debian/rules
  - Removed obsolete configuration options
  - Enable db and radius basic authentication modules

* debian/patches/01-cf.data.debian
  - Adapted to new upstream version

* debian/patches/02-makefile-defaults
  - Adapted to new upstream version

* debian/{squid.postinst,squid.rc,README.Debian,watch}
  - Updated references to squid 3.1

* debian/squid3.install
  - Install CSS file for error pages
  - Install manual pages for new authentication modules

* debian/squid3-common.install
  - Install documented version of configuration file in /usr/share/doc/squid3

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
 *
11
11
 * Uses getpwnam() routines for authentication.
12
12
 * This has the following advantages over the NCSA module:
13
 
 * 
 
13
 *
14
14
 * - Allow authentication of all know local users
15
15
 * - Allows authentication through nsswitch.conf
16
16
 *   + can handle NIS(+) requests
18
18
 *   + can handle PAM request
19
19
 *
20
20
 * 2006-07: Giancarlo Razzolini <linux-fan@onda.com.br>
21
 
 * 
 
21
 *
22
22
 * Added functionality for doing shadow authentication too,
23
23
 * using the getspnam() function on systems that support it.
24
24
 *
53
53
#define ERR    "ERR\n"
54
54
#define OK     "OK\n"
55
55
 
56
 
static int 
 
56
static int
57
57
passwd_auth(char *user, char *passwd)
58
58
{
59
59
    struct passwd *pwd;
60
60
    pwd = getpwnam(user);
61
61
    if (pwd == NULL) {
62
 
        return 0;               /* User does not exist */
 
62
        return 0;               /* User does not exist */
63
63
    } else {
64
 
        if (strcmp(pwd->pw_passwd, (char *) crypt(passwd, pwd->pw_passwd))) {
65
 
            return 2;           /* Wrong password */
66
 
        } else {
67
 
            return 1;           /* Authentication Sucessful */
68
 
        }
 
64
        if (strcmp(pwd->pw_passwd, (char *) crypt(passwd, pwd->pw_passwd))) {
 
65
            return 2;           /* Wrong password */
 
66
        } else {
 
67
            return 1;           /* Authentication Sucessful */
 
68
        }
69
69
    }
70
70
}
71
71
 
72
72
#if HAVE_SHADOW_H
73
 
static int 
 
73
static int
74
74
shadow_auth(char *user, char *passwd)
75
75
{
76
76
    struct spwd *pwd;
77
77
    pwd = getspnam(user);
78
78
    if (pwd == NULL) {
79
 
        return passwd_auth(user, passwd);       /* Fall back to passwd_auth */
 
79
        return passwd_auth(user, passwd);       /* Fall back to passwd_auth */
80
80
    } else {
81
 
        if (strcmp(pwd->sp_pwdp, crypt(passwd, pwd->sp_pwdp))) {
82
 
            return 2;           /* Wrong password */
83
 
        } else {
84
 
            return 1;           /* Authentication Sucessful */
85
 
        }
 
81
        if (strcmp(pwd->sp_pwdp, crypt(passwd, pwd->sp_pwdp))) {
 
82
            return 2;           /* Wrong password */
 
83
        } else {
 
84
            return 1;           /* Authentication Sucessful */
 
85
        }
86
86
    }
87
87
}
88
88
#endif
97
97
    setbuf(stdout, NULL);
98
98
    while (fgets(buf, 256, stdin) != NULL) {
99
99
 
100
 
        if ((p = strchr(buf, '\n')) != NULL)
101
 
            *p = '\0';          /* strip \n */
 
100
        if ((p = strchr(buf, '\n')) != NULL)
 
101
            *p = '\0';          /* strip \n */
102
102
 
103
 
        if ((user = strtok(buf, " ")) == NULL) {
104
 
            printf(ERR);
105
 
            continue;
106
 
        }
107
 
        if ((passwd = strtok(NULL, "")) == NULL) {
108
 
            printf(ERR);
109
 
            continue;
110
 
        }
111
 
        rfc1738_unescape(user);
112
 
        rfc1738_unescape(passwd);
 
103
        if ((user = strtok(buf, " ")) == NULL) {
 
104
            printf(ERR);
 
105
            continue;
 
106
        }
 
107
        if ((passwd = strtok(NULL, "")) == NULL) {
 
108
            printf(ERR);
 
109
            continue;
 
110
        }
 
111
        rfc1738_unescape(user);
 
112
        rfc1738_unescape(passwd);
113
113
#if HAVE_SHADOW_H
114
 
        auth = shadow_auth(user, passwd);
 
114
        auth = shadow_auth(user, passwd);
115
115
#else
116
 
        auth = passwd_auth(user, passwd);
 
116
        auth = passwd_auth(user, passwd);
117
117
#endif
118
 
        if (auth == 0) {
119
 
            printf("ERR No such user\n");
120
 
        } else {
121
 
            if (auth == 2) {
122
 
                printf("ERR Wrong password\n");
123
 
            } else {
124
 
                printf(OK);
125
 
            }
126
 
        }
 
118
        if (auth == 0) {
 
119
            printf("ERR No such user\n");
 
120
        } else {
 
121
            if (auth == 2) {
 
122
                printf("ERR Wrong password\n");
 
123
            } else {
 
124
                printf(OK);
 
125
            }
 
126
        }
127
127
    }
128
128
    exit(0);
129
129
}