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