[1] | 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 | |
---|
| 27 | int main(int argc, char **argv) { |
---|
| 28 | if(argc != 1) { |
---|
| 29 | exit(1); |
---|
| 30 | } |
---|
| 31 | |
---|
[3] | 32 | #define NUMBUF 5 |
---|
| 33 | #define BUFLEN 128 |
---|
| 34 | char buf[NUMBUF][BUFLEN]; |
---|
| 35 | char *env[NUMBUF+1]; |
---|
| 36 | int i = 0; |
---|
| 37 | snprintf(buf[i++], BUFLEN-1, "%s=%s", "HOME", "/home/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/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin"); |
---|
| 42 | for(i = 0; i < NUMBUF; i++) { |
---|
| 43 | env[i] = buf[i]; |
---|
| 44 | } |
---|
| 45 | env[i] = NULL; |
---|
| 46 | |
---|
[1] | 47 | char uid[21]; // 64-bit uid requires 21 |
---|
| 48 | char gid[21]; // 64-bit gid requires 21 |
---|
| 49 | int retval = snprintf(uid, 21, "%d", getuid()); |
---|
| 50 | if(retval < 0 || retval >= 21) { |
---|
| 51 | exit(1); |
---|
| 52 | } |
---|
| 53 | retval = snprintf(gid, 21, "%d", getgid()); |
---|
| 54 | if(retval < 0 || retval >= 21) { |
---|
| 55 | exit(1); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | char *v[5]; |
---|
| 59 | #define SIGNUP_PATH "/afs/athena.mit.edu/contrib/sql/web_scripts/main/batch/signup.php" |
---|
| 60 | v[0] = SIGNUP_PATH; |
---|
| 61 | v[1] = getpwuid(getuid())->pw_name; |
---|
| 62 | v[2] = uid; |
---|
| 63 | v[3] = gid; |
---|
| 64 | v[4] = NULL; |
---|
| 65 | |
---|
| 66 | if(setregid(SQL_GID, SQL_GID) != 0) { |
---|
| 67 | exit(1); |
---|
| 68 | } |
---|
| 69 | if(setreuid(SQL_UID, SQL_UID) != 0) { |
---|
| 70 | exit(1); |
---|
| 71 | } |
---|
| 72 | |
---|
[3] | 73 | execle(SIGNUP_PATH, v, env); |
---|
[1] | 74 | return 1; |
---|
| 75 | } |
---|