+static void reset_signals(void)
+{
+ para_sigaction(SIGCHLD, SIG_IGN);
+ para_sigaction(SIGINT, SIG_DFL);
+ para_sigaction(SIGTERM, SIG_DFL);
+ para_sigaction(SIGHUP, SIG_DFL);
+}
+
+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;
+}
+
+#define HANDSHAKE_BUFSIZE 4096
+
+static int parse_sb_command(struct command_context *cc, struct iovec *iov)
+{
+ int ret, i;
+ char *p, *end;
+
+ ret = -E_BAD_CMD;
+ if (iov->iov_base == NULL || iov->iov_len == 0)
+ goto out;
+ p = iov->iov_base;
+ p[iov->iov_len - 1] = '\0'; /* just to be sure */
+ cc->cmd = get_cmd_ptr(p, NULL);
+ if (!cc->cmd)
+ goto out;
+ ret = check_perms(cc->u->perms, cc->cmd);
+ if (ret < 0)
+ goto out;
+ end = iov->iov_base + iov->iov_len;
+ for (i = 0, p = iov->iov_base; p < end; i++)
+ p += strlen(p) + 1;
+ cc->argc = i;
+ cc->argv = para_malloc((cc->argc + 1) * sizeof(char *));
+ for (i = 0, p = iov->iov_base; p < end; i++) {
+ cc->argv[i] = para_strdup(p);
+ p += strlen(p) + 1;
+ }
+ cc->argv[cc->argc] = NULL;
+ ret = cc->argc;
+out:
+ free(iov->iov_base);
+ return ret;
+}
+