📄 security.c
字号:
/*--------------------------------------------------------------------*/
/* s e c u r i t y . c */
/* */
/* Security routines for UUPC/extended */
/* */
/* Copyright (c) 1991, Andrew H. Derbyshire */
/* See README.PRN for additional copyrights and restrictions */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* RCS Information */
/*--------------------------------------------------------------------*/
/*
* $Id: security.c 1.9 1993/10/03 20:37:34 ahd Exp $
*
* Revision history:
* $Log: security.c $
* Revision 1.9 1993/10/03 20:37:34 ahd
* Lower case all strings loaded into directory array
*
* Revision 1.8 1993/09/20 04:38:11 ahd
* TCP/IP support from Dave Watt
* 't' protocol support
* OS/2 2.x support
*
* Revision 1.7 1993/08/03 03:11:49 ahd
* Make missing directories non-fatal
*
* Revision 1.6 1993/05/06 03:41:48 ahd
* Use NULL to denote current directory, not "."
*
* Revision 1.5 1993/04/11 00:31:04 ahd
* Global edits for year, TEXT, etc.
*
* Revision 1.4 1993/03/06 22:48:23 ahd
* Re-do compare of sort to void bug in some qsort() functions
*
* Revision 1.3 1992/11/22 20:58:55 ahd
* Normalize directories as read
* Use strpool to allocate const strings
*
* Revision 1.2 1992/11/19 02:57:31 ahd
* drop rcsid
*
* Revision 1.1 1992/11/16 05:00:26 ahd
* Initial revision
*
*/
/*--------------------------------------------------------------------*/
/* System include files */
/*--------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <sys/types.h> /* Only really needed for MS C */
#include <sys/stat.h>
#include <time.h>
#include <direct.h>
/*--------------------------------------------------------------------*/
/* UUPC/extended include files */
/*--------------------------------------------------------------------*/
#include "lib.h"
#include "hostable.h"
#include "security.h"
#include "usertabl.h"
#include "expath.h"
#include "hlib.h"
/*--------------------------------------------------------------------*/
/* Local defines */
/*--------------------------------------------------------------------*/
static boolean InitEntry( char *buf, const char *fname);
static size_t InitDir( char *directories,
const REMOTE_ACCESS access,
const boolean grant,
struct HostSecurity *anchor,
size_t max_elements );
int dircmp( const void *a , const void *b );
/*--------------------------------------------------------------------*/
/* Global varables */
/*--------------------------------------------------------------------*/
struct HostSecurity *securep = NULL;
static struct HostSecurity *default_security = NULL;
static char drive[] = "C:";
currentfile();
/*--------------------------------------------------------------------*/
/* L o a d S e c u r i t y */
/* */
/* Initialize security processing; returns TRUE if security */
/* initialized, otherewise FALSE */
/*--------------------------------------------------------------------*/
boolean LoadSecurity( void )
{
char fname[FILENAME_MAX];
char buffer[BUFSIZ*4]; /* Allows around 2K for the data */
struct HostTable *hostp;
FILE *stream;
/*--------------------------------------------------------------------*/
/* Generate a filename for the permissions file and open it */
/*--------------------------------------------------------------------*/
mkfilename(fname, E_confdir, PERMISSIONS);
stream = FOPEN( fname, "r",TEXT_MODE);
if ( stream == NULL ) /* Did the file open? */
{ /* No --> Report failure to caller */
printerr( fname );
return FALSE;
} /* ( stream == NULL ) */
/*--------------------------------------------------------------------*/
/* Get current drive for normalizing names */
/*--------------------------------------------------------------------*/
getcwd( buffer, sizeof buffer );
*drive = *buffer;
/*--------------------------------------------------------------------*/
/* Begin processing the PERMISSIONS file */
/*--------------------------------------------------------------------*/
while ( !feof( stream ) )
{
char *next = buffer;
/*--------------------------------------------------------------------*/
/* Build up the buffer to be processed */
/*--------------------------------------------------------------------*/
*next = '\0';
while( fgets( next, sizeof buffer - strlen(next), stream ) != NULL)
{
if ((*next == '#') || (*next == '\n'))
{
*next = '\0';
continue;
}
next = next + strlen( next ) - 1;
if (*next == '\n')
*next-- = '\0';
else if (!feof( stream )) /* Did we hit EOF? */
{ /* No --> Presume the buffer overflowed*/
printmsg(0,"LoadSecurity: buffer overflow while reading %s",
fname);
fclose( stream );
return FALSE;
}
while( isspace( *next )) /* Dump trailing white space */
*next-- = '\0';
if (*next == '\\')
*next = '\0';
else
break;
} /* while( fgets( next, sizeof available, stream )) != NULL)) */
/*--------------------------------------------------------------------*/
/* Done read the data; verify we had no errors */
/*--------------------------------------------------------------------*/
if (ferror( stream ))
{
printerr( fname );
clearerr( stream );
return FALSE;
} /* if */
/*--------------------------------------------------------------------*/
/* Build entries for one permissions entry */
/*--------------------------------------------------------------------*/
printmsg(10,"Buffer is \"%s\"", buffer );
if ((*next != '\0') && !InitEntry( buffer , fname))
{
fclose( stream );
return FALSE;
}
} /* while ( !feof( stream ) ) */
/*--------------------------------------------------------------------*/
/* Initialize local host entry */
/*--------------------------------------------------------------------*/
hostp = checkname( E_nodename );
if ( hostp == NULL )
panic();
hostp->hsecure = malloc( sizeof *hostp->hsecure );
checkref( hostp->hsecure );
memset( hostp->hsecure , '\0', sizeof *hostp->hsecure);
/* Clear pointers */
hostp->hsecure->local = TRUE;
/*--------------------------------------------------------------------*/
/* Return to caller */
/*--------------------------------------------------------------------*/
fclose( stream );
return TRUE;
} /* LoadSecurity */
/*--------------------------------------------------------------------*/
/* I n i t i a l i z e E n t r y */
/* */
/* Initialize a single permissions file entry */
/*--------------------------------------------------------------------*/
static boolean InitEntry( char *buf, const char *fname)
{
/*--------------------------------------------------------------------*/
/* Configuration variables */
/*--------------------------------------------------------------------*/
static char *myname, *validate, *commands;
static char *callback, *xpubdir, *machine, *noread, *nowrite;
static char *request, *read, *sendfiles, *write, *logname;
static CONFIGTABLE securetable[] = {
{ "callback", &callback, B_TOKEN | B_UUXQT } ,
{ "commands", &commands, B_CLIST | B_UUXQT } ,
{ "logname", &logname, B_TOKEN | B_UUXQT } ,
{ "machine", &machine, B_TOKEN | B_UUXQT | B_MALLOC } ,
{ "myname", &myname, B_TOKEN | B_UUXQT } ,
{ "pubdir", &xpubdir, B_PATH | B_UUXQT } ,
{ "noread", &noread, B_TOKEN | B_UUXQT | B_MALLOC } ,
{ "nowrite", &nowrite, B_TOKEN | B_UUXQT | B_MALLOC } ,
{ "read", &read, B_TOKEN | B_UUXQT | B_MALLOC} ,
{ "request", &request, B_TOKEN | B_UUXQT } ,
{ "sendfiles", &sendfiles, B_TOKEN | B_UUXQT } ,
{ "validate", &validate, B_CLIST | B_UUXQT } ,
{ "write", &write, B_TOKEN | B_UUXQT | B_MALLOC } ,
{ nil(char) }
}; /* securetable */
struct HostSecurity *anchor = malloc( sizeof *anchor );
/*--------------------------------------------------------------------*/
/* Default list of allowed commands */
/*--------------------------------------------------------------------*/
static char *command_list[] = { "rmail", "rnews" , NULL } ;
/*--------------------------------------------------------------------*/
/* Other variables */
/*--------------------------------------------------------------------*/
boolean success = TRUE;
CONFIGTABLE *tptr;
char *token = buf;
char *parameter;
struct UserTable *userp;
struct HostTable *hostp;
size_t max_elements = 16;
/*--------------------------------------------------------------------*/
/* Initialize the security structure */
/*--------------------------------------------------------------------*/
checkref( anchor );
memset( anchor , '\0', sizeof *anchor); /* Clear pointers */
/*--------------------------------------------------------------------*/
/* Initialize the table */
/*--------------------------------------------------------------------*/
for (tptr = securetable; tptr->sym != nil(char); tptr++)
if (tptr->bits & (B_TOKEN | B_STRING | B_LIST| B_CLIST))
*(tptr->loc) = nil(char);
/*--------------------------------------------------------------------*/
/* Parse the information in the table */
/*--------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -