2 * Copyright (C) 1997-2013 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file command.c Client authentication and server commands. */
9 #include <netinet/in.h>
10 #include <sys/socket.h>
13 #include <sys/types.h>
15 #include <arpa/inet.h>
24 #include "server.cmdline.h"
37 #include "user_list.h"
38 #include "server_command_list.h"
39 #include "afs_command_list.h"
43 static struct server_command afs_cmds[] = {DEFINE_AFS_CMD_ARRAY};
44 static struct server_command server_cmds[] = {DEFINE_SERVER_CMD_ARRAY};
46 /** Commands including options must be shorter than this. */
47 #define MAX_COMMAND_LEN 32768
50 extern struct misc_meta_data *mmd;
51 extern struct sender senders[];
52 int send_afs_status(struct command_context *cc, int parser_friendly);
54 static void dummy(__a_unused int s)
58 static void mmd_dup(struct misc_meta_data *new_mmd)
60 mutex_lock(mmd_mutex);
62 mutex_unlock(mmd_mutex);
66 * Compute human readable string containing vss status for given integer value.
68 * We don't want to use vss_playing() and friends here because we take a
69 * snapshot of the mmd struct and use the copy for computing the state of the
70 * vss. If the real data were used, we would take the mmd lock for a rather
71 * long time or risk to get an inconsistent view.
73 static char *vss_status_tohuman(unsigned int flags)
75 if (flags & VSS_PLAYING)
76 return para_strdup("playing");
78 return para_strdup("stopped");
79 return para_strdup("paused");
83 * return human readable permission string. Never returns NULL.
85 static char *cmd_perms_itohuman(unsigned int perms)
87 char *msg = para_malloc(5 * sizeof(char));
89 msg[0] = perms & AFS_READ? 'a' : '-';
90 msg[1] = perms & AFS_WRITE? 'A' : '-';
91 msg[2] = perms & VSS_READ? 'v' : '-';
92 msg[3] = perms & VSS_WRITE? 'V' : '-';
100 static char *vss_get_status_flags(unsigned int flags)
102 char *msg = para_malloc(5 * sizeof(char));
104 msg[0] = (flags & VSS_PLAYING)? 'P' : '_';
105 msg[1] = (flags & VSS_NOMORE)? 'O' : '_';
106 msg[2] = (flags & VSS_NEXT)? 'N' : '_';
107 msg[3] = (flags & VSS_REPOS)? 'R' : '_';
112 static unsigned get_status(struct misc_meta_data *nmmd, int parser_friendly,
116 char *status, *flags; /* vss status info */
117 /* nobody updates our version of "now" */
118 char *ut = get_server_uptime_str(NULL);
119 long offset = (nmmd->offset + 500) / 1000;
120 struct timeval current_time;
122 struct para_buffer b = {.flags = parser_friendly? PBF_SIZE_PREFIX : 0};
124 /* report real status */
125 status = vss_status_tohuman(nmmd->vss_status_flags);
126 flags = vss_get_status_flags(nmmd->vss_status_flags);
127 if (nmmd->size) { /* parent currently has an audio file open */
128 localtime_r(&nmmd->mtime, &mtime_tm);
129 strftime(mtime, 29, "%b %d %Y", &mtime_tm);
131 clock_get_realtime(¤t_time);
133 * The calls to WRITE_STATUS_ITEM() below never fail because
134 * b->max_size is zero (unlimited), see para_printf(). However, clang
135 * is not smart enough to prove this and complains nevertheless.
136 * Casting the return value to void silences clang.
138 (void)WRITE_STATUS_ITEM(&b, SI_FILE_SIZE, "%zu\n", nmmd->size / 1024);
139 (void)WRITE_STATUS_ITEM(&b, SI_MTIME, "%s\n", mtime);
140 (void)WRITE_STATUS_ITEM(&b, SI_STATUS, "%s\n", status);
141 (void)WRITE_STATUS_ITEM(&b, SI_STATUS_FLAGS, "%s\n", flags);
142 (void)WRITE_STATUS_ITEM(&b, SI_OFFSET, "%li\n", offset);
143 (void)WRITE_STATUS_ITEM(&b, SI_AFS_MODE, "%s\n", mmd->afs_mode_string);
144 (void)WRITE_STATUS_ITEM(&b, SI_STREAM_START, "%lu.%lu\n",
145 (long unsigned)nmmd->stream_start.tv_sec,
146 (long unsigned)nmmd->stream_start.tv_usec);
147 (void)WRITE_STATUS_ITEM(&b, SI_CURRENT_TIME, "%lu.%lu\n",
148 (long unsigned)current_time.tv_sec,
149 (long unsigned)current_time.tv_usec);
157 static int check_sender_args(int argc, char * const * argv, struct sender_command_data *scd)
160 /* this has to match sender.h */
161 const char *subcmds[] = {"add", "delete", "allow", "deny", "on", "off", NULL};
163 scd->sender_num = -1;
165 return -E_COMMAND_SYNTAX;
166 for (i = 0; senders[i].name; i++)
167 if (!strcmp(senders[i].name, argv[1]))
169 PARA_DEBUG_LOG("%d:%s\n", argc, argv[1]);
170 if (!senders[i].name)
171 return -E_COMMAND_SYNTAX;
173 for (i = 0; subcmds[i]; i++)
174 if (!strcmp(subcmds[i], argv[2]))
177 return -E_COMMAND_SYNTAX;
179 if (!senders[scd->sender_num].client_cmds[scd->cmd_num])
180 return -E_SENDER_CMD;
181 switch (scd->cmd_num) {
185 return -E_COMMAND_SYNTAX;
189 if (argc != 4 || parse_cidr(argv[3], scd->host,
190 sizeof(scd->host), &scd->netmask) == NULL)
191 return -E_COMMAND_SYNTAX;
196 return -E_COMMAND_SYNTAX;
197 return parse_fec_url(argv[3], scd);
199 return -E_COMMAND_SYNTAX;
205 * Send a sideband packet through a blocking file descriptor.
207 * \param scc fd and crypto keys.
208 * \param buf The buffer to send.
209 * \param numbytes The size of \a buf.
210 * \param band The sideband designator of this packet.
211 * \param dont_free If true, never deallocate \a buf.
213 * The nonblock flag must be disabled for the file descriptor given by \a scc.
215 * Stream cipher encryption is automatically activated if neccessary via the
216 * sideband transformation, depending on the value of \a band.
220 * \sa \ref send_sb_va().
222 int send_sb(struct stream_cipher_context *scc, void *buf, size_t numbytes,
223 int band, bool dont_free)
226 struct sb_context *sbc;
228 sb_transformation trafo = band < SBD_PROCEED? NULL : sc_trafo;
229 struct sb_buffer sbb = SBB_INIT(band, buf, numbytes);
231 sbc = sb_new_send(&sbb, dont_free, trafo, scc->send);
233 ret = sb_get_send_buffers(sbc, iov);
234 ret = xwritev(scc->fd, iov, ret);
237 } while (sb_sent(sbc, ret) == false);
245 * Create a variable sized buffer and send it as a sideband packet.
247 * \param scc Passed to \ref send_sb.
248 * \param band See \ref send_sb.
249 * \param fmt The format string.
251 * \return The return value of the underlying call to \ref send_sb.
253 __printf_3_4 int send_sb_va(struct stream_cipher_context *scc, int band,
254 const char *fmt, ...)
261 ret = xvasprintf(&msg, fmt, ap);
263 return send_sb(scc, msg, ret, band, false);
267 * Send an error message to a client.
269 * \param cc Client info.
270 * \param err The (positive) error code.
272 * \return The return value of the underlying call to send_sb_va().
274 int send_strerror(struct command_context *cc, int err)
276 return send_sb_va(&cc->scc, SBD_ERROR_LOG, "%s\n", para_strerror(err));
280 * Send a sideband packet through a blocking file descriptor.
282 * \param scc fd and crypto keys.
283 * \param expected_band The expected band designator.
284 * \param max_size Passed to \ref sb_new_recv().
285 * \param result Body of the sideband packet is returned here.
287 * If \a expected_band is not \p SBD_ANY, the band designator of the received
288 * sideband packet is compared to \a expected_band and a mismatch is considered
293 int recv_sb(struct stream_cipher_context *scc,
294 enum sb_designator expected_band,
295 size_t max_size, struct iovec *result)
298 struct sb_context *sbc;
300 struct sb_buffer sbb;
301 sb_transformation trafo;
303 trafo = expected_band != SBD_ANY && expected_band < SBD_PROCEED?
305 sbc = sb_new_recv(max_size, trafo, scc->recv);
307 sb_get_recv_buffer(sbc, &iov);
308 ret = recv_bin_buffer(scc->fd, iov.iov_base, iov.iov_len);
313 ret = sb_received(sbc, ret, &sbb);
320 if (expected_band != SBD_ANY && sbb.band != expected_band)
329 static int com_sender(struct command_context *cc)
333 struct sender_command_data scd;
336 for (i = 0; senders[i].name; i++) {
338 ret = xasprintf(&tmp, "%s%s\n", msg? msg : "",
343 return send_sb(&cc->scc, msg, ret, SBD_OUTPUT, false);
345 ret = check_sender_args(cc->argc, cc->argv, &scd);
347 if (scd.sender_num < 0)
349 msg = senders[scd.sender_num].help();
350 return send_sb(&cc->scc, msg, strlen(msg), SBD_OUTPUT, false);
353 switch (scd.cmd_num) {
356 assert(senders[scd.sender_num].resolve_target);
357 ret = senders[scd.sender_num].resolve_target(cc->argv[3], &scd);
362 for (i = 0; i < 10; i++) {
363 mutex_lock(mmd_mutex);
364 if (mmd->sender_cmd_data.cmd_num >= 0) {
365 mutex_unlock(mmd_mutex);
369 memcpy(&mmd->sender_cmd_data, &scd, sizeof(scd));
370 mutex_unlock(mmd_mutex);
373 return (i < 10)? 1 : -E_LOCK;
377 static int com_si(struct command_context *cc)
380 char *msg, *ut, *sender_info = NULL;
383 return -E_COMMAND_SYNTAX;
384 mutex_lock(mmd_mutex);
385 for (i = 0; senders[i].name; i++) {
386 char *info = senders[i].info();
387 sender_info = para_strcat(sender_info, info);
390 ut = get_server_uptime_str(now);
391 ret = xasprintf(&msg,
393 "up: %s\nplayed: %u\n"
396 "connections (active/accepted/total): %u/%u/%u\n"
397 "current loglevel: %s\n"
398 "supported audio formats: %s\n"
404 mmd->active_connections,
408 AUDIO_FORMAT_HANDLERS,
411 mutex_unlock(mmd_mutex);
414 return send_sb(&cc->scc, msg, ret, SBD_OUTPUT, false);
418 static int com_version(struct command_context *cc)
424 return -E_COMMAND_SYNTAX;
425 len = xasprintf(&msg, "%s", version_text("server"));
426 return send_sb(&cc->scc, msg, len, SBD_OUTPUT, false);
429 #define EMPTY_STATUS_ITEMS \
434 ITEM(ATTRIBUTES_BITMAP) \
435 ITEM(ATTRIBUTES_TXT) \
446 ITEM(SECONDS_TOTAL) \
458 * Write a list of audio-file related status items with empty values.
460 * This is used by vss when currently no audio file is open.
462 static unsigned empty_status_items(int parser_friendly, char **result)
468 len = xasprintf(&esi,
469 #define ITEM(x) "0004 %02x:\n"
472 #define ITEM(x) , SI_ ## x
477 len = xasprintf(&esi,
478 #define ITEM(x) "%s:\n"
481 #define ITEM(x) ,status_item_list[SI_ ## x]
488 #undef EMPTY_STATUS_ITEMS
491 static int com_stat(struct command_context *cc)
494 struct misc_meta_data tmp, *nmmd = &tmp;
497 int parser_friendly = 0;
499 para_sigaction(SIGUSR1, dummy);
501 for (i = 1; i < cc->argc; i++) {
502 const char *arg = cc->argv[i];
505 if (!strcmp(arg, "--")) {
509 if (!strncmp(arg, "-n=", 3)) {
510 ret = para_atoi32(arg + 3, &num);
515 if (!strcmp(arg, "-p")) {
519 return -E_COMMAND_SYNTAX;
522 return -E_COMMAND_SYNTAX;
525 ret = get_status(nmmd, parser_friendly, &s);
526 ret = send_sb(&cc->scc, s, ret, SBD_OUTPUT, false);
529 if (nmmd->vss_status_flags & VSS_NEXT) {
531 ret = empty_status_items(parser_friendly, &esi);
532 ret = send_sb(&cc->scc, esi, ret, SBD_OUTPUT, false);
536 send_afs_status(cc, parser_friendly);
538 if (num > 0 && !--num)
541 ret = -E_SERVER_CRASH;
549 static int send_list_of_commands(struct command_context *cc, struct server_command *cmd,
554 for (; cmd->name; cmd++) {
555 char *tmp, *perms = cmd_perms_itohuman(cmd->perms);
556 tmp = make_message("%s\t%s\t%s\t%s\n", cmd->name, handler,
557 perms, cmd->description);
559 msg = para_strcat(msg, tmp);
563 return send_sb(&cc->scc, msg, strlen(msg), SBD_OUTPUT, false);
566 /* returns string that must be freed by the caller */
567 static struct server_command *get_cmd_ptr(const char *name, char **handler)
569 struct server_command *cmd;
571 for (cmd = server_cmds; cmd->name; cmd++)
572 if (!strcmp(cmd->name, name)) {
574 *handler = para_strdup("server"); /* server commands */
577 /* not found, look for commands supported by afs */
578 for (cmd = afs_cmds; cmd->name; cmd++)
579 if (!strcmp(cmd->name, name)) {
581 *handler = para_strdup("afs");
588 static int com_help(struct command_context *cc)
590 struct server_command *cmd;
591 char *perms, *handler, *buf;
595 /* no argument given, print list of commands */
596 if ((ret = send_list_of_commands(cc, server_cmds, "server")) < 0)
598 return send_list_of_commands(cc, afs_cmds, "afs");
600 /* argument given for help */
601 cmd = get_cmd_ptr(cc->argv[1], &handler);
604 perms = cmd_perms_itohuman(cmd->perms);
605 ret = xasprintf(&buf, "%s - %s\n\n"
619 return send_sb(&cc->scc, buf, ret, SBD_OUTPUT, false);
623 static int com_hup(struct command_context *cc)
626 return -E_COMMAND_SYNTAX;
627 kill(getppid(), SIGHUP);
632 static int com_term(struct command_context *cc)
635 return -E_COMMAND_SYNTAX;
636 kill(getppid(), SIGTERM);
640 static int com_play(struct command_context *cc)
643 return -E_COMMAND_SYNTAX;
644 mutex_lock(mmd_mutex);
645 mmd->new_vss_status_flags |= VSS_PLAYING;
646 mmd->new_vss_status_flags &= ~VSS_NOMORE;
647 mutex_unlock(mmd_mutex);
652 static int com_stop(struct command_context *cc)
655 return -E_COMMAND_SYNTAX;
656 mutex_lock(mmd_mutex);
657 mmd->new_vss_status_flags &= ~VSS_PLAYING;
658 mmd->new_vss_status_flags &= ~VSS_REPOS;
659 mmd->new_vss_status_flags |= VSS_NEXT;
660 mutex_unlock(mmd_mutex);
665 static int com_pause(struct command_context *cc)
668 return -E_COMMAND_SYNTAX;
669 mutex_lock(mmd_mutex);
670 if (!vss_paused() && !vss_stopped()) {
672 mmd->new_vss_status_flags &= ~VSS_PLAYING;
673 mmd->new_vss_status_flags &= ~VSS_NEXT;
675 mutex_unlock(mmd_mutex);
680 static int com_next(struct command_context *cc)
683 return -E_COMMAND_SYNTAX;
684 mutex_lock(mmd_mutex);
686 mmd->new_vss_status_flags |= VSS_NEXT;
687 mutex_unlock(mmd_mutex);
692 static int com_nomore(struct command_context *cc)
695 return -E_COMMAND_SYNTAX;
696 mutex_lock(mmd_mutex);
697 if (vss_playing() || vss_paused())
698 mmd->new_vss_status_flags |= VSS_NOMORE;
699 mutex_unlock(mmd_mutex);
704 static int com_ff(struct command_context *cc)
707 int ret, backwards = 0;
712 return -E_COMMAND_SYNTAX;
713 if (!(ret = sscanf(cc->argv[1], "%u%c", &i, &c)))
714 return -E_COMMAND_SYNTAX;
715 if (ret > 1 && c == '-')
716 backwards = 1; /* jmp backwards */
717 mutex_lock(mmd_mutex);
718 ret = -E_NO_AUDIO_FILE;
719 if (!mmd->afd.afhi.chunks_total || !mmd->afd.afhi.seconds_total)
721 promille = (1000 * mmd->current_chunk) / mmd->afd.afhi.chunks_total;
723 promille -= 1000 * i / mmd->afd.afhi.seconds_total;
725 promille += 1000 * i / mmd->afd.afhi.seconds_total;
728 if (promille > 1000) {
729 mmd->new_vss_status_flags |= VSS_NEXT;
732 mmd->repos_request = (mmd->afd.afhi.chunks_total * promille) / 1000;
733 mmd->new_vss_status_flags |= VSS_REPOS;
734 mmd->new_vss_status_flags &= ~VSS_NEXT;
738 mutex_unlock(mmd_mutex);
743 static int com_jmp(struct command_context *cc)
749 return -E_COMMAND_SYNTAX;
750 if (sscanf(cc->argv[1], "%lu", &i) <= 0)
751 return -E_COMMAND_SYNTAX;
752 mutex_lock(mmd_mutex);
753 ret = -E_NO_AUDIO_FILE;
754 if (!mmd->afd.afhi.chunks_total)
758 PARA_INFO_LOG("jumping to %lu%%\n", i);
759 mmd->repos_request = (mmd->afd.afhi.chunks_total * i + 50)/ 100;
760 PARA_INFO_LOG("sent: %lu, offset before jmp: %lu\n",
761 mmd->chunks_sent, mmd->offset);
762 mmd->new_vss_status_flags |= VSS_REPOS;
763 mmd->new_vss_status_flags &= ~VSS_NEXT;
767 mutex_unlock(mmd_mutex);
772 * check if perms are sufficient to exec a command having perms cmd_perms.
773 * Returns 0 if perms are sufficient, -E_PERM otherwise.
775 static int check_perms(unsigned int perms, struct server_command *cmd_ptr)
777 PARA_DEBUG_LOG("checking permissions\n");
778 return (cmd_ptr->perms & perms) < cmd_ptr->perms ? -E_PERM : 0;
781 static void reset_signals(void)
783 para_sigaction(SIGCHLD, SIG_IGN);
784 para_sigaction(SIGINT, SIG_DFL);
785 para_sigaction(SIGTERM, SIG_DFL);
786 para_sigaction(SIGHUP, SIG_DFL);
789 static int parse_auth_request(char *buf, int len, struct user **u)
792 char *p, *username, **features = NULL;
793 size_t auth_rq_len = strlen(AUTH_REQUEST_MSG);
794 bool sideband_requested = false;
797 if (len < auth_rq_len + 2)
798 return -E_AUTH_REQUEST;
799 if (strncmp(buf, AUTH_REQUEST_MSG, auth_rq_len) != 0)
800 return -E_AUTH_REQUEST;
801 username = buf + auth_rq_len;
802 p = strchr(username, ' ');
806 return -E_AUTH_REQUEST;
809 create_argv(p, ",", &features);
810 for (i = 0; features[i]; i++) {
811 if (strcmp(features[i], "sideband") == 0)
812 sideband_requested = true;
814 ret = -E_BAD_FEATURE;
819 if (sideband_requested == false) { /* sideband is mandatory */
820 PARA_ERROR_LOG("client did not request sideband\n");
821 ret = -E_BAD_FEATURE;
824 PARA_DEBUG_LOG("received auth request for user %s\n", username);
825 *u = lookup_user(username);
832 #define HANDSHAKE_BUFSIZE 4096
834 static int parse_sb_command(struct command_context *cc, struct iovec *iov)
840 if (iov->iov_base == NULL || iov->iov_len == 0)
843 p[iov->iov_len - 1] = '\0'; /* just to be sure */
844 cc->cmd = get_cmd_ptr(p, NULL);
847 ret = check_perms(cc->u->perms, cc->cmd);
850 end = iov->iov_base + iov->iov_len;
851 for (i = 0; p < end; i++)
854 cc->argv = para_malloc((cc->argc + 1) * sizeof(char *));
855 for (i = 0, p = iov->iov_base; p < end; i++) {
856 cc->argv[i] = para_strdup(p);
859 cc->argv[cc->argc] = NULL;
867 * Perform user authentication and execute a command.
869 * \param fd The file descriptor to send output to.
870 * \param peername Identifies the connecting peer.
872 * Whenever para_server accepts an incoming tcp connection on
873 * the port it listens on, it forks and the resulting child
874 * calls this function.
876 * An RSA-based challenge/response is used to authenticate
877 * the peer. It that authentication succeeds, a random
878 * session key is generated and sent back to the peer,
879 * encrypted with its RSA public key. From this point on,
880 * all transfers are crypted with this session key.
882 * Next it is checked if the peer supplied a valid server command or a command
883 * for the audio file selector. If yes, and if the user has sufficient
884 * permissions to execute that command, the function calls the corresponding
885 * command handler which does argument checking and further processing.
887 * In order to cope with a DOS attacks, a timeout is set up
888 * which terminates the function if the connection was not
889 * authenticated when the timeout expires.
891 * \sa alarm(2), crypt.c, crypt.h
893 __noreturn void handle_connect(int fd, const char *peername)
896 unsigned char rand_buf[CHALLENGE_SIZE + 2 * SESSION_KEY_LEN];
897 unsigned char challenge_hash[HASH_SIZE];
898 char *p, *command = NULL, *buf = para_malloc(HANDSHAKE_BUFSIZE) /* must be on the heap */;
900 struct command_context cc_struct = {.peer = peername}, *cc = &cc_struct;
905 /* we need a blocking fd here as recv() might return EAGAIN otherwise. */
906 ret = mark_fd_blocking(fd);
909 /* send Welcome message */
910 ret = write_va_buffer(fd, "This is para_server, version "
911 PACKAGE_VERSION ".\n"
912 "Features: sideband\n"
916 /* recv auth request line */
917 ret = recv_buffer(fd, buf, HANDSHAKE_BUFSIZE);
920 ret = parse_auth_request(buf, ret, &cc->u);
923 p = buf + strlen(AUTH_REQUEST_MSG);
924 PARA_DEBUG_LOG("received auth request for user %s\n", p);
925 cc->u = lookup_user(p);
927 get_random_bytes_or_die(rand_buf, sizeof(rand_buf));
928 ret = pub_encrypt(cc->u->pubkey, rand_buf, sizeof(rand_buf),
929 (unsigned char *)buf);
935 * We don't want to reveal our user names, so we send a
936 * challenge to the client even if the user does not exist, and
937 * fail the authentication later.
940 get_random_bytes_or_die((unsigned char *)buf, numbytes);
942 PARA_DEBUG_LOG("sending %u byte challenge + rc4 keys (%zu bytes)\n",
943 CHALLENGE_SIZE, numbytes);
944 ret = send_sb(&cc->scc, buf, numbytes, SBD_CHALLENGE, false);
948 ret = recv_sb(&cc->scc, SBD_CHALLENGE_RESPONSE,
949 HANDSHAKE_BUFSIZE, &iov);
953 numbytes = iov.iov_len;
954 PARA_DEBUG_LOG("received %zu bytes challenge response\n", numbytes);
959 * The correct response is the hash of the first CHALLENGE_SIZE bytes
960 * of the random data.
963 if (numbytes != HASH_SIZE)
965 hash_function((char *)rand_buf, CHALLENGE_SIZE, challenge_hash);
966 if (memcmp(challenge_hash, buf, HASH_SIZE))
968 /* auth successful */
970 PARA_INFO_LOG("good auth for %s\n", cc->u->name);
971 /* init stream cipher keys with the second part of the random buffer */
972 cc->scc.recv = sc_new(rand_buf + CHALLENGE_SIZE, SESSION_KEY_LEN);
973 cc->scc.send = sc_new(rand_buf + CHALLENGE_SIZE + SESSION_KEY_LEN, SESSION_KEY_LEN);
974 ret = send_sb(&cc->scc, NULL, 0, SBD_PROCEED, false);
977 ret = recv_sb(&cc->scc, SBD_COMMAND, MAX_COMMAND_LEN, &iov);
980 ret = parse_sb_command(cc, &iov);
984 PARA_NOTICE_LOG("calling com_%s() for %s@%s\n", cc->cmd->name,
985 cc->u->name, peername);
986 ret = cc->cmd->handler(cc);
988 mutex_lock(mmd_mutex);
990 mutex_unlock(mmd_mutex);
994 if (send_strerror(cc, -ret) >= 0)
995 send_sb(&cc->scc, NULL, 0, SBD_EXIT__FAILURE, true);
997 PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
1001 mutex_lock(mmd_mutex);
1002 if (cc->cmd && (cc->cmd->perms & AFS_WRITE) && ret >= 0)
1004 mmd->active_connections--;
1005 mutex_unlock(mmd_mutex);
1007 ret = send_sb(&cc->scc, NULL, 0, SBD_EXIT__SUCCESS, true);
1009 PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
1011 sc_free(cc->scc.recv);
1012 sc_free(cc->scc.send);
1013 exit(ret < 0? EXIT_FAILURE : EXIT_SUCCESS);