Removed examples/tiny-cgi.c (it wasn't a FastCGI application?!).
[catagits/fcgi2.git] / examples / tiny-authorizer.c
CommitLineData
0198fd3c 1/*
2 * tiny-authorizer.c --
3 *
4 * FastCGI example Authorizer program using fcgi_stdio library
5 *
6 *
7 * Be sure to run this program in a region with CGIPassword
8 * in order to get REMOTE_USER and REMOTE_PASSWD in place
9 * of HTTP_AUTHORIZATION.
10 *
11 * Copyright (c) 1996 Open Market, Inc.
12 *
13 * See the file "LICENSE.TERMS" for information on usage and redistribution
14 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15 *
16 */
17
18#ifndef lint
19static const char rcsid[] = "$Id: tiny-authorizer.c,v 1.1 1997/09/16 15:36:28 stanleyg Exp $";
20#endif /* not lint */
21
22#include "fcgi_stdio.h"
23#include <stdlib.h>
24#include <string.h>
25
26void main(void)
27{
28 char *user, *password;
29 user = getenv("USER");
30 if(user == NULL) {
31 user = "doe";
32 }
33 password = getenv("PASSWORD");
34 if(password == NULL) {
35 password = "xxxx";
36 }
37
38 while(FCGI_Accept() >= 0) {
39 char *remoteUser, *remotePassword;
40 remoteUser = getenv("REMOTE_USER");
41 remotePassword = getenv("REMOTE_PASSWD");
42 if((remoteUser == NULL) || (remotePassword == NULL) ||
43 strcmp(remoteUser, user) || strcmp(remotePassword, password)) {
44 printf("Status: 401 Unauthorized\r\n"
45 "WWW-Authenticate: Basic realm=\"Test\"\r\n"
46 "\r\n");
47
48 } else {
49 char *processId = getenv("QUERY_STRING");
50 if(processId == NULL || strlen(processId) == 0) {
51 processId = "0";
52 }
53 printf("Status: 200 OK\r\n"
54 "Variable-AUTH_TYPE: Basic\r\n"
55 "Variable-REMOTE_PASSWD:\r\n"
56 "Variable-PROCESS_ID: %s\r\n"
57 "\r\n", processId);
58 }
59 }
60}