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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
|
/********************************************************************
* $Author: lindner $
* $Revision: 3.12 $
* $Date: 1995/09/25 05:02:39 $
* $Source: /home/arcwelder/GopherSrc/CVS/gopher+/gopherd/site.c,v $
* $State: Exp $
*
* Paul Lindner, University of Minnesota CIS.
*
* Copyright 1991, 1992 by the Regents of the University of Minnesota
* see the file "Copyright" in the distribution for conditions of use.
*********************************************************************
* MODULE: site.c
* Routines to build up a table of hostnames and access levels
*********************************************************************
* Revision History:
* $Log: site.c,v $
* Revision 3.12 1995/09/25 05:02:39 lindner
* Convert to ANSI C
*
* Revision 3.11 1995/02/17 23:15:30 lindner
* Fix for access: lines
*
* Revision 3.10 1995/02/02 17:13:55 lindner
* Fix memory leaks
*
* Revision 3.9 1994/07/22 22:56:20 lindner
* More NO_AUTH stuff..
*
* Revision 3.8 1994/07/22 22:25:51 lindner
* NO_AUTHENTICATION mods
*
* Revision 3.7 1994/07/19 20:24:12 lindner
* Use local Locale.h
*
* Revision 3.6 1994/05/02 07:41:15 lindner
* Mods to use setlocale()
*
* Revision 3.5 1994/03/17 21:18:24 lindner
* Massive reworking of access limits
*
* Revision 3.4 1994/03/17 04:27:49 lindner
* Additions for maxsessions
*
* Revision 3.3 1993/08/20 18:03:14 lindner
* Mods to allow gopherd.conf files control ftp gateway access
*
* Revision 3.2 1993/07/27 05:27:57 lindner
* Mondo Debug overhaul from Mitra
*
* Revision 3.1.1.1 1993/02/11 18:02:53 lindner
* Gopher+1.2beta release
*
* Revision 1.2 1993/02/09 22:29:23 lindner
* added util.h to includes
*
* Revision 1.1 1992/12/10 23:13:27 lindner
* gopher 1.1 release
*
*
*********************************************************************/
#ifndef NO_AUTHENTICATION
#include "site.h"
#include "Malloc.h"
#include "Locale.h"
#include <ctype.h>
#include "util.h"
#include "Debug.h"
static Site *
SiteNew()
{
Site *temp;
temp = (Site *) malloc(sizeof(Site));
if (temp == NULL)
return(NULL);
temp->domain = STRnew();
STRinit(temp->domain);
SITEsetLevel(temp, ACC_FULL);
SITEsetisnum(temp, FALSE);
SITEsetmaxsessions(temp, -1);
return(temp);
}
static void
SiteDestroy(Site *site)
{
STRdestroy(site->domain);
free(site);
}
static void
Sitecpy(Site *site1, Site *site2)
{
STRcpy(site1->domain, site2->domain);
site1->Level = site2->Level;
site1->isnum = site2->isnum;
site1->maxsessions = site2->maxsessions;
}
static void
SiteSet(Site *site, char *dom, Accesslevel access, int maxsess)
{
STRset(site->domain, dom);
site->Level = access;
if (isdigit(*dom))
site->isnum = TRUE;
else
site->isnum = FALSE;
site->maxsessions = maxsess;
}
/******************************************************/
SiteArray *
SiteArrayNew()
{
SiteArray *temp;
temp = DAnew(20, SiteNew, NULL, SiteDestroy, Sitecpy);
return(temp);
}
static void
SiteArrayAdd(SiteArray *sitearr, char *name, Accesslevel Level, int sessions)
{
Site *temp;
temp = SiteNew();
SiteSet(temp, name, Level, sessions);
SiteArrPush(sitearr, temp);
SiteDestroy(temp);
return;
}
/*
* Find the default access level
*/
Accesslevel
SiteDefAccess(SiteArray *sitearr)
{
int i;
Site *temp;
for (i=0; i< DAgetTop(sitearr); i++) {
temp = SiteArrgetEntry(sitearr, i);
if (strcmp(SITEgetDomain(temp), "default") == 0)
return(SITEgetLevel(temp));
}
return(ACC_UNKNOWN);
}
/*
* Tries to find a match in sitearr for "hostname" or ipnum, then tests the
* accesslevel against "mask".
*
* If it finds it, it returns the result of the search
*
* If it doesn't it tests agains the "default" item
*
*/
AccessResult
SiteAccess(
SiteArray *sitearr,
char *hostname,
char *ipnum,
Accesslevel mask,
int sessions)
{
int i;
Site *temp;
Accesslevel defaccess = ACC_FULL, level;
int defmaxsess = -1;
int maxsess;
if (hostname == NULL && ipnum == NULL)
/*** ??? We need to compare *something* ***/
return(SITE_UNDEF);
for (i=0; i< DAgetTop(sitearr); i++) {
temp = SiteArrgetEntry(sitearr, i);
Debug("Testing for %s\n", STRget(temp->domain));
if (strcmp(SITEgetDomain(temp), "default") == 0) {
defaccess = SITEgetLevel(temp);
defmaxsess = SITEmaxsessions(temp);
} else if (SITEisnum(temp) == TRUE) {
/*** Check for a match with the domain name
from the beginning ***/
int iplen, domainlen;
iplen = strlen(ipnum);
domainlen = strlen(STRget(temp->domain));
if (iplen >domainlen)
iplen = domainlen;
if (strncmp(ipnum, SITEgetDomain(temp), iplen) == 0) {
break;
}
} else {
/*** Check for a match from the end ***/
/*** It's a domain name, not an ip number ***/
int namelen, domainlen;
namelen = strlen(hostname);
domainlen = strlen(SITEgetDomain(temp));
/*** don't compare if incoming name is shorter than domain ***/
if (domainlen <= namelen)
if (strcasecmp((hostname+namelen-domainlen),
SITEgetDomain(temp))==0)
break;
}
}
if (i == DAgetTop(sitearr)) {
/*** Hmmm, didn't find a match, return "default" val ***/
level = defaccess;
maxsess = defmaxsess;
} else {
/** Otherwise we found a match.. **/
level = SITEgetLevel(temp);
maxsess = SITEmaxsessions(temp);
}
if (sessions > 0) {
if (maxsess < sessions && maxsess > 0)
return(SITE_TOOBUSY);
}
if ((level & mask) == mask)
return(SITE_OK);
else
return(SITE_NOACCESS);
}
/*
* process a site description line.
*/
boolean
SiteProcessLine(SiteArray *sitearr, char *inputline, Accesslevel defaccess)
{
char name[256];
char *namep = name;
Accesslevel level = defaccess;
int maxsess = 0;
/*** the first word is the domain/ip# ***/
while (*inputline == ' ' || *inputline == '\t')
inputline++;
while (*inputline != ' ' && *inputline != '\t') {
*namep = *inputline;
namep++;
inputline++;
}
*namep = '\0'; /*** Terminate it ***/
if (namep == name)
return(FALSE); /*** bad line ***/
while (*inputline != '\0') {
if (*inputline == ' ' || *inputline == '\t' || *inputline == ',') {
inputline++;
if (*inputline == '!')
inputline++;
switch (*inputline) {
case '0': case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9':
/** Maxsessions **/
while (*inputline <= '9' && '0' <= *inputline) {
maxsess = maxsess * 10 + (*inputline - '0');
inputline++;
}
break;
case 'b':
/** Browse **/
if (*(inputline -1) == '!')
level &= (ACC_SEARCH | ACC_READ | ACC_FTP);
else
level |= ACC_BROWSE;
break;
case 'r':
/*** Read ***/
if (*(inputline -1) == '!')
level &= (ACC_BROWSE | ACC_SEARCH | ACC_FTP);
else
level |= ACC_READ;
break;
case 's':
/*** Search ***/
if (*(inputline -1) == '!')
level &= (ACC_BROWSE | ACC_READ | ACC_FTP);
else
level |= ACC_SEARCH;
break;
case 'f':
/*** FTP ***/
if (*(inputline -1) == '!')
level &= (ACC_BROWSE | ACC_READ | ACC_SEARCH);
else
level |= ACC_FTP;
break;
}
} else
inputline++;
}
SiteArrayAdd(sitearr, name, level, maxsess);
return(TRUE);
}
#else
#endif
|