+static int parse_auth_request(char *buf, int len, struct user **u,
+ bool *use_sideband)
+{
+ int ret;
+ char *p, *username, **features = NULL;
+ size_t auth_rq_len = strlen(AUTH_REQUEST_MSG);
+
+ *u = NULL;
+ *use_sideband = false;
+ if (len < auth_rq_len + 2)
+ return -E_AUTH_REQUEST;
+ if (strncmp(buf, AUTH_REQUEST_MSG, auth_rq_len) != 0)
+ return -E_AUTH_REQUEST;
+ username = buf + auth_rq_len;
+ p = strchr(username, ' ');
+ if (p) {
+ int i;
+ if (p == username)
+ return -E_AUTH_REQUEST;
+ *p = '\0';
+ p++;
+ create_argv(p, ",", &features);
+ for (i = 0; features[i]; i++) {
+ if (strcmp(features[i], "sideband") == 0)
+ *use_sideband = true;
+ else {
+ ret = -E_BAD_FEATURE;
+ goto out;
+ }
+ }
+ }
+ PARA_DEBUG_LOG("received auth request for user %s (sideband = %s)\n",
+ username, *use_sideband? "true" : "false");
+ *u = lookup_user(username);
+ ret = 1;
+out:
+ free_argv(features);
+ return ret;
+}
+