summaryrefslogtreecommitdiff
path: root/obsolete/fonts/utilities/safemtpk/maketex.c
blob: 0461afd3dcf02d4b2254c4815e145d7cbabdab4c (plain)
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
/****************************************************/
/*                                                  */
/*  Executable wrapper for MakeTeX... programs.     */
/*  Calls its namesake from TOOLS directory.        */
/*  Provide links with different names to make it   */
/*  multipurpose.                                   */
/*                                                  */
/*  Michal Jaegermann, Feb 11 1995                  */
/*                                                  */
/****************************************************/

#include <unistd.h>
#include <string.h>
#include <stdlib.h>

#define VERSION_S "0.2"
/*
 * If you do not have ANSI compiler you may use
 * an "explicit"single string in TOOLS define; this
 * is just a way to make future modifications easier.
 */
#define TOOLS   "/usr/local/tex/scripts-" VERSION_S "/bin/"
#define ASIZE  120

/*
 * This is a list of names under which we are willing
 * to execute. It has be NULL terminated.
 */
const char *accepted[] = {
    "MakeTeXPK",
    "MakeTeXTFM",
    "MakeTeXMF",
    NULL
};

int
main(int argc, char **argv)
{
    char doer[ASIZE] = TOOLS;
    int idx = 0;
    /*
     * If your compiler is broken and the construction below
     * does not work then "tail = strchr(doer, '\0');", or
     * equivalent, will serve as well.
     */
    char *tail = doer + (sizeof(TOOLS) - 1);
    char *start;

    /* find our base name */
    start = (start = strrchr(argv[0], '/')) ?
                               (start + 1) : argv[0];
    /* check if we are on the list */
    while (1) {
	if (NULL == accepted[idx])
	    exit(1);          /* not on the list - bye-bye */
	if (0 == strcmp(accepted[idx], start))
	    break;            /* this is ours */
	idx += 1;
    }
    /*
     * Set pretty bland, but hopefuly secure environment;
     * we intend to run this program 'suid'.
     */
    setenv("PATH", "/bin:/usr/bin", 1);
    setenv("IFS", " ", 1);
    /*
     * You may want/need some other calls to setenv().
     * For example, if your system has an environment
     * variable pointing to shared libraries it should
     * be set here.
     */

    /*
     * Attach our name at the end of a directory string.
     * This assumes that real scripts in TOOLS directory
     * will be called by their own names (but indirectly)
     */
    strcpy(tail, start);
    setuid(geteuid());		/* we want priviledges of
				   an owner of this program */
    return execv(doer, argv);   /* do it and tell results   */
}

/*
 * Local variables:
 * compile-command: "gcc -s -O6 -fomit-frame-pointer -Wall -pipe -m486 -Xlinker -N -o ../MakeTeXPK maketex.c"
 * End:
 */