[go: up one dir, main page]

File: authorizer.c

package info (click to toggle)
libfcgi 2.4.0-8.3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,252 kB
  • ctags: 1,606
  • sloc: sh: 6,897; ansic: 4,800; java: 872; cpp: 290; makefile: 154; perl: 2
file content (57 lines) | stat: -rw-r--r-- 1,515 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * tiny-authorizer.c --
 *
 * FastCGI example Authorizer program using fcgi_stdio library
 *
 * Copyright (c) 1996 Open Market, Inc.
 * See the file "LICENSE.TERMS" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * $Id: authorizer.c,v 1.1 2001/06/19 15:30:02 robs Exp $
 */

#include "fcgi_stdio.h"
#include <stdlib.h>
#include <string.h>

int main(void)
{
    char *user, *password;

    user = getenv("USER");
    if (user == NULL) {
        user = "doe";
    }

    password = getenv("PASSWORD");
    if (password == NULL) {
        password = "xxxx";
    }

    while (FCGI_Accept() >= 0) {
        char *remoteUser, *remotePassword;

        remoteUser = getenv("REMOTE_USER");
        remotePassword = getenv("REMOTE_PASSWD");
        if ((remoteUser == NULL) || (remotePassword == NULL)
             || strcmp(remoteUser, user) || strcmp(remotePassword, password))
        {
             printf("Status: 401 Unauthorized\r\n"
                 "WWW-Authenticate: Basic realm=\"Test\"\r\n"
                 "\r\n");
        }
        else {
            char *processId = getenv("QUERY_STRING");
            if (processId == NULL || strlen(processId) == 0) {
                processId = "0";
        }
            printf("Status: 200 OK\r\n"
                "Variable-AUTH_TYPE: Basic\r\n"
                "Variable-REMOTE_PASSWD:\r\n"
                "Variable-PROCESS_ID: %s\r\n"
                "\r\n", processId);
        }
    }

    return 0;
}