=================================================================== RCS file: /home/cvs/OpenXM_contrib/gnuplot/Attic/plot.c,v retrieving revision 1.1 retrieving revision 1.1.1.3 diff -u -p -r1.1 -r1.1.1.3 --- OpenXM_contrib/gnuplot/Attic/plot.c 2000/01/09 17:00:54 1.1 +++ OpenXM_contrib/gnuplot/Attic/plot.c 2003/09/15 07:09:25 1.1.1.3 @@ -1,5 +1,5 @@ #ifndef lint -static char *RCSid = "$Id: plot.c,v 1.1 2000/01/09 17:00:54 maekawa Exp $"; +static char *RCSid = "$Id: plot.c,v 1.1.1.3 2003/09/15 07:09:25 ohara Exp $"; #endif /* GNUPLOT - plot.c */ @@ -34,14 +34,22 @@ static char *RCSid = "$Id: plot.c,v 1.1 2000/01/09 17: * to the extent permitted by applicable law. ]*/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include +#include #include "plot.h" #include "fit.h" #include "setshow.h" #include "fnproto.h" -#include +#ifdef HAVE_SYS_UTSNAME_H +# include +#endif + #if defined(MSDOS) || defined(DOS386) || defined(__EMX__) # include #endif @@ -84,9 +92,10 @@ char *call_args[10] = { NULL, NULL, NULL, NULL, NULL, char *infile_name = NULL; /* name of command file; NULL if terminal */ -#ifdef GNU_READLINE +#ifdef HAVE_LIBREADLINE extern char *rl_readline_name; extern int rl_complete_with_tilde_expansion; +extern char *rl_terminal_name; #endif #ifdef X11 @@ -105,9 +114,9 @@ char HelpFile[MAXPATH]; /* a longjmp buffer to get back to the command line */ #ifdef _Windows -static jmp_buf far command_line_env; +static JMP_BUF far command_line_env; #else -static jmp_buf command_line_env; +static JMP_BUF command_line_env; #endif static void load_rcfile __PROTO((void)); @@ -216,6 +225,8 @@ static struct udvt_entry udv_pi = { NULL, "pi", FALSE struct udvt_entry *first_udv = &udv_pi; struct udft_entry *first_udf = NULL; +static int exit_status = EXIT_SUCCESS; + #ifdef OS2 # define INCL_DOS # define INCL_REXXSAA @@ -252,15 +263,63 @@ int anint; #else term_reset(); (void) putc('\n', stderr); - longjmp(command_line_env, TRUE); /* return to prompt */ + LONGJMP(command_line_env, TRUE); /* return to prompt */ #endif } +#ifdef LINUXVGA +/* utility functions to ensure that setuid gnuplot + * assumes root privileges only for those parts + * of the code which require root rights. + * + * By "Dr. Werner Fink" + */ +static uid_t euid, ruid; +static gid_t egid, rgid; +static int asked_privi = 0; +void +drop_privilege() +{ + if (!asked_privi) { + euid = geteuid(); + egid = getegid(); + ruid = getuid(); + rgid = getgid(); + asked_privi = 1; + } + if (setegid(rgid) == -1) + (void) fprintf(stderr, "setegid(%d): %s\n", + (int) rgid, strerror(errno)); + if (seteuid(ruid) == -1) + (void) fprintf(stderr, "seteuid(%d): %s\n", + (int) ruid, strerror(errno)); +} + +void +take_privilege() +{ + if (!asked_privi) { + euid = geteuid(); + egid = getegid(); + ruid = getuid(); + rgid = getgid(); + asked_privi = 1; + } + if (setegid(egid) == -1) + (void) fprintf(stderr, "setegid(%d): %s\n", + (int) egid, strerror(errno)); + if (seteuid(euid) == -1) + (void) fprintf(stderr, "seteuid(%d): %s\n", + (int) euid, strerror(errno)); +} +#endif /* LINUXVGA */ + + /* a wrapper for longjmp so we can keep everything local */ void bail_to_command_line() { - longjmp(command_line_env, TRUE); + LONGJMP(command_line_env, TRUE); } #if defined(_Windows) || defined(_Macintosh) @@ -329,9 +388,10 @@ char **argv; unsigned int status[2] = { 1, 0 }; #endif -#ifdef GNU_READLINE +#ifdef HAVE_LIBREADLINE rl_readline_name = argv[0]; rl_complete_with_tilde_expansion = 1; + rl_terminal_name = getenv("TERM"); #endif #ifdef X11 @@ -371,7 +431,7 @@ char **argv; #endif gpoutfile = stdout; - (void) Gcomplex(&udv_pi.udv_value, Pi, 0.0); + (void) Gcomplex(&udv_pi.udv_value, M_PI, 0.0); init_memory(); @@ -396,6 +456,33 @@ char **argv; else noinputfiles = TRUE; + /* Need this before show_version is called for the first time */ + +#ifdef HAVE_SYS_UTSNAME_H + { + struct utsname uts; + + /* something is fundamentally wrong if this fails ... */ + if (uname(&uts) > -1) { +# ifdef _AIX + strcpy(os_name, uts.sysname); + sprintf(os_name, "%s.%s", uts.version, uts.release); +# elif defined(SCO) + strcpy(os_name, "SCO"); + strcpy(os_rel, uts.release); +# else + strcpy(os_name, uts.sysname); + strcpy(os_rel, uts.release); +# endif + } + } +#else /* ! HAVE_SYS_UTSNAME_H */ + + strcpy(os_name, OS); + strcpy(os_rel, ""); + +#endif /* HAVE_SYS_UTSNAME_H */ + if (interactive) show_version(stderr); @@ -407,7 +494,7 @@ char **argv; done(status[1]); #endif /* VMS */ - if (!setjmp(command_line_env)) { + if (!SETJMP(command_line_env, 1)) { /* first time */ interrupt_setup(); load_rcfile(); @@ -417,6 +504,9 @@ char **argv; fprintf(stderr, "\nTerminal type set to '%s'\n", term->name); } else { /* come back here from int_error() */ + if (interactive == FALSE) + exit_status = EXIT_FAILURE; + #ifdef AMIGA_SC_6_1 (void) rawcon(0); #endif @@ -472,7 +562,7 @@ char **argv; while (!com_line()); - /* interactive = FALSE; /* should this be here? */ + /* interactive = FALSE; */ /* should this be here? */ } else load_file(fopen(*argv, "r"), *argv, FALSE); @@ -499,7 +589,7 @@ char **argv; if (aesid > -1) atexit(appl_exit); #endif - return (IO_SUCCESS); + return (exit_status); } #if (defined(ATARI) || defined(MTOS)) && defined(__PUREC__) @@ -648,11 +738,11 @@ ULONG RexxInterface(PRXSTRING rxCmd, PUSHORT pusErr, P */ { int rc; - static jmp_buf keepenv; + static JMP_BUF keepenv; int cmdlen; - memcpy(keepenv, command_line_env, sizeof(jmp_buf)); - if (!setjmp(command_line_env)) { + memcpy(keepenv, command_line_env, sizeof(JMP_BUF)); + if (!SETJMP(command_line_env, 1)) { /* set variable input_line. * Watch out for line length of NOT_ZERO_TERMINATED strings ! */ cmdlen = rxCmd->strlength + 1; @@ -668,7 +758,7 @@ ULONG RexxInterface(PRXSTRING rxCmd, PUSHORT pusErr, P *pusErr = RXSUBCOM_ERROR; RexxSetHalt(getpid(), 1); } - memcpy(command_line_env, keepenv, sizeof(jmp_buf)); + memcpy(command_line_env, keepenv, sizeof(JMP_BUF)); return 0; } #endif