source: server/common/oursrc/sqladm/signup-sql.c @ 1

Last change on this file since 1 was 1, checked in by jbarnold, 18 years ago
File size: 1.7 KB
Line 
1/*
2 * signup-sql
3 * Copyright (C) 2006  Jeff Arnold <jbarnold@mit.edu>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18 *
19 * See /COPYRIGHT in this repository for more information.
20 */
21
22#include <stdlib.h>
23#include <stdio.h>
24#include <sys/types.h> // for getpwnam
25#include <pwd.h> // for getpwnam
26
27int main(int argc, char **argv) {
28        if(argc != 1) {
29                exit(1);
30        }
31
32        char uid[21]; // 64-bit uid requires 21
33        char gid[21]; // 64-bit gid requires 21
34        int retval = snprintf(uid, 21, "%d", getuid());
35        if(retval < 0 || retval >= 21) {
36                exit(1);
37        }
38        retval = snprintf(gid, 21, "%d", getgid());
39        if(retval < 0 || retval >= 21) {
40                exit(1);
41        }
42
43        char *v[5];
44#define SIGNUP_PATH "/afs/athena.mit.edu/contrib/sql/web_scripts/main/batch/signup.php"
45        v[0] = SIGNUP_PATH;
46        v[1] = getpwuid(getuid())->pw_name;
47        v[2] = uid;
48        v[3] = gid;
49        v[4] = NULL;
50
51        if(setregid(SQL_GID, SQL_GID) != 0) {
52                exit(1);
53        }
54        if(setreuid(SQL_UID, SQL_UID) != 0) {
55                exit(1);
56        }
57
58        execv(SIGNUP_PATH, v);
59        return 1;
60}
Note: See TracBrowser for help on using the repository browser.