1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
|
#!/usr/local/Hughes/bin/lite
/*
** This script sets up the required databases and tables for the W3-Auth
** access control system.
*/
echo("\n");
echo("This script sets up the required databases and tables for the W3-Auth\n");
echo("access control system.\n\n");
/*
** Create the empty databases
*/
echo ("Creating the empty database ...");
if (system("/usr/local/Hughes/bin/msqladmin create w3-msql") != 0)
{
fatal("\nError : creating databases");
exit(1);
}
/*
** Connect to the server
*/
echo("\nW3-mSQL Setup\n-------------\n\n");
echo("Connecting to the mSQL server ... ");
$sock = msqlConnect();
if ($sock < 0)
{
fatal("Error : $ERRMSG\n");
}
if (msqlSelectDB($sock,"w3-msql") < 0)
{
fatal("Error : $ERRMSG\n");
}
echo ("connected.\n");
/*
** Create the auth tables
*/
echo("Creating the namespace table ... ");
if (msqlQuery($sock, " create table namespaces (
namespace char(50),
descr char(50))" ) < 0)
{
fatal("Error : $ERRMSG\n");
}
echo("done.\n");
echo("Creating the areas table ... ");
if (msqlQuery($sock, "create table areas (
name char(50),
url char(255),
namespace char(25))" ) < 0)
{
fatal("Error : $ERRMSG\n");
}
echo("done.\n");
echo("Creating the access control table ... ");
if (msqlQuery($sock, "create table area_acl (
name char(50),
offset int,
group char(20),
acl char(50),
namespace char(25))" ) < 0)
{
fatal("Error : $ERRMSG\n");
}
echo("done.\n");
echo("Creating the access control table index ... ");
if (msqlQuery($sock, "create index idx1 on area_acl (name)") < 0)
{
fatal("Error : $ERRMSG\n");
}
echo("done.\n");
echo("Creating the users table ... ");
if (msqlQuery($sock, "create table users (
namespace char(25),
uname char(20),
passwd char(20),
full_name char(50))") < 0)
{
fatal("Error : $ERRMSG\n");
}
echo("done.\n");
echo("Creating the users table index ... ");
if (msqlQuery($sock, "create unique index idx1 on users (
namespace,
uname)") < 0)
{
fatal("Error : $ERRMSG\n");
}
echo("done.\n");
echo("Creating the namespace perms table ... ");
if (msqlQuery($sock, "create table perms (
uname char(25),
namespace char(25),
level int)") < 0)
{
fatal("Error : $ERRMSG\n");
}
echo("done.\n");
echo("Creating the namespace perms table index ... ");
if (msqlQuery($sock, "create index idx1 on perms ( uname )") < 0)
{
fatal("Error : $ERRMSG\n");
}
echo("done.\n");
echo("Creating the group_members table ... ");
if (msqlQuery($sock, "create table group_members (
namespace char(25),
group char(20),
uname char(20))") < 0)
{
fatal("Error : $ERRMSG\n");
}
echo("done.\n");
echo("Creating the group_members table index ... ");
if (msqlQuery($sock, "create index idx1 on group_members (
namespace,
group)") < 0)
{
fatal("Error : $ERRMSG\n");
}
echo("done.\n");
echo("Creating the groups table ... ");
if (msqlQuery($sock, "create table groups (
namespace char(25),
group char(20),
descr char(50))") < 0)
{
fatal("Error : $ERRMSG\n");
}
echo("done.\n");
echo("Creating the groups table index ... ");
if (msqlQuery($sock, "create index idx1 on groups (
namespace,
group)") < 0)
{
fatal("Error : $ERRMSG\n");
}
echo("done.\n");
echo("Creating the group_admin table ... ");
if (msqlQuery($sock, "create table group_admin (
namespace char(25),
group char(20),
uname char(20))") < 0)
{
fatal("Error : $ERRMSG\n");
}
echo("done.\n");
echo("Creating the group_admin table index ... ");
if (msqlQuery($sock, "create index idx1 on group_admin (
namespace,
group)") < 0)
{
fatal("Error : $ERRMSG\n");
}
echo("done.\n");
/*
** Populate the data with some bootstrap info
*/
echo("Creating the W3-auth administrative namespace ... ");
if (msqlQuery($sock, "insert into namespaces values
('SuperUser', 'W3-mSQL Administrators')") < 0)
{
fatal("Error : $ERRMSG\n");
}
echo("done.\n");
/*
** Add a "super user" to the w3-msql auth tables
*/
echo ("\nAdding a \"super user\" to the w3-msql auth tables\n\n");
echo ("Username : ");
$user = readln($stdin);
$user = chop($user);
echo ("Full name : ");
$fullname = readln($stdin);
$fullname = chop($fullname);
echo ("Password : ");
$passwd = readln($stdin);
$passwd = chop($passwd);
$passwd = crypt($passwd,"AA");
if (msqlQuery($sock,"insert into users values
('SuperUser', '$user','$passwd','$fullname')") < 0)
{
fatal("Error : $ERRMSG\n");
}
if (msqlQuery($sock,"insert into perms values
('$user','SuperUser',255)") < 0)
{
fatal("Error : $ERRMSG\n");
}
msqlClose($sock);
echo("Done.\n\nSetup of W3-mSQL is complete\n\n");
|