~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to trampoline/trampoline.c

  • Committer: mattgiuca
  • Date: 2007-12-21 00:10:32 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:110
setup.py: Added to trampoline/conf.h an "allowed_uids" array. Asks the user
    for a single allowed UID.
trampoline/trampoline.c: Checks this array against the current UID who called
    the program, and exits early unless the UID is root, or on the whitelist.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
 
54
54
#define UID_ROOT        0
55
55
 
 
56
/* Returns TRUE if the given uid is allowed to execute trampoline.
 
57
 * Only root or the web server should be allowed to execute.
 
58
 * This is determined by the whitelist allowed_uids in conf.h.
 
59
 */
 
60
int uid_allowed(int uid)
 
61
{
 
62
    int i;
 
63
    /* root is always allowed to execute trampoline */
 
64
    if (uid == 0)
 
65
        return 1;
 
66
    /* loop over all allowed_uids */
 
67
    for (i=(sizeof(allowed_uids)/sizeof(*allowed_uids))-1; i>=0; i--)
 
68
    {
 
69
        if (allowed_uids[i] == uid)
 
70
            return 1;
 
71
    }
 
72
    /* default to disallowing */
 
73
    return 0;
 
74
}
 
75
 
56
76
int main(int argc, char* const argv[])
57
77
{
58
78
    char* jailpath;
59
79
    int uid;
 
80
 
 
81
    /* Disallow execution from all users but the whitelisted ones, and root */
 
82
    if (!uid_allowed(getuid()))
 
83
    {
 
84
        fprintf(stderr, "only the web server may execute trampoline\n");
 
85
        exit(1);
 
86
    }
 
87
 
60
88
    /* Args check and usage */
61
89
    if (argc < MIN_ARGC)
62
90
    {