diff options
author | Kaleb Keithley <kaleb@freedesktop.org> | 2003-11-14 16:48:57 +0000 |
---|---|---|
committer | Kaleb Keithley <kaleb@freedesktop.org> | 2003-11-14 16:48:57 +0000 |
commit | a3101452dc6f4ef01c328fad7e18685363937bcf (patch) | |
tree | ddb3ef090426319f8d7a6a999155cb84853363f9 /process.c | |
parent | 511f5a05d0cc763d60b6b39584ea29b287cb801c (diff) |
XFree86 4.3.0.1xf86-4_3_99_903_specialxf86-4_3_99_902xf86-4_3_99_901xf86-4_3_99_16xf86-4_3_0_1xf86-012804-2330PRE_xf86-4_3_0_1
Diffstat (limited to 'process.c')
-rw-r--r-- | process.c | 86 |
1 files changed, 71 insertions, 15 deletions
@@ -28,13 +28,13 @@ in this Software without prior written authorization from The Open Group. * Modified into "iceauth" : Ralph Mor, X Consortium */ +/* $XFree86: xc/programs/iceauth/process.c,v 3.8 2002/05/31 18:46:07 dawes Exp $ */ + #include "iceauth.h" #include <ctype.h> #include <errno.h> -#ifdef X_NOT_STDC_ENV -extern int errno; -#endif - +#include <sys/types.h> +#include <sys/stat.h> #include <signal.h> #define SECURERPC "SUN-DES-1" @@ -51,11 +51,14 @@ typedef struct _AuthList { /* linked list of entries */ #define add_to_list(h,t,e) {if (t) (t)->next = (e); else (h) = (e); (t) = (e);} +typedef int (*ProcessFunc)(char *, int, int, char **); +typedef int (*DoFunc)(char *, int, IceAuthFileEntry *, char *); + typedef struct _CommandTable { /* commands that are understood */ char *name; /* full name */ int minlen; /* unique prefix */ int maxlen; /* strlen(name) */ - int (*processfunc)(); /* handler */ + ProcessFunc processfunc; /* handler */ char *helptext; /* what to print for help */ } CommandTable; @@ -80,9 +83,39 @@ static char *stdout_filename = "(stdout)"; /* for messages */ static char *Yes = "yes"; /* for messages */ static char *No = "no"; /* for messages */ -static int do_list(), do_merge(), do_extract(), do_add(), do_remove(); -static int do_help(), do_source(), do_info(), do_exit(); -static int do_quit(), do_questionmark(); +static char *copystring ( char *src ); +static int binaryEqual ( char *a, char *b, unsigned len ); +static void prefix ( char *fn, int n ); +static void badcommandline ( char *cmd ); +static char *skip_space ( char *s ); +static char *skip_nonspace ( char *s ); +static char **split_into_words ( char *src, int *argcp ); +static FILE *open_file ( char **filenamep, char *mode, Bool *usedstdp, char *srcfn, int srcln, char *cmd ); +static int read_auth_entries ( FILE *fp, AuthList **headp, AuthList **tailp ); +static int cvthexkey ( char *hexstr, char **ptrp ); +static int dispatch_command ( char *inputfilename, int lineno, int argc, char **argv, CommandTable *tab, int *statusp ); +static void die ( int sig ); +static void catchsig ( int sig ); +static void register_signals ( void ); +static int write_auth_file ( char *tmp_nam ); +static void fprintfhex ( FILE *fp, unsigned int len, char *cp ); +static int dump_entry ( char *inputfilename, int lineno, IceAuthFileEntry *auth, char *data ); +static int extract_entry ( char *inputfilename, int lineno, IceAuthFileEntry *auth, char *data ); +static int match_auth ( IceAuthFileEntry *a, IceAuthFileEntry *b, int *authDataSame ); +static int merge_entries ( AuthList **firstp, AuthList *second, int *nnewp, int *nreplp, int *ndupp ); +static int search_and_do ( char *inputfilename, int lineno, int start, int argc, char *argv[], DoFunc do_func, char *data ); +static int remove_entry ( char *inputfilename, int lineno, IceAuthFileEntry *auth, char *data ); +static int do_help ( char *inputfilename, int lineno, int argc, char **argv ); +static int do_questionmark ( char *inputfilename, int lineno, int argc, char **argv ); +static int do_list ( char *inputfilename, int lineno, int argc, char **argv ); +static int do_merge ( char *inputfilename, int lineno, int argc, char **argv ); +static int do_extract ( char *inputfilename, int lineno, int argc, char **argv ); +static int do_add ( char *inputfilename, int lineno, int argc, char **argv ); +static int do_remove ( char *inputfilename, int lineno, int argc, char **argv ); +static int do_info ( char *inputfilename, int lineno, int argc, char **argv ); +static int do_exit ( char *inputfilename, int lineno, int argc, char **argv ); +static int do_quit ( char *inputfilename, int lineno, int argc, char **argv ); +static int do_source ( char *inputfilename, int lineno, int argc, char **argv ); static CommandTable command_table[] = { /* table of known commands */ { "add", 2, 3, do_add, @@ -465,12 +498,15 @@ static Bool dieing = False; #define _signal_t void #endif +/* poor man's puts(), for under signal handlers */ +#define WRITES(fd, S) (void)write((fd), (S), strlen((S))) + /* ARGSUSED */ static _signal_t die (sig) int sig; { dieing = True; - exit (auth_finalize ()); + _exit (auth_finalize ()); /* NOTREACHED */ #ifdef SIGNALRETURNSINT return -1; /* for picky compilers */ @@ -483,7 +519,15 @@ static _signal_t catchsig (sig) #ifdef SYSV if (sig > 0) signal (sig, die); /* re-establish signal handler */ #endif - if (verbose && iceauth_modified) printf ("\r\n"); + /* + * fileno() might not be reentrant, avoid it if possible, and use + * stderr instead of stdout + */ +#ifdef STDERR_FILENO + if (verbose && iceauth_modified) WRITES(STDERR_FILENO, "\r\n"); +#else + if (verbose && iceauth_modified) WRITES(fileno(stderr), "\r\n"); +#endif die (sig); /* NOTREACHED */ #ifdef SIGNALRETURNSINT @@ -639,8 +683,20 @@ int auth_finalize () if (iceauth_modified) { if (dieing) { if (verbose) { - printf ("Aborting changes to authority file %s\n", - iceauth_filename); + /* + * called from a signal handler -- printf is *not* reentrant; also + * fileno() might not be reentrant, avoid it if possible, and use + * stderr instead of stdout + */ +#ifdef STDERR_FILENO + WRITES(STDERR_FILENO, "\nAborting changes to authority file "); + WRITES(STDERR_FILENO, iceauth_filename); + WRITES(STDERR_FILENO, "\n"); +#else + WRITES(fileno(stderr), "\nAborting changes to authority file "); + WRITES(fileno(stderr), iceauth_filename); + WRITES(fileno(stderr), "\n"); +#endif } } else if (!iceauth_allowed) { fprintf (stderr, @@ -659,7 +715,7 @@ int auth_finalize () ProgramName, temp_name); } else { (void) unlink (iceauth_filename); -#ifdef WIN32 +#if defined(WIN32) || defined(__UNIXOS2__) if (rename(temp_name, iceauth_filename) == -1) #else if (link (temp_name, iceauth_filename) == -1) @@ -897,7 +953,7 @@ static int search_and_do (inputfilename, lineno, start, int start; int argc; char *argv[]; - int (*do_func)(); + DoFunc do_func; char *data; { int i; @@ -1237,7 +1293,7 @@ static int do_add (inputfilename, lineno, argc, argv) char *authdata_hex; char *authdata; int protodata_len, authdata_len; - IceAuthFileEntry *auth; + IceAuthFileEntry *auth = NULL; AuthList *list; int status = 0; |