+ // Can't lock control if: User not actually logged in (sanity), or key is still valid and the user is not an admin
+ if (user_type == USER_UNAUTH ||
+ (user_type != USER_ADMIN && !expired && *(context->control_key) != '\0'))
+ return false;
+
+ // Release any existing control (if any)
+ FCGI_ReleaseControl(context);
+
+ // Set timestamp
+ context->control_timestamp = now;
+
+ // Generate a SHA1 hash for the user
+ SHA_CTX sha1ctx;
+ unsigned char sha1[20];
+ int i = rand();
+ SHA1_Init(&sha1ctx);
+ SHA1_Update(&sha1ctx, &now, sizeof(now));
+ SHA1_Update(&sha1ctx, &i, sizeof(i));
+ SHA1_Final(sha1, &sha1ctx);
+ for (i = 0; i < sizeof(sha1); i++)
+ sprintf(context->control_key + i * 2, "%02x", sha1[i]);
+
+ // Set the IP address
+ snprintf(context->control_ip, 16, "%s", getenv("REMOTE_ADDR"));
+ // Set the user name
+ int uname_len = strlen(user_name);
+ if (snprintf(context->user_name, sizeof(context->user_name), "%s", user_name) < uname_len)
+ {
+ Log(LOGERR, "Username at %d characters too long (limit %d)", uname_len, sizeof(context->user_name));
+ return false; // :-(
+ }
+ // Set the user type
+ context->user_type = user_type;
+ // Create directory
+ if (mkdir(user_name, 0777) != 0 && errno != EEXIST)