helpers/basic_auth/MSNT/msntauth.c
Go to the documentation of this file.00001 00002 /* 00003 * MSNT - Microsoft Windows NT domain squid authenticator module 00004 * Version 2.0 by Stellar-X Pty Ltd, Antonino Iannella 00005 * Sun Sep 2 14:39:53 CST 2001 00006 * 00007 * Modified to act as a Squid authenticator module. 00008 * Removed all Pike stuff. 00009 * Returns OK for a successful authentication, or ERR upon error. 00010 * 00011 * Uses code from - 00012 * Andrew Tridgell 1997 00013 * Richard Sharpe 1996 00014 * Bill Welliver 1999 00015 * Duane Wessels 2000 (wessels@squid-cache.org) 00016 * 00017 * Released under GNU Public License 00018 * 00019 * This program is free software; you can redistribute it and/or modify 00020 * it under the terms of the GNU General Public License as published by 00021 * the Free Software Foundation; either version 2 of the License, or 00022 * (at your option) any later version. 00023 * 00024 * This program is distributed in the hope that it will be useful, 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00027 * GNU General Public License for more details. 00028 * 00029 * You should have received a copy of the GNU General Public License 00030 * along with this program; if not, write to the Free Software 00031 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00032 */ 00033 00034 #include "rfc1738.h" 00035 #include "util.h" 00036 00037 #include <stdio.h> 00038 #include <signal.h> 00039 #include <syslog.h> 00040 #include <string.h> 00041 #include <sys/time.h> 00042 00043 #include "msntauth.h" 00044 00045 extern char version[]; 00046 char msntauth_version[] = "Msntauth v2.0.3 (C) 2 Sep 2001 Stellar-X Antonino Iannella.\nModified by the Squid HTTP Proxy team 26 Jun 2002"; 00047 00048 /* Main program for simple authentication. 00049 * Reads the denied user file. Sets alarm timer. 00050 * Scans and checks for Squid input, and attempts to validate the user. 00051 */ 00052 00053 int 00054 main(int argc, char **argv) 00055 { 00056 char username[256]; 00057 char password[256]; 00058 char wstr[256]; 00059 int err = 0; 00060 00061 openlog("msnt_auth", LOG_PID, LOG_USER); 00062 setbuf(stdout, NULL); 00063 00064 /* Read configuration file. Abort wildly if error. */ 00065 if (OpenConfigFile() == 1) 00066 return 1; 00067 00068 /* 00069 * Read denied and allowed user files. 00070 * If they fails, there is a serious problem. 00071 * Check syslog messages. Deny all users while in this state. 00072 * The msntauth process should then be killed. 00073 */ 00074 if ((Read_denyusers() == 1) || (Read_allowusers() == 1)) { 00075 while (1) { 00076 memset(wstr, '\0', sizeof(wstr)); 00077 if (fgets(wstr, 255, stdin) == NULL) 00078 break; 00079 puts("ERR"); 00080 } 00081 return 1; 00082 } 00083 00084 /* 00085 * Make Check_forchange() the handle for HUP signals. 00086 * Don't use alarms any more. I don't think it was very 00087 * portable between systems. 00088 * XXX this should be sigaction() 00089 */ 00090 signal(SIGHUP, Check_forchange); 00091 00092 while (1) { 00093 int n; 00094 /* Read whole line from standard input. Terminate on break. */ 00095 memset(wstr, '\0', sizeof(wstr)); 00096 if (fgets(wstr, 255, stdin) == NULL) 00097 break; 00098 /* ignore this line if we didn't get the end-of-line marker */ 00099 if (NULL == strchr(wstr, '\n')) { 00100 err = 1; 00101 continue; 00102 } 00103 if (err) { 00104 syslog(LOG_WARNING, "oversized message"); 00105 puts("ERR"); 00106 err = 0; 00107 continue; 00108 } 00109 00110 /* 00111 * extract username and password. 00112 * XXX is sscanf() safe? 00113 */ 00114 username[0] = '\0'; 00115 password[0] = '\0'; 00116 n = sscanf(wstr, "%s %[^\n]", username, password); 00117 if (2 != n) { 00118 puts("ERR"); 00119 continue; 00120 } 00121 /* Check for invalid or blank entries */ 00122 if ((username[0] == '\0') || (password[0] == '\0')) { 00123 puts("ERR"); 00124 continue; 00125 } 00126 Checktimer(); /* Check if the user lists have changed */ 00127 00128 rfc1738_unescape(username); 00129 rfc1738_unescape(password); 00130 00131 /* 00132 * Check if user is explicitly denied or allowed. 00133 * If user passes both checks, they can be authenticated. 00134 */ 00135 if (Check_user(username) == 1) { 00136 syslog(LOG_INFO, "'%s' denied", username); 00137 puts("ERR"); 00138 } else if (QueryServers(username, password) == 0) 00139 puts("OK"); 00140 else { 00141 syslog(LOG_INFO, "'%s' login failed", username); 00142 puts("ERR"); 00143 } 00144 err = 0; 00145 } 00146 00147 return 0; 00148 }
Search
Introduction
- About Squid
- Why Squid?
- Squid Developers
- How to Help Out
- Getting Squid
- Donate
- Squid Deployment Case-Studies
Documentation
- FAQ | Wiki | Book
- Configuration Reference
- Configuration Guide - Visolve
- Configuration Examples
- Users guide
- Non-English
- Security Advisories
- More...
Support
- Bugzilla Database
- Mailing lists
- Contacting us
- Commercial services
- Project Sponsors
- Squid-based products
