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

« back to all changes in this revision

Viewing changes to helpers/basic_auth/PAM/pam_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:
1
1
/*
2
 
 * $Id: pam_auth.c,v 1.17 2007/07/19 03:36:05 hno Exp $
 
2
 * $Id$
3
3
 *
4
4
 * PAM authenticator module for Squid.
5
5
 * Copyright (C) 1999,2002,2003 Henrik Nordstrom <hno@squid-cache.org>
100
100
password_conversation(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr)
101
101
{
102
102
    if (num_msg != 1 || msg[0]->msg_style != PAM_PROMPT_ECHO_OFF) {
103
 
        fprintf(stderr, "ERROR: Unexpected PAM converstaion '%d/%s'\n", msg[0]->msg_style, msg[0]->msg);
104
 
        return PAM_CONV_ERR;
105
 
    }
106
 
    if (!appdata_ptr) {
107
 
        /* Workaround for Solaris 2.6 where the PAM library is broken
108
 
         * and does not pass appdata_ptr to the conversation routine
109
 
         */
110
 
        appdata_ptr = password;
111
 
    }
112
 
    if (!appdata_ptr) {
113
 
        fprintf(stderr, "ERROR: No password available to password_converstation!\n");
114
 
        return PAM_CONV_ERR;
 
103
        fprintf(stderr, "ERROR: Unexpected PAM converstaion '%d/%s'\n", msg[0]->msg_style, msg[0]->msg);
 
104
        return PAM_CONV_ERR;
 
105
    }
 
106
    if (!appdata_ptr) {
 
107
        /* Workaround for Solaris 2.6 where the PAM library is broken
 
108
         * and does not pass appdata_ptr to the conversation routine
 
109
         */
 
110
        appdata_ptr = password;
 
111
    }
 
112
    if (!appdata_ptr) {
 
113
        fprintf(stderr, "ERROR: No password available to password_converstation!\n");
 
114
        return PAM_CONV_ERR;
115
115
    }
116
116
    *resp = calloc(num_msg, sizeof(struct pam_response));
117
117
    if (!*resp) {
118
 
        fprintf(stderr, "ERROR: Out of memory!\n");
119
 
        return PAM_CONV_ERR;
 
118
        fprintf(stderr, "ERROR: Out of memory!\n");
 
119
        return PAM_CONV_ERR;
120
120
    }
121
121
    (*resp)[0].resp = strdup((char *) appdata_ptr);
122
122
    (*resp)[0].resp_retcode = 0;
124
124
    return ((*resp)[0].resp ? PAM_SUCCESS : PAM_CONV_ERR);
125
125
}
126
126
 
127
 
static struct pam_conv conv =
128
 
{
 
127
static struct pam_conv conv = {
129
128
    &password_conversation,
130
129
    NULL
131
130
};
159
158
    setvbuf(stdout, NULL, _IOLBF, 0);
160
159
 
161
160
    while (1) {
162
 
        int ch = getopt(argc, argv, "1n:t:o");
163
 
        switch (ch) {
164
 
        case -1:
165
 
                goto start;
166
 
        case 'n':
167
 
                service = optarg;
168
 
                break;
169
 
        case 't':
170
 
                ttl = atoi(optarg);
171
 
                break;
172
 
        case '1':
173
 
                ttl = 0;
174
 
                break;
175
 
        case 'o':
176
 
                no_acct_mgmt = 1;
177
 
                break;
178
 
        default:
179
 
                fprintf(stderr, "Unknown getopt value '%c'\n", ch);
180
 
                usage(argv[0]);
181
 
                exit(1);
182
 
        }
 
161
        int ch = getopt(argc, argv, "1n:t:o");
 
162
        switch (ch) {
 
163
        case -1:
 
164
            goto start;
 
165
        case 'n':
 
166
            service = optarg;
 
167
            break;
 
168
        case 't':
 
169
            ttl = atoi(optarg);
 
170
            break;
 
171
        case '1':
 
172
            ttl = 0;
 
173
            break;
 
174
        case 'o':
 
175
            no_acct_mgmt = 1;
 
176
            break;
 
177
        default:
 
178
            fprintf(stderr, "Unknown getopt value '%c'\n", ch);
 
179
            usage(argv[0]);
 
180
            exit(1);
 
181
        }
183
182
    }
184
183
start:
185
184
    if (optind < argc) {
186
 
        fprintf(stderr, "Unknown option '%s'\n", argv[optind]);
187
 
        usage(argv[0]);
188
 
        exit(1);
 
185
        fprintf(stderr, "Unknown option '%s'\n", argv[optind]);
 
186
        usage(argv[0]);
 
187
        exit(1);
189
188
    }
190
189
 
191
190
    while (fgets(buf, BUFSIZE, stdin)) {
192
 
        user = buf;
193
 
        password = strchr(buf, '\n');
194
 
        if (!password) {
195
 
            fprintf(stderr, "authenticator: Unexpected input '%s'\n", buf);
196
 
            goto error;
197
 
        }
198
 
        *password = '\0';
199
 
        password = strchr(buf, ' ');
200
 
        if (!password) {
201
 
            fprintf(stderr, "authenticator: Unexpected input '%s'\n", buf);
202
 
            goto error;
203
 
        }
204
 
        *password++ = '\0';
205
 
        rfc1738_unescape(user);
206
 
        rfc1738_unescape(password);
207
 
        conv.appdata_ptr = (char *) password;   /* from buf above. not allocated */
 
191
        user = buf;
 
192
        password = strchr(buf, '\n');
 
193
        if (!password) {
 
194
            fprintf(stderr, "authenticator: Unexpected input '%s'\n", buf);
 
195
            goto error;
 
196
        }
 
197
        *password = '\0';
 
198
        password = strchr(buf, ' ');
 
199
        if (!password) {
 
200
            fprintf(stderr, "authenticator: Unexpected input '%s'\n", buf);
 
201
            goto error;
 
202
        }
 
203
        *password++ = '\0';
 
204
        rfc1738_unescape(user);
 
205
        rfc1738_unescape(password);
 
206
        conv.appdata_ptr = (char *) password;   /* from buf above. not allocated */
208
207
 
209
 
        if (ttl == 0) {
210
 
            /* Create PAM connection */
211
 
            retval = pam_start(service, user, &conv, &pamh);
212
 
            if (retval != PAM_SUCCESS) {
213
 
                fprintf(stderr, "ERROR: failed to create PAM authenticator\n");
214
 
                goto error;
215
 
            }
216
 
        } else if (!pamh || (time(NULL) - pamh_created) >= ttl || pamh_created > time(NULL)) {
217
 
            /* Close previous PAM connection */
218
 
            if (pamh) {
219
 
                retval = pam_end(pamh, retval);
220
 
                if (retval != PAM_SUCCESS) {
221
 
                    fprintf(stderr, "WARNING: failed to release PAM authenticator\n");
222
 
                }
223
 
                pamh = NULL;
224
 
            }
225
 
            /* Initialize persistent PAM connection */
226
 
            retval = pam_start(service, "squid@", &conv, &pamh);
227
 
            if (retval != PAM_SUCCESS) {
228
 
                fprintf(stderr, "ERROR: failed to create PAM authenticator\n");
229
 
                goto error;
230
 
            }
231
 
            pamh_created = time(NULL);
232
 
        }
233
 
        /* Authentication */
234
 
        retval = PAM_SUCCESS;
235
 
        if (ttl != 0) {
236
 
            if (retval == PAM_SUCCESS)
237
 
                retval = pam_set_item(pamh, PAM_USER, user);
238
 
            if (retval == PAM_SUCCESS)
239
 
                retval = pam_set_item(pamh, PAM_CONV, &conv);
240
 
        }
241
 
        if (retval == PAM_SUCCESS)
242
 
            retval = pam_authenticate(pamh, 0);
243
 
        if (retval == PAM_SUCCESS && !no_acct_mgmt)
244
 
            retval = pam_acct_mgmt(pamh, 0);
245
 
        if (retval == PAM_SUCCESS) {
246
 
            fprintf(stdout, "OK\n");
247
 
        } else {
 
208
        if (ttl == 0) {
 
209
            /* Create PAM connection */
 
210
            retval = pam_start(service, user, &conv, &pamh);
 
211
            if (retval != PAM_SUCCESS) {
 
212
                fprintf(stderr, "ERROR: failed to create PAM authenticator\n");
 
213
                goto error;
 
214
            }
 
215
        } else if (!pamh || (time(NULL) - pamh_created) >= ttl || pamh_created > time(NULL)) {
 
216
            /* Close previous PAM connection */
 
217
            if (pamh) {
 
218
                retval = pam_end(pamh, retval);
 
219
                if (retval != PAM_SUCCESS) {
 
220
                    fprintf(stderr, "WARNING: failed to release PAM authenticator\n");
 
221
                }
 
222
                pamh = NULL;
 
223
            }
 
224
            /* Initialize persistent PAM connection */
 
225
            retval = pam_start(service, "squid@", &conv, &pamh);
 
226
            if (retval != PAM_SUCCESS) {
 
227
                fprintf(stderr, "ERROR: failed to create PAM authenticator\n");
 
228
                goto error;
 
229
            }
 
230
            pamh_created = time(NULL);
 
231
        }
 
232
        /* Authentication */
 
233
        retval = PAM_SUCCESS;
 
234
        if (ttl != 0) {
 
235
            if (retval == PAM_SUCCESS)
 
236
                retval = pam_set_item(pamh, PAM_USER, user);
 
237
            if (retval == PAM_SUCCESS)
 
238
                retval = pam_set_item(pamh, PAM_CONV, &conv);
 
239
        }
 
240
        if (retval == PAM_SUCCESS)
 
241
            retval = pam_authenticate(pamh, 0);
 
242
        if (retval == PAM_SUCCESS && !no_acct_mgmt)
 
243
            retval = pam_acct_mgmt(pamh, 0);
 
244
        if (retval == PAM_SUCCESS) {
 
245
            fprintf(stdout, "OK\n");
 
246
        } else {
248
247
error:
249
 
            fprintf(stdout, "ERR\n");
250
 
        }
251
 
        /* cleanup */
252
 
        retval = PAM_SUCCESS;
 
248
            fprintf(stdout, "ERR\n");
 
249
        }
 
250
        /* cleanup */
 
251
        retval = PAM_SUCCESS;
253
252
#ifdef PAM_AUTHTOK
254
 
        if (ttl != 0) {
255
 
            if (retval == PAM_SUCCESS)
256
 
                retval = pam_set_item(pamh, PAM_AUTHTOK, NULL);
257
 
        }
 
253
        if (ttl != 0) {
 
254
            if (retval == PAM_SUCCESS)
 
255
                retval = pam_set_item(pamh, PAM_AUTHTOK, NULL);
 
256
        }
258
257
#endif
259
 
        if (ttl == 0 || retval != PAM_SUCCESS) {
260
 
            retval = pam_end(pamh, retval);
261
 
            if (retval != PAM_SUCCESS) {
262
 
                fprintf(stderr, "WARNING: failed to release PAM authenticator\n");
263
 
            }
264
 
            pamh = NULL;
265
 
        }
 
258
        if (ttl == 0 || retval != PAM_SUCCESS) {
 
259
            retval = pam_end(pamh, retval);
 
260
            if (retval != PAM_SUCCESS) {
 
261
                fprintf(stderr, "WARNING: failed to release PAM authenticator\n");
 
262
            }
 
263
            pamh = NULL;
 
264
        }
266
265
    }
267
266
 
268
267
    if (pamh) {
269
 
        retval = pam_end(pamh, retval);
270
 
        if (retval != PAM_SUCCESS) {
271
 
            pamh = NULL;
272
 
            fprintf(stderr, "ERROR: failed to release PAM authenticator\n");
273
 
        }
 
268
        retval = pam_end(pamh, retval);
 
269
        if (retval != PAM_SUCCESS) {
 
270
            pamh = NULL;
 
271
            fprintf(stderr, "ERROR: failed to release PAM authenticator\n");
 
272
        }
274
273
    }
275
274
    return 0;
276
275
}