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

Last change on this file since 89 was 5, checked in by jbarnold, 18 years ago
fixed incorrect HOME and improved PATH
File size: 2.2 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#define NUMBUF 5
33#define BUFLEN 256
34        char buf[NUMBUF][BUFLEN];
35        char *env[NUMBUF+1];
36        int i = 0;
37        snprintf(buf[i++], BUFLEN-1, "%s=%s", "HOME", "/afs/athena.mit.edu/contrib/sql");
38        snprintf(buf[i++], BUFLEN-1, "%s=%s", "TERM", "xterm");
39        snprintf(buf[i++], BUFLEN-1, "%s=%s", "USER", "sql");
40        snprintf(buf[i++], BUFLEN-1, "%s=%s", "SHELL", "/usr/local/bin/bash");
41        snprintf(buf[i++], BUFLEN-1, "%s=%s", "PATH", "/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin");
42        for(i = 0; i < NUMBUF; i++) {
43                env[i] = buf[i];
44        }
45        env[i] = NULL;
46
47        char uid_str[21]; // 64-bit uid requires 21
48        char gid_str[21]; // 64-bit gid requires 21
49        int uid_num = getuid();
50        int retval = snprintf(uid_str, 21, "%d", uid_num);
51        if(retval < 0 || retval >= 21) {
52                exit(1);
53        }
54        retval = snprintf(gid_str, 21, "%d", getgid());
55        if(retval < 0 || retval >= 21) {
56                exit(1);
57        }
58
59        if(setregid(SQL_GID, SQL_GID) != 0) {
60                exit(1);
61        }
62        if(setreuid(SQL_UID, SQL_UID) != 0) {
63                exit(1);
64        }
65
66#define SIGNUP_PATH "/afs/athena.mit.edu/contrib/sql/web_scripts/main/batch/signup.php"
67        execle(SIGNUP_PATH, SIGNUP_PATH, getpwuid(uid_num)->pw_name, uid_str, gid_str, NULL, env);
68        return 1;
69}
Note: See TracBrowser for help on using the repository browser.