All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

mkprojdir.in 2.75 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/usr/local/bin/perl -wT
use Mysql;
use English;

#
# Make a project directory hierarchy. Must be called as tbroot.
# Creates a directory rooted /proj/pid. The directory is setuid
# to the project leader, and setgid to the project gid. We get
# this info from the database.
#
# usage: mkprojdir <pid>
#

14 15 16
#
# Configure variables
#
17
my $TB       = "@prefix@";
18 19

my $PROJROOT = "/proj";
20
my $TFTPROOT = "/tftpboot";
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
my @DIRLIST  = ("exp", "images", "logs", "deltas", "tarfiles", "rpms");

#
# Untaint the path
# 
$ENV{'PATH'} = "/bin:/usr/bin";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

#
# Turn off line buffering on output
#
$| = 1;

#
# Load the Testbed support stuff. 
#
37 38
use lib "@prefix@/lib";
use libdb;
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

#
# Check args.
#
if ($#ARGV < 0) {
    die("Usage: mkprojdir <pid>\n");
}
my $pid = $ARGV[0];

#
# Untaint the argument.
#
if ($pid =~ /^([-\@\w.]+)$/) {
    $pid = $1;
}
else {
    die("Invalid pid '$pid' contains illegal characters.\n");
}

#
59
# Figure out who called us. Only root or people with admin status
60 61
# in the DB can run this script.
#
62 63
if ($UID && !TBAdmin($UID)) {
    die("mkprojdir: You must be root or a TB administrator\n");
64 65 66 67 68 69 70 71
}

#
# We need several bits of info from the database.
#
# * The project gid.
# * The project leader uid.
#
72 73 74
$db_result =
    DBQueryFatal("select unix_gid,head_uid from projects where pid='$pid'");

75 76 77 78 79 80 81
if ($db_result->numrows < 1) {	
    die("There is no project '$pid'.\n");
}
@row = $db_result->fetchrow_array();
my $gid  = $row[0];
my $head = $row[1];

82 83 84 85 86 87
#
# This acts as check (and we need the numeric uid) in case mkacct failed!
# 
my ($login,$pass,$uid) = getpwnam($head)
    or die "$head not in passwd file";

88 89 90 91 92 93 94
#
# Okay, do it.
#
if (! mkdir("$PROJROOT/$pid", 0770)) {
    die("Could not make directory $PROJROOT/$pid: $!\n");
}

95 96 97 98
if (! chmod(0770, "$PROJROOT/$pid")) {
    die("Could not chmod directory $PROJROOT/$pid: $!\n");
}

99 100 101 102 103
if (! chown($uid, $gid, "$PROJROOT/$pid")) {
    die("Could not chown $PROJROOT/$pid to $uid/$gid: $!\n");
}

#
104 105 106
# Make project subdirs.
#
foreach my $dir (@DIRLIST) {
107

108 109 110 111 112 113 114 115 116
    if (! mkdir("$PROJROOT/$pid/$dir", 0770)) {
	die("Could not make directory $PROJROOT/$pid/$dir: $!\n");
    }
    if (! chmod(0770, "$PROJROOT/$pid/$dir")) {
	die("Could not chmod directory $PROJROOT/$pid/$dir: $!\n");
    }
    if (! chown($uid, $gid, "$PROJROOT/$pid/$dir")) {
	die("Could not chown $PROJROOT/$pid/$dir to $uid/$gid: $!\n");
    }
117 118
}

119
#
120
# Create a tftp directory for oskit kernels.
121 122 123 124 125 126 127 128 129 130 131
# 
if (! mkdir("$TFTPROOT/proj/$pid", 0770)) {
    die("Could not make directory $TFTPROOT/proj/$pid: $!\n");
}
if (! chmod(0777, "$TFTPROOT/proj/$pid")) {
    die("Could not chmod directory $TFTPROOT/proj/$pid: $!\n");
}
if (! chown($uid, $gid, "$TFTPROOT/proj/$pid")) {
    die("Could not chown $TFTPROOT/proj/$pid to $uid/$gid: $!\n");
}

132 133
exit(0);