bump version to 0.82 and prepare for release
[catagits/fcgi2.git] / examples / authorizer.c
CommitLineData
68ff52f8 1/*
0198fd3c 2 * tiny-authorizer.c --
3 *
68ff52f8 4 * FastCGI example Authorizer program using fcgi_stdio library
0198fd3c 5 *
6 * Copyright (c) 1996 Open Market, Inc.
af1b4cad 7 * See the file "LICENSE" for information on usage and redistribution
0198fd3c 8 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9 *
1708380d 10 * $Id: authorizer.c,v 1.1 2001/06/19 15:30:02 robs Exp $
0198fd3c 11 */
12
0198fd3c 13#include "fcgi_stdio.h"
14#include <stdlib.h>
15#include <string.h>
16
3293ebdf 17int main(void)
0198fd3c 18{
19 char *user, *password;
3293ebdf 20
0198fd3c 21 user = getenv("USER");
3293ebdf 22 if (user == NULL) {
0198fd3c 23 user = "doe";
24 }
3293ebdf 25
0198fd3c 26 password = getenv("PASSWORD");
3293ebdf 27 if (password == NULL) {
0198fd3c 28 password = "xxxx";
29 }
68ff52f8 30
3293ebdf 31 while (FCGI_Accept() >= 0) {
0198fd3c 32 char *remoteUser, *remotePassword;
3293ebdf 33
0198fd3c 34 remoteUser = getenv("REMOTE_USER");
35 remotePassword = getenv("REMOTE_PASSWD");
3293ebdf 36 if ((remoteUser == NULL) || (remotePassword == NULL)
37 || strcmp(remoteUser, user) || strcmp(remotePassword, password))
38 {
39 printf("Status: 401 Unauthorized\r\n"
40 "WWW-Authenticate: Basic realm=\"Test\"\r\n"
41 "\r\n");
68ff52f8 42 }
3293ebdf 43 else {
0198fd3c 44 char *processId = getenv("QUERY_STRING");
3293ebdf 45 if (processId == NULL || strlen(processId) == 0) {
0198fd3c 46 processId = "0";
68ff52f8 47 }
0198fd3c 48 printf("Status: 200 OK\r\n"
3293ebdf 49 "Variable-AUTH_TYPE: Basic\r\n"
50 "Variable-REMOTE_PASSWD:\r\n"
51 "Variable-PROCESS_ID: %s\r\n"
52 "\r\n", processId);
0198fd3c 53 }
54 }
3293ebdf 55
56 return 0;
0198fd3c 57}