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. */
11 #include <sys/types.h>
19 #include "server.cmdline.h"
32 #include "user_list.h"
33 #include "server_command_list.h"
34 #include "afs_command_list.h"
38 static struct server_command afs_cmds[] = {DEFINE_AFS_CMD_ARRAY};
39 static struct server_command server_cmds[] = {DEFINE_SERVER_CMD_ARRAY};
41 /** Commands including options must be shorter than this. */
42 #define MAX_COMMAND_LEN 32768
45 extern struct misc_meta_data *mmd;
46 extern struct sender senders[];
47 int send_afs_status(struct command_context *cc, int parser_friendly);
49 static void dummy(__a_unused int s)
53 static void mmd_dup(struct misc_meta_data *new_mmd)
55 mutex_lock(mmd_mutex);
57 mutex_unlock(mmd_mutex);
61 * Compute human readable string containing vss status for given integer value.
63 * We don't want to use vss_playing() and friends here because we take a
64 * snapshot of the mmd struct and use the copy for computing the state of the
65 * vss. If the real data were used, we would take the mmd lock for a rather
66 * long time or risk to get an inconsistent view.
68 static char *vss_status_tohuman(unsigned int flags)
70 if (flags & VSS_PLAYING)
71 return para_strdup("playing");
73 return para_strdup("stopped");
74 return para_strdup("paused");
78 * return human readable permission string. Never returns NULL.
80 static char *cmd_perms_itohuman(unsigned int perms)
82 char *msg = para_malloc(5 * sizeof(char));
84 msg[0] = perms & AFS_READ? 'a' : '-';
85 msg[1] = perms & AFS_WRITE? 'A' : '-';
86 msg[2] = perms & VSS_READ? 'v' : '-';
87 msg[3] = perms & VSS_WRITE? 'V' : '-';
95 static char *vss_get_status_flags(unsigned int flags)
97 char *msg = para_malloc(5 * sizeof(char));
99 msg[0] = (flags & VSS_PLAYING)? 'P' : '_';
100 msg[1] = (flags & VSS_NOMORE)? 'O' : '_';
101 msg[2] = (flags & VSS_NEXT)? 'N' : '_';
102 msg[3] = (flags & VSS_REPOS)? 'R' : '_';
107 static unsigned get_status(struct misc_meta_data *nmmd, int parser_friendly,
111 char *status, *flags; /* vss status info */
112 /* nobody updates our version of "now" */
113 char *ut = get_server_uptime_str(NULL);
114 long offset = (nmmd->offset + 500) / 1000;
115 struct timeval current_time;
117 struct para_buffer b = {.flags = parser_friendly? PBF_SIZE_PREFIX : 0};
119 /* report real status */
120 status = vss_status_tohuman(nmmd->vss_status_flags);
121 flags = vss_get_status_flags(nmmd->vss_status_flags);
122 if (nmmd->size) { /* parent currently has an audio file open */
123 localtime_r(&nmmd->mtime, &mtime_tm);
124 strftime(mtime, 29, "%b %d %Y", &mtime_tm);
126 clock_get_realtime(¤t_time);
128 * The calls to WRITE_STATUS_ITEM() below never fail because
129 * b->max_size is zero (unlimited), see para_printf(). However, clang
130 * is not smart enough to prove this and complains nevertheless.
131 * Casting the return value to void silences clang.
133 (void)WRITE_STATUS_ITEM(&b, SI_FILE_SIZE, "%zu\n", nmmd->size / 1024);
134 (void)WRITE_STATUS_ITEM(&b, SI_MTIME, "%s\n", mtime);
135 (void)WRITE_STATUS_ITEM(&b, SI_STATUS, "%s\n", status);
136 (void)WRITE_STATUS_ITEM(&b, SI_STATUS_FLAGS, "%s\n", flags);
137 (void)WRITE_STATUS_ITEM(&b, SI_OFFSET, "%li\n", offset);
138 (void)WRITE_STATUS_ITEM(&b, SI_AFS_MODE, "%s\n", mmd->afs_mode_string);
139 (void)WRITE_STATUS_ITEM(&b, SI_STREAM_START, "%lu.%lu\n",
140 (long unsigned)nmmd->stream_start.tv_sec,
141 (long unsigned)nmmd->stream_start.tv_usec);
142 (void)WRITE_STATUS_ITEM(&b, SI_CURRENT_TIME, "%lu.%lu\n",
143 (long unsigned)current_time.tv_sec,
144 (long unsigned)current_time.tv_usec);
152 static int check_sender_args(int argc, char * const * argv, struct sender_command_data *scd)
155 /* this has to match sender.h */
156 const char *subcmds[] = {"add", "delete", "allow", "deny", "on", "off", NULL};
158 scd->sender_num = -1;
160 return -E_COMMAND_SYNTAX;
161 for (i = 0; senders[i].name; i++)
162 if (!strcmp(senders[i].name, argv[1]))
164 PARA_DEBUG_LOG("%d:%s\n", argc, argv[1]);
165 if (!senders[i].name)
166 return -E_COMMAND_SYNTAX;
168 for (i = 0; subcmds[i]; i++)
169 if (!strcmp(subcmds[i], argv[2]))
172 return -E_COMMAND_SYNTAX;
174 if (!senders[scd->sender_num].client_cmds[scd->cmd_num])
175 return -E_SENDER_CMD;
176 switch (scd->cmd_num) {
180 return -E_COMMAND_SYNTAX;
184 if (argc != 4 || parse_cidr(argv[3], scd->host,
185 sizeof(scd->host), &scd->netmask) == NULL)
186 return -E_COMMAND_SYNTAX;
191 return -E_COMMAND_SYNTAX;
192 return parse_fec_url(argv[3], scd);
194 return -E_COMMAND_SYNTAX;
200 * Send a sideband packet through a blocking file descriptor.
202 * \param scc fd and crypto keys.
203 * \param buf The buffer to send.
204 * \param numbytes The size of \a buf.
205 * \param band The sideband designator of this packet.
206 * \param dont_free If true, never deallocate \a buf.
208 * The nonblock flag must be disabled for the file descriptor given by \a scc.
210 * Stream cipher encryption is automatically activated if neccessary via the
211 * sideband transformation, depending on the value of \a band.
215 * \sa \ref send_sb_va().
217 int send_sb(struct stream_cipher_context *scc, void *buf, size_t numbytes,
218 int band, bool dont_free)
221 struct sb_context *sbc;
223 struct sb_buffer sbb = SBB_INIT(band, buf, numbytes);
224 sb_transformation trafo = band < SBD_PROCEED? NULL : sc_trafo;
226 sbc = sb_new_send(&sbb, dont_free, trafo, scc->send);
228 ret = sb_get_send_buffers(sbc, iov);
229 ret = xwritev(scc->fd, iov, ret);
232 } while (sb_sent(sbc, ret) == false);
240 * Create a variable sized buffer and send it as a sideband packet.
242 * \param scc Passed to \ref send_sb.
243 * \param band See \ref send_sb.
244 * \param fmt The format string.
246 * \return The return value of the underlying call to \ref send_sb.
248 __printf_3_4 int send_sb_va(struct stream_cipher_context *scc, int band,
249 const char *fmt, ...)
256 ret = xvasprintf(&msg, fmt, ap);
258 return send_sb(scc, msg, ret, band, false);
262 * Send an error message to a client.
264 * \param cc Client info.
265 * \param err The (positive) error code.
267 * \return The return value of the underlying call to send_sb_va().
269 int send_strerror(struct command_context *cc, int err)
271 return send_sb_va(&cc->scc, SBD_ERROR_LOG, "%s\n", para_strerror(err));
275 * Send a sideband packet through a blocking file descriptor.
277 * \param scc fd and crypto keys.
278 * \param expected_band The expected band designator.
279 * \param max_size Passed to \ref sb_new_recv().
280 * \param result Body of the sideband packet is returned here.
282 * If \a expected_band is not \p SBD_ANY, the band designator of the received
283 * sideband packet is compared to \a expected_band and a mismatch is considered
288 int recv_sb(struct stream_cipher_context *scc,
289 enum sb_designator expected_band,
290 size_t max_size, struct iovec *result)
293 struct sb_context *sbc;
295 struct sb_buffer sbb;
296 sb_transformation trafo;
298 trafo = expected_band != SBD_ANY && expected_band < SBD_PROCEED?
300 sbc = sb_new_recv(max_size, trafo, scc->recv);
302 sb_get_recv_buffer(sbc, &iov);
303 ret = recv_bin_buffer(scc->fd, iov.iov_base, iov.iov_len);
308 ret = sb_received(sbc, ret, &sbb);
315 if (expected_band != SBD_ANY && sbb.band != expected_band)
324 static int com_sender(struct command_context *cc)
328 struct sender_command_data scd;
331 for (i = 0; senders[i].name; i++) {
333 ret = xasprintf(&tmp, "%s%s\n", msg? msg : "",
338 return send_sb(&cc->scc, msg, ret, SBD_OUTPUT, false);
340 ret = check_sender_args(cc->argc, cc->argv, &scd);
342 if (scd.sender_num < 0)
344 msg = senders[scd.sender_num].help();
345 return send_sb(&cc->scc, msg, strlen(msg), SBD_OUTPUT, false);
348 switch (scd.cmd_num) {
351 assert(senders[scd.sender_num].resolve_target);
352 ret = senders[scd.sender_num].resolve_target(cc->argv[3], &scd);
357 for (i = 0; i < 10; i++) {
358 mutex_lock(mmd_mutex);
359 if (mmd->sender_cmd_data.cmd_num >= 0) {
360 mutex_unlock(mmd_mutex);
364 memcpy(&mmd->sender_cmd_data, &scd, sizeof(scd));
365 mutex_unlock(mmd_mutex);
368 return (i < 10)? 1 : -E_LOCK;
372 static int com_si(struct command_context *cc)
375 char *msg, *ut, *sender_info = NULL;
378 return -E_COMMAND_SYNTAX;
379 mutex_lock(mmd_mutex);
380 for (i = 0; senders[i].name; i++) {
381 char *info = senders[i].info();
382 sender_info = para_strcat(sender_info, info);
385 ut = get_server_uptime_str(now);
386 ret = xasprintf(&msg,
388 "up: %s\nplayed: %u\n"
391 "connections (active/accepted/total): %u/%u/%u\n"
392 "current loglevel: %s\n"
393 "supported audio formats: %s\n"
399 mmd->active_connections,
403 AUDIO_FORMAT_HANDLERS,
406 mutex_unlock(mmd_mutex);
409 return send_sb(&cc->scc, msg, ret, SBD_OUTPUT, false);
413 static int com_version(struct command_context *cc)
419 return -E_COMMAND_SYNTAX;
420 len = xasprintf(&msg, "%s", version_text("server"));
421 return send_sb(&cc->scc, msg, len, SBD_OUTPUT, false);
424 #define EMPTY_STATUS_ITEMS \
429 ITEM(ATTRIBUTES_BITMAP) \
430 ITEM(ATTRIBUTES_TXT) \
441 ITEM(SECONDS_TOTAL) \
453 * Write a list of audio-file related status items with empty values.
455 * This is used by vss when currently no audio file is open.
457 static unsigned empty_status_items(int parser_friendly, char **result)
463 len = xasprintf(&esi,
464 #define ITEM(x) "0004 %02x:\n"
467 #define ITEM(x) , SI_ ## x
472 len = xasprintf(&esi,
473 #define ITEM(x) "%s:\n"
476 #define ITEM(x) ,status_item_list[SI_ ## x]
483 #undef EMPTY_STATUS_ITEMS
486 static int com_stat(struct command_context *cc)
489 struct misc_meta_data tmp, *nmmd = &tmp;
492 int parser_friendly = 0;
494 para_sigaction(SIGUSR1, dummy);
496 for (i = 1; i < cc->argc; i++) {
497 const char *arg = cc->argv[i];
500 if (!strcmp(arg, "--")) {
504 if (!strncmp(arg, "-n=", 3)) {
505 ret = para_atoi32(arg + 3, &num);
510 if (!strcmp(arg, "-p")) {
514 return -E_COMMAND_SYNTAX;
517 return -E_COMMAND_SYNTAX;
520 ret = get_status(nmmd, parser_friendly, &s);
521 ret = send_sb(&cc->scc, s, ret, SBD_OUTPUT, false);
524 if (nmmd->vss_status_flags & VSS_NEXT) {
526 ret = empty_status_items(parser_friendly, &esi);
527 ret = send_sb(&cc->scc, esi, ret, SBD_OUTPUT, false);
531 send_afs_status(cc, parser_friendly);
533 if (num > 0 && !--num)
536 ret = -E_SERVER_CRASH;
544 static int send_list_of_commands(struct command_context *cc, struct server_command *cmd,
549 for (; cmd->name; cmd++) {
550 char *tmp, *perms = cmd_perms_itohuman(cmd->perms);
551 tmp = make_message("%s\t%s\t%s\t%s\n", cmd->name, handler,
552 perms, cmd->description);
554 msg = para_strcat(msg, tmp);
557 return send_sb(&cc->scc, msg, strlen(msg), SBD_OUTPUT, false);
560 /* returns string that must be freed by the caller */
561 static struct server_command *get_cmd_ptr(const char *name, char **handler)
563 struct server_command *cmd;
565 for (cmd = server_cmds; cmd->name; cmd++)
566 if (!strcmp(cmd->name, name)) {
568 *handler = para_strdup("server"); /* server commands */
571 /* not found, look for commands supported by afs */
572 for (cmd = afs_cmds; cmd->name; cmd++)
573 if (!strcmp(cmd->name, name)) {
575 *handler = para_strdup("afs");
582 static int com_help(struct command_context *cc)
584 struct server_command *cmd;
585 char *perms, *handler, *buf;
589 /* no argument given, print list of commands */
590 if ((ret = send_list_of_commands(cc, server_cmds, "server")) < 0)
592 return send_list_of_commands(cc, afs_cmds, "afs");
594 /* argument given for help */
595 cmd = get_cmd_ptr(cc->argv[1], &handler);
598 perms = cmd_perms_itohuman(cmd->perms);
599 ret = xasprintf(&buf, "%s - %s\n\n"
613 return send_sb(&cc->scc, buf, ret, SBD_OUTPUT, false);
617 static int com_hup(struct command_context *cc)
620 return -E_COMMAND_SYNTAX;
621 kill(getppid(), SIGHUP);
626 static int com_term(struct command_context *cc)
629 return -E_COMMAND_SYNTAX;
630 kill(getppid(), SIGTERM);
634 static int com_play(struct command_context *cc)
637 return -E_COMMAND_SYNTAX;
638 mutex_lock(mmd_mutex);
639 mmd->new_vss_status_flags |= VSS_PLAYING;
640 mmd->new_vss_status_flags &= ~VSS_NOMORE;
641 mutex_unlock(mmd_mutex);
646 static int com_stop(struct command_context *cc)
649 return -E_COMMAND_SYNTAX;
650 mutex_lock(mmd_mutex);
651 mmd->new_vss_status_flags &= ~VSS_PLAYING;
652 mmd->new_vss_status_flags &= ~VSS_REPOS;
653 mmd->new_vss_status_flags |= VSS_NEXT;
654 mutex_unlock(mmd_mutex);
659 static int com_pause(struct command_context *cc)
662 return -E_COMMAND_SYNTAX;
663 mutex_lock(mmd_mutex);
664 if (!vss_paused() && !vss_stopped()) {
666 mmd->new_vss_status_flags &= ~VSS_PLAYING;
667 mmd->new_vss_status_flags &= ~VSS_NEXT;
669 mutex_unlock(mmd_mutex);
674 static int com_next(struct command_context *cc)
677 return -E_COMMAND_SYNTAX;
678 mutex_lock(mmd_mutex);
680 mmd->new_vss_status_flags |= VSS_NEXT;
681 mutex_unlock(mmd_mutex);
686 static int com_nomore(struct command_context *cc)
689 return -E_COMMAND_SYNTAX;
690 mutex_lock(mmd_mutex);
691 if (vss_playing() || vss_paused())
692 mmd->new_vss_status_flags |= VSS_NOMORE;
693 mutex_unlock(mmd_mutex);
698 static int com_ff(struct command_context *cc)
701 int ret, backwards = 0;
706 return -E_COMMAND_SYNTAX;
707 if (!(ret = sscanf(cc->argv[1], "%u%c", &i, &c)))
708 return -E_COMMAND_SYNTAX;
709 if (ret > 1 && c == '-')
710 backwards = 1; /* jmp backwards */
711 mutex_lock(mmd_mutex);
712 ret = -E_NO_AUDIO_FILE;
713 if (!mmd->afd.afhi.chunks_total || !mmd->afd.afhi.seconds_total)
715 promille = (1000 * mmd->current_chunk) / mmd->afd.afhi.chunks_total;
717 promille -= 1000 * i / mmd->afd.afhi.seconds_total;
719 promille += 1000 * i / mmd->afd.afhi.seconds_total;
722 if (promille > 1000) {
723 mmd->new_vss_status_flags |= VSS_NEXT;
726 mmd->repos_request = (mmd->afd.afhi.chunks_total * promille) / 1000;
727 mmd->new_vss_status_flags |= VSS_REPOS;
728 mmd->new_vss_status_flags &= ~VSS_NEXT;
732 mutex_unlock(mmd_mutex);
737 static int com_jmp(struct command_context *cc)
743 return -E_COMMAND_SYNTAX;
744 if (sscanf(cc->argv[1], "%lu", &i) <= 0)
745 return -E_COMMAND_SYNTAX;
746 mutex_lock(mmd_mutex);
747 ret = -E_NO_AUDIO_FILE;
748 if (!mmd->afd.afhi.chunks_total)
752 PARA_INFO_LOG("jumping to %lu%%\n", i);
753 mmd->repos_request = (mmd->afd.afhi.chunks_total * i + 50)/ 100;
754 PARA_INFO_LOG("sent: %lu, offset before jmp: %lu\n",
755 mmd->chunks_sent, mmd->offset);
756 mmd->new_vss_status_flags |= VSS_REPOS;
757 mmd->new_vss_status_flags &= ~VSS_NEXT;
761 mutex_unlock(mmd_mutex);
766 * check if perms are sufficient to exec a command having perms cmd_perms.
767 * Returns 0 if perms are sufficient, -E_PERM otherwise.
769 static int check_perms(unsigned int perms, struct server_command *cmd_ptr)
771 PARA_DEBUG_LOG("checking permissions\n");
772 return (cmd_ptr->perms & perms) < cmd_ptr->perms ? -E_PERM : 0;
775 static void reset_signals(void)
777 para_sigaction(SIGCHLD, SIG_IGN);
778 para_sigaction(SIGINT, SIG_DFL);
779 para_sigaction(SIGTERM, SIG_DFL);
780 para_sigaction(SIGHUP, SIG_DFL);
783 static int parse_auth_request(char *buf, int len, struct user **u)
786 char *p, *username, **features = NULL;
787 size_t auth_rq_len = strlen(AUTH_REQUEST_MSG);
788 bool sideband_requested = false;
791 if (len < auth_rq_len + 2)
792 return -E_AUTH_REQUEST;
793 if (strncmp(buf, AUTH_REQUEST_MSG, auth_rq_len) != 0)
794 return -E_AUTH_REQUEST;
795 username = buf + auth_rq_len;
796 p = strchr(username, ' ');
800 return -E_AUTH_REQUEST;
803 create_argv(p, ",", &features);
804 for (i = 0; features[i]; i++) {
805 if (strcmp(features[i], "sideband") == 0)
806 sideband_requested = true;
808 ret = -E_BAD_FEATURE;
813 if (sideband_requested == false) { /* sideband is mandatory */
814 PARA_ERROR_LOG("client did not request sideband\n");
815 ret = -E_BAD_FEATURE;
818 PARA_DEBUG_LOG("received auth request for user %s\n", username);
819 *u = lookup_user(username);
826 #define HANDSHAKE_BUFSIZE 4096
828 static int parse_sb_command(struct command_context *cc, struct iovec *iov)
834 if (iov->iov_base == NULL || iov->iov_len == 0)
837 p[iov->iov_len - 1] = '\0'; /* just to be sure */
838 cc->cmd = get_cmd_ptr(p, NULL);
841 ret = check_perms(cc->u->perms, cc->cmd);
844 end = iov->iov_base + iov->iov_len;
845 for (i = 0, p = iov->iov_base; p < end; i++)
848 cc->argv = para_malloc((cc->argc + 1) * sizeof(char *));
849 for (i = 0, p = iov->iov_base; p < end; i++) {
850 cc->argv[i] = para_strdup(p);
853 cc->argv[cc->argc] = NULL;
861 * Perform user authentication and execute a command.
863 * \param fd The file descriptor to send output to.
864 * \param peername Identifies the connecting peer.
866 * Whenever para_server accepts an incoming tcp connection on
867 * the port it listens on, it forks and the resulting child
868 * calls this function.
870 * An RSA-based challenge/response is used to authenticate
871 * the peer. It that authentication succeeds, a random
872 * session key is generated and sent back to the peer,
873 * encrypted with its RSA public key. From this point on,
874 * all transfers are crypted with this session key.
876 * Next it is checked if the peer supplied a valid server command or a command
877 * for the audio file selector. If yes, and if the user has sufficient
878 * permissions to execute that command, the function calls the corresponding
879 * command handler which does argument checking and further processing.
881 * In order to cope with a DOS attacks, a timeout is set up
882 * which terminates the function if the connection was not
883 * authenticated when the timeout expires.
885 * \sa alarm(2), crypt.c, crypt.h
887 __noreturn void handle_connect(int fd, const char *peername)
890 unsigned char rand_buf[CHALLENGE_SIZE + 2 * SESSION_KEY_LEN];
891 unsigned char challenge_hash[HASH_SIZE];
892 char *p, *command = NULL, *buf = para_malloc(HANDSHAKE_BUFSIZE) /* must be on the heap */;
894 struct command_context cc_struct = {.peer = peername}, *cc = &cc_struct;
899 /* we need a blocking fd here as recv() might return EAGAIN otherwise. */
900 ret = mark_fd_blocking(fd);
903 /* send Welcome message */
904 ret = write_va_buffer(fd, "This is para_server, version "
905 PACKAGE_VERSION ".\n"
906 "Features: sideband\n"
910 /* recv auth request line */
911 ret = recv_buffer(fd, buf, HANDSHAKE_BUFSIZE);
914 ret = parse_auth_request(buf, ret, &cc->u);
917 p = buf + strlen(AUTH_REQUEST_MSG);
918 PARA_DEBUG_LOG("received auth request for user %s\n", p);
919 cc->u = lookup_user(p);
921 get_random_bytes_or_die(rand_buf, sizeof(rand_buf));
922 ret = pub_encrypt(cc->u->pubkey, rand_buf, sizeof(rand_buf),
923 (unsigned char *)buf);
929 * We don't want to reveal our user names, so we send a
930 * challenge to the client even if the user does not exist, and
931 * fail the authentication later.
934 get_random_bytes_or_die((unsigned char *)buf, numbytes);
936 PARA_DEBUG_LOG("sending %u byte challenge + rc4 keys (%zu bytes)\n",
937 CHALLENGE_SIZE, numbytes);
938 ret = send_sb(&cc->scc, buf, numbytes, SBD_CHALLENGE, false);
942 ret = recv_sb(&cc->scc, SBD_CHALLENGE_RESPONSE,
943 HANDSHAKE_BUFSIZE, &iov);
947 numbytes = iov.iov_len;
948 PARA_DEBUG_LOG("received %zu bytes challenge response\n", numbytes);
953 * The correct response is the hash of the first CHALLENGE_SIZE bytes
954 * of the random data.
957 if (numbytes != HASH_SIZE)
959 hash_function((char *)rand_buf, CHALLENGE_SIZE, challenge_hash);
960 if (memcmp(challenge_hash, buf, HASH_SIZE))
962 /* auth successful */
964 PARA_INFO_LOG("good auth for %s\n", cc->u->name);
965 /* init stream cipher keys with the second part of the random buffer */
966 cc->scc.recv = sc_new(rand_buf + CHALLENGE_SIZE, SESSION_KEY_LEN);
967 cc->scc.send = sc_new(rand_buf + CHALLENGE_SIZE + SESSION_KEY_LEN, SESSION_KEY_LEN);
968 ret = send_sb(&cc->scc, NULL, 0, SBD_PROCEED, false);
971 ret = recv_sb(&cc->scc, SBD_COMMAND, MAX_COMMAND_LEN, &iov);
974 ret = parse_sb_command(cc, &iov);
978 PARA_NOTICE_LOG("calling com_%s() for %s@%s\n", cc->cmd->name,
979 cc->u->name, peername);
980 ret = cc->cmd->handler(cc);
982 mutex_lock(mmd_mutex);
984 mutex_unlock(mmd_mutex);
988 if (send_strerror(cc, -ret) >= 0)
989 send_sb(&cc->scc, NULL, 0, SBD_EXIT__FAILURE, true);
991 PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
995 mutex_lock(mmd_mutex);
996 if (cc->cmd && (cc->cmd->perms & AFS_WRITE) && ret >= 0)
998 mmd->active_connections--;
999 mutex_unlock(mmd_mutex);
1001 ret = send_sb(&cc->scc, NULL, 0, SBD_EXIT__SUCCESS, true);
1003 PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
1005 sc_free(cc->scc.recv);
1006 sc_free(cc->scc.send);
1007 exit(ret < 0? EXIT_FAILURE : EXIT_SUCCESS);