- #if 0
- //
- strcpy(input, Username);
- strcpy(input, Salt);
- // TODO: Get user's SHA-1 hash
- sprintf(tmp, "uid=%s", Username);
- ldap_search_s(ld, "", LDAP_SCOPE_BASE, tmp, "userPassword", 0, res);
-
- sprintf(input+ofs, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
- h[ 0], h[ 1], h[ 2], h[ 3], h[ 4], h[ 5], h[ 6], h[ 7], h[ 8], h[ 9],
- h[10], h[11], h[12], h[13], h[14], h[15], h[16], h[17], h[18], h[19]
- );
- // Then create the hash from the provided salt
- // Compare that with the provided hash
- #endif
+ // Read arguments
+ username = Args;
+ while( *username == ' ' ) username ++;
+ space = strchr(username, ' ');
+ if(space) *space = '\0';
+
+ // Try to create user
+ if( Bank_CreateUser(username) == -1 ) {
+ sendf(Client->Socket, "404 User exists\n");
+ return ;
+ }
+
+ sendf(Client->Socket, "200 User Added\n");
+}
+
+void Server_Cmd_USERFLAGS(tClient *Client, char *Args)
+{
+ char *username, *flags;
+ char *space;
+ int mask=0, value=0;
+ int uid;
+
+ // Check permissions
+ if( !(Bank_GetFlags(Client->UID) & USER_FLAG_WHEEL) ) {
+ sendf(Client->Socket, "403 Not Wheel\n");
+ return ;
+ }
+
+ // Read arguments
+ // - Username
+ username = Args;
+ while( *username == ' ' ) username ++;
+ space = strchr(username, ' ');
+ if(!space) {
+ sendf(Client->Socket, "407 USER_FLAGS requires 2 arguments, 1 given\n");
+ return ;
+ }
+ *space = '\0';
+ // - Flags
+ flags = space + 1;
+ while( *flags == ' ' ) flags ++;
+ space = strchr(flags, ' ');
+ if(space) *space = '\0';
+
+ // Get UID
+ uid = Bank_GetUserID(username);
+ if( uid == -1 ) {
+ sendf(Client->Socket, "404 User '%s' not found\n", username);
+ return ;
+ }
+
+ // Parse flags
+ do {
+ int bRemove = 0;
+ int i;
+ struct {
+ const char *Name;
+ int Mask;
+ int Value;
+ } cFLAGS[] = {
+ {"disabled", USER_FLAG_DISABLED, USER_FLAG_DISABLED}
+ ,{"door", USER_FLAG_DOORGROUP, USER_FLAG_DOORGROUP}
+ ,{"coke", USER_FLAG_COKE, USER_FLAG_COKE}
+ ,{"wheel", USER_FLAG_WHEEL, USER_FLAG_WHEEL}
+ // ,{"internal", USER_FLAG_INTERNAL, USER_FLAG_INTERNAL}
+ };
+ const int ciNumFlags = sizeof(cFLAGS)/sizeof(cFLAGS[0]);
+
+ while( *flags == ' ' ) flags ++; // Eat whitespace
+ space = strchr(flags, ','); // Find the end of the flag
+ if(space) *space = '\0';
+
+ // Check for inversion/removal
+ if( *flags == '!' || *flags == '-' ) {
+ bRemove = 1;
+ flags ++;
+ }
+ else if( *flags == '+' ) {
+ flags ++;
+ }
+
+ // Check flag values
+ for( i = 0; i < ciNumFlags; i ++ )
+ {
+ if( strcmp(flags, cFLAGS[i].Name) == 0 ) {
+ mask |= cFLAGS[i].Mask;
+ value &= ~cFLAGS[i].Mask;
+ if( !bRemove )
+ value |= cFLAGS[i].Value;
+ break;
+ }
+ }
+
+ // Error check
+ if( i == ciNumFlags ) {
+ sendf(Client->Socket, "407 Unknown flag value '%s'\n", flags);
+ return ;
+ }
+
+ flags = space + 1;
+ } while(space);
+
+ // Apply flags
+ Bank_SetFlags(uid, mask, value);