2 * Copyright (C) 1997-2014 Andre Noll <maan@tuebingen.mpg.de>
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 long offset = (nmmd->offset + 500) / 1000;
119 struct timeval current_time;
121 struct para_buffer b = {.flags = parser_friendly? PBF_SIZE_PREFIX : 0};
123 /* report real status */
124 status = vss_status_tohuman(nmmd->vss_status_flags);
125 flags = vss_get_status_flags(nmmd->vss_status_flags);
126 if (nmmd->size) { /* parent currently has an audio file open */
127 localtime_r(&nmmd->mtime, &mtime_tm);
128 strftime(mtime, 29, "%b %d %Y", &mtime_tm);
130 clock_get_realtime(¤t_time);
132 * The calls to WRITE_STATUS_ITEM() below never fail because
133 * b->max_size is zero (unlimited), see para_printf(). However, clang
134 * is not smart enough to prove this and complains nevertheless.
135 * Casting the return value to void silences clang.
137 (void)WRITE_STATUS_ITEM(&b, SI_FILE_SIZE, "%zu\n", nmmd->size / 1024);
138 (void)WRITE_STATUS_ITEM(&b, SI_MTIME, "%s\n", mtime);
139 (void)WRITE_STATUS_ITEM(&b, SI_STATUS, "%s\n", status);
140 (void)WRITE_STATUS_ITEM(&b, SI_STATUS_FLAGS, "%s\n", flags);
141 (void)WRITE_STATUS_ITEM(&b, SI_OFFSET, "%li\n", offset);
142 (void)WRITE_STATUS_ITEM(&b, SI_AFS_MODE, "%s\n", mmd->afs_mode_string);
143 (void)WRITE_STATUS_ITEM(&b, SI_STREAM_START, "%lu.%lu\n",
144 (long unsigned)nmmd->stream_start.tv_sec,
145 (long unsigned)nmmd->stream_start.tv_usec);
146 (void)WRITE_STATUS_ITEM(&b, SI_CURRENT_TIME, "%lu.%lu\n",
147 (long unsigned)current_time.tv_sec,
148 (long unsigned)current_time.tv_usec);
155 static int check_sender_args(int argc, char * const * argv, struct sender_command_data *scd)
158 /* this has to match sender.h */
159 const char *subcmds[] = {"add", "delete", "allow", "deny", "on", "off", NULL};
161 scd->sender_num = -1;
163 return -E_COMMAND_SYNTAX;
164 for (i = 0; senders[i].name; i++)
165 if (!strcmp(senders[i].name, argv[1]))
167 PARA_DEBUG_LOG("%d:%s\n", argc, argv[1]);
168 if (!senders[i].name)
169 return -E_COMMAND_SYNTAX;
171 for (i = 0; subcmds[i]; i++)
172 if (!strcmp(subcmds[i], argv[2]))
175 return -E_COMMAND_SYNTAX;
177 if (!senders[scd->sender_num].client_cmds[scd->cmd_num])
178 return -E_SENDER_CMD;
179 switch (scd->cmd_num) {
183 return -E_COMMAND_SYNTAX;
187 if (argc != 4 || parse_cidr(argv[3], scd->host,
188 sizeof(scd->host), &scd->netmask) == NULL)
189 return -E_COMMAND_SYNTAX;
194 return -E_COMMAND_SYNTAX;
195 return parse_fec_url(argv[3], scd);
197 return -E_COMMAND_SYNTAX;
203 * Send a sideband packet through a blocking file descriptor.
205 * \param scc fd and crypto keys.
206 * \param buf The buffer to send.
207 * \param numbytes The size of \a buf.
208 * \param band The sideband designator of this packet.
209 * \param dont_free If true, never deallocate \a buf.
211 * The nonblock flag must be disabled for the file descriptor given by \a scc.
213 * Stream cipher encryption is automatically activated if neccessary via the
214 * sideband transformation, depending on the value of \a band.
218 * \sa \ref send_sb_va().
220 int send_sb(struct stream_cipher_context *scc, void *buf, size_t numbytes,
221 int band, bool dont_free)
224 struct sb_context *sbc;
226 sb_transformation trafo = band < SBD_PROCEED? NULL : sc_trafo;
227 struct sb_buffer sbb = SBB_INIT(band, buf, numbytes);
229 sbc = sb_new_send(&sbb, dont_free, trafo, scc->send);
231 ret = sb_get_send_buffers(sbc, iov);
232 ret = xwritev(scc->fd, iov, ret);
235 } while (sb_sent(sbc, ret) == false);
243 * Create a variable sized buffer and send it as a sideband packet.
245 * \param scc Passed to \ref send_sb.
246 * \param band See \ref send_sb.
247 * \param fmt The format string.
249 * \return The return value of the underlying call to \ref send_sb.
251 __printf_3_4 int send_sb_va(struct stream_cipher_context *scc, int band,
252 const char *fmt, ...)
259 ret = xvasprintf(&msg, fmt, ap);
261 return send_sb(scc, msg, ret, band, false);
265 * Send an error message to a client.
267 * \param cc Client info.
268 * \param err The (positive) error code.
270 * \return The return value of the underlying call to send_sb_va().
272 int send_strerror(struct command_context *cc, int err)
274 return send_sb_va(&cc->scc, SBD_ERROR_LOG, "%s\n", para_strerror(err));
278 * Send a sideband packet through a blocking file descriptor.
280 * \param scc fd and crypto keys.
281 * \param expected_band The expected band designator.
282 * \param max_size Passed to \ref sb_new_recv().
283 * \param result Body of the sideband packet is returned here.
285 * If \a expected_band is not \p SBD_ANY, the band designator of the received
286 * sideband packet is compared to \a expected_band and a mismatch is considered
291 int recv_sb(struct stream_cipher_context *scc,
292 enum sb_designator expected_band,
293 size_t max_size, struct iovec *result)
296 struct sb_context *sbc;
298 struct sb_buffer sbb;
299 sb_transformation trafo;
301 trafo = expected_band != SBD_ANY && expected_band < SBD_PROCEED?
303 sbc = sb_new_recv(max_size, trafo, scc->recv);
305 sb_get_recv_buffer(sbc, &iov);
306 ret = recv_bin_buffer(scc->fd, iov.iov_base, iov.iov_len);
311 ret = sb_received(sbc, ret, &sbb);
318 if (expected_band != SBD_ANY && sbb.band != expected_band)
327 static int com_sender(struct command_context *cc)
331 struct sender_command_data scd;
334 for (i = 0; senders[i].name; i++) {
336 ret = xasprintf(&tmp, "%s%s\n", msg? msg : "",
341 return send_sb(&cc->scc, msg, ret, SBD_OUTPUT, false);
343 ret = check_sender_args(cc->argc, cc->argv, &scd);
345 if (scd.sender_num < 0)
347 if (strcmp(cc->argv[2], "status") == 0)
348 msg = senders[scd.sender_num].status();
350 msg = senders[scd.sender_num].help();
351 return send_sb(&cc->scc, msg, strlen(msg), SBD_OUTPUT, false);
354 switch (scd.cmd_num) {
357 assert(senders[scd.sender_num].resolve_target);
358 ret = senders[scd.sender_num].resolve_target(cc->argv[3], &scd);
363 for (i = 0; i < 10; i++) {
364 mutex_lock(mmd_mutex);
365 if (mmd->sender_cmd_data.cmd_num >= 0) {
366 mutex_unlock(mmd_mutex);
370 mmd->sender_cmd_data = scd;
371 mutex_unlock(mmd_mutex);
374 return (i < 10)? 1 : -E_LOCK;
378 static int com_si(struct command_context *cc)
384 return -E_COMMAND_SYNTAX;
385 mutex_lock(mmd_mutex);
386 ut = daemon_get_uptime_str(now);
387 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",
397 mmd->active_connections,
401 AUDIO_FORMAT_HANDLERS
403 mutex_unlock(mmd_mutex);
405 return send_sb(&cc->scc, msg, ret, SBD_OUTPUT, false);
409 static int com_version(struct command_context *cc)
415 return -E_COMMAND_SYNTAX;
416 len = xasprintf(&msg, "%s", version_text("server"));
417 return send_sb(&cc->scc, msg, len, SBD_OUTPUT, false);
420 #define EMPTY_STATUS_ITEMS \
425 ITEM(ATTRIBUTES_BITMAP) \
426 ITEM(ATTRIBUTES_TXT) \
437 ITEM(SECONDS_TOTAL) \
449 * Write a list of audio-file related status items with empty values.
451 * This is used by vss when currently no audio file is open.
453 static unsigned empty_status_items(int parser_friendly, char **result)
459 len = xasprintf(&esi,
460 #define ITEM(x) "0004 %02x:\n"
463 #define ITEM(x) , SI_ ## x
468 len = xasprintf(&esi,
469 #define ITEM(x) "%s:\n"
472 #define ITEM(x) ,status_item_list[SI_ ## x]
479 #undef EMPTY_STATUS_ITEMS
482 static int com_stat(struct command_context *cc)
485 struct misc_meta_data tmp, *nmmd = &tmp;
488 int parser_friendly = 0;
490 para_sigaction(SIGUSR1, dummy);
492 for (i = 1; i < cc->argc; i++) {
493 const char *arg = cc->argv[i];
496 if (!strcmp(arg, "--")) {
500 if (!strncmp(arg, "-n=", 3)) {
501 ret = para_atoi32(arg + 3, &num);
506 if (!strcmp(arg, "-p")) {
510 return -E_COMMAND_SYNTAX;
513 return -E_COMMAND_SYNTAX;
516 ret = get_status(nmmd, parser_friendly, &s);
517 ret = send_sb(&cc->scc, s, ret, SBD_OUTPUT, false);
520 if (nmmd->vss_status_flags & VSS_NEXT) {
522 ret = empty_status_items(parser_friendly, &esi);
523 ret = send_sb(&cc->scc, esi, ret, SBD_OUTPUT, false);
527 send_afs_status(cc, parser_friendly);
529 if (num > 0 && !--num)
532 ret = -E_SERVER_CRASH;
540 static int send_list_of_commands(struct command_context *cc, struct server_command *cmd,
545 for (; cmd->name; cmd++) {
546 char *tmp, *perms = cmd_perms_itohuman(cmd->perms);
547 tmp = make_message("%s\t%s\t%s\t%s\n", cmd->name, handler,
548 perms, cmd->description);
550 msg = para_strcat(msg, tmp);
554 return send_sb(&cc->scc, msg, strlen(msg), SBD_OUTPUT, false);
557 /* returns string that must be freed by the caller */
558 static struct server_command *get_cmd_ptr(const char *name, char **handler)
560 struct server_command *cmd;
562 for (cmd = server_cmds; cmd->name; cmd++)
563 if (!strcmp(cmd->name, name)) {
565 *handler = para_strdup("server"); /* server commands */
568 /* not found, look for commands supported by afs */
569 for (cmd = afs_cmds; cmd->name; cmd++)
570 if (!strcmp(cmd->name, name)) {
572 *handler = para_strdup("afs");
579 static int com_help(struct command_context *cc)
581 struct server_command *cmd;
582 char *perms, *handler, *buf;
586 /* no argument given, print list of commands */
587 if ((ret = send_list_of_commands(cc, server_cmds, "server")) < 0)
589 return send_list_of_commands(cc, afs_cmds, "afs");
591 /* argument given for help */
592 cmd = get_cmd_ptr(cc->argv[1], &handler);
595 perms = cmd_perms_itohuman(cmd->perms);
596 ret = xasprintf(&buf, "%s - %s\n\n"
610 return send_sb(&cc->scc, buf, ret, SBD_OUTPUT, false);
614 static int com_hup(struct command_context *cc)
617 return -E_COMMAND_SYNTAX;
618 kill(getppid(), SIGHUP);
623 static int com_term(struct command_context *cc)
626 return -E_COMMAND_SYNTAX;
627 kill(getppid(), SIGTERM);
631 static int com_play(struct command_context *cc)
634 return -E_COMMAND_SYNTAX;
635 mutex_lock(mmd_mutex);
636 mmd->new_vss_status_flags |= VSS_PLAYING;
637 mmd->new_vss_status_flags &= ~VSS_NOMORE;
638 mutex_unlock(mmd_mutex);
643 static int com_stop(struct command_context *cc)
646 return -E_COMMAND_SYNTAX;
647 mutex_lock(mmd_mutex);
648 mmd->new_vss_status_flags &= ~VSS_PLAYING;
649 mmd->new_vss_status_flags &= ~VSS_REPOS;
650 mmd->new_vss_status_flags |= VSS_NEXT;
651 mutex_unlock(mmd_mutex);
656 static int com_pause(struct command_context *cc)
659 return -E_COMMAND_SYNTAX;
660 mutex_lock(mmd_mutex);
661 if (!vss_paused() && !vss_stopped()) {
663 mmd->new_vss_status_flags &= ~VSS_PLAYING;
664 mmd->new_vss_status_flags &= ~VSS_NEXT;
666 mutex_unlock(mmd_mutex);
671 static int com_next(struct command_context *cc)
674 return -E_COMMAND_SYNTAX;
675 mutex_lock(mmd_mutex);
677 mmd->new_vss_status_flags |= VSS_NEXT;
678 mutex_unlock(mmd_mutex);
683 static int com_nomore(struct command_context *cc)
686 return -E_COMMAND_SYNTAX;
687 mutex_lock(mmd_mutex);
688 if (vss_playing() || vss_paused())
689 mmd->new_vss_status_flags |= VSS_NOMORE;
690 mutex_unlock(mmd_mutex);
695 static int com_ff(struct command_context *cc)
698 int ret, backwards = 0;
703 return -E_COMMAND_SYNTAX;
704 if (!(ret = sscanf(cc->argv[1], "%u%c", &i, &c)))
705 return -E_COMMAND_SYNTAX;
706 if (ret > 1 && c == '-')
707 backwards = 1; /* jmp backwards */
708 mutex_lock(mmd_mutex);
709 ret = -E_NO_AUDIO_FILE;
710 if (!mmd->afd.afhi.chunks_total || !mmd->afd.afhi.seconds_total)
712 promille = (1000 * mmd->current_chunk) / mmd->afd.afhi.chunks_total;
714 promille -= 1000 * i / mmd->afd.afhi.seconds_total;
716 promille += 1000 * i / mmd->afd.afhi.seconds_total;
719 if (promille > 1000) {
720 mmd->new_vss_status_flags |= VSS_NEXT;
723 mmd->repos_request = (mmd->afd.afhi.chunks_total * promille) / 1000;
724 mmd->new_vss_status_flags |= VSS_REPOS;
725 mmd->new_vss_status_flags &= ~VSS_NEXT;
729 mutex_unlock(mmd_mutex);
734 static int com_jmp(struct command_context *cc)
740 return -E_COMMAND_SYNTAX;
741 if (sscanf(cc->argv[1], "%lu", &i) <= 0)
742 return -E_COMMAND_SYNTAX;
743 mutex_lock(mmd_mutex);
744 ret = -E_NO_AUDIO_FILE;
745 if (!mmd->afd.afhi.chunks_total)
749 PARA_INFO_LOG("jumping to %lu%%\n", i);
750 mmd->repos_request = (mmd->afd.afhi.chunks_total * i + 50)/ 100;
751 PARA_INFO_LOG("sent: %lu, offset before jmp: %lu\n",
752 mmd->chunks_sent, mmd->offset);
753 mmd->new_vss_status_flags |= VSS_REPOS;
754 mmd->new_vss_status_flags &= ~VSS_NEXT;
758 mutex_unlock(mmd_mutex);
763 * check if perms are sufficient to exec a command having perms cmd_perms.
764 * Returns 0 if perms are sufficient, -E_PERM otherwise.
766 static int check_perms(unsigned int perms, struct server_command *cmd_ptr)
768 PARA_DEBUG_LOG("checking permissions\n");
769 return (cmd_ptr->perms & perms) < cmd_ptr->perms ? -E_PERM : 0;
772 static void reset_signals(void)
774 para_sigaction(SIGCHLD, SIG_IGN);
775 para_sigaction(SIGINT, SIG_DFL);
776 para_sigaction(SIGTERM, SIG_DFL);
777 para_sigaction(SIGHUP, SIG_DFL);
780 struct connection_features {
781 bool sideband_requested;
782 bool aes_ctr128_requested;
785 static int parse_auth_request(char *buf, int len, struct user **u,
786 struct connection_features *cf)
789 char *p, *username, **features = NULL;
790 size_t auth_rq_len = strlen(AUTH_REQUEST_MSG);
793 memset(cf, 0, sizeof(*cf));
794 if (len < auth_rq_len + 2)
795 return -E_AUTH_REQUEST;
796 if (strncmp(buf, AUTH_REQUEST_MSG, auth_rq_len) != 0)
797 return -E_AUTH_REQUEST;
798 username = buf + auth_rq_len;
799 p = strchr(username, ' ');
803 return -E_AUTH_REQUEST;
806 create_argv(p, ",", &features);
807 for (i = 0; features[i]; i++) {
808 if (strcmp(features[i], "sideband") == 0)
809 cf->sideband_requested = true;
810 else if (strcmp(features[i], "aes_ctr128") == 0)
811 cf->aes_ctr128_requested = true;
813 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 < 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 *command = NULL, *buf = para_malloc(HANDSHAKE_BUFSIZE) /* must be on the heap */;
894 struct command_context cc_struct = {.peer = peername}, *cc = &cc_struct;
896 struct connection_features cf;
900 /* we need a blocking fd here as recv() might return EAGAIN otherwise. */
901 ret = mark_fd_blocking(fd);
904 /* send Welcome message */
905 ret = write_va_buffer(fd, "This is para_server, version "
906 PACKAGE_VERSION ".\n"
907 "Features: sideband,aes_ctr128\n"
911 /* recv auth request line */
912 ret = recv_buffer(fd, buf, HANDSHAKE_BUFSIZE);
915 ret = parse_auth_request(buf, ret, &cc->u, &cf);
918 if (!cf.sideband_requested) { /* sideband is mandatory */
919 PARA_ERROR_LOG("client did not request sideband\n");
920 ret = -E_BAD_FEATURE;
924 get_random_bytes_or_die(rand_buf, sizeof(rand_buf));
925 ret = pub_encrypt(cc->u->pubkey, rand_buf, sizeof(rand_buf),
926 (unsigned char *)buf);
932 * We don't want to reveal our user names, so we send a
933 * challenge to the client even if the user does not exist, and
934 * fail the authentication later.
937 get_random_bytes_or_die((unsigned char *)buf, numbytes);
939 PARA_DEBUG_LOG("sending %u byte challenge + session key (%zu bytes)\n",
940 CHALLENGE_SIZE, numbytes);
941 ret = send_sb(&cc->scc, buf, numbytes, SBD_CHALLENGE, false);
945 ret = recv_sb(&cc->scc, SBD_CHALLENGE_RESPONSE,
946 HANDSHAKE_BUFSIZE, &iov);
950 numbytes = iov.iov_len;
951 PARA_DEBUG_LOG("received %zu bytes challenge response\n", numbytes);
956 * The correct response is the hash of the first CHALLENGE_SIZE bytes
957 * of the random data.
960 if (numbytes != HASH_SIZE)
962 hash_function((char *)rand_buf, CHALLENGE_SIZE, challenge_hash);
963 if (memcmp(challenge_hash, buf, HASH_SIZE))
965 /* auth successful */
967 PARA_INFO_LOG("good auth for %s\n", cc->u->name);
968 /* init stream cipher keys with the second part of the random buffer */
969 cc->scc.recv = sc_new(rand_buf + CHALLENGE_SIZE, SESSION_KEY_LEN,
970 cf.aes_ctr128_requested);
971 cc->scc.send = sc_new(rand_buf + CHALLENGE_SIZE + SESSION_KEY_LEN,
972 SESSION_KEY_LEN, cf.aes_ctr128_requested);
973 ret = send_sb(&cc->scc, NULL, 0, SBD_PROCEED, false);
976 ret = recv_sb(&cc->scc, SBD_COMMAND, MAX_COMMAND_LEN, &iov);
979 ret = parse_sb_command(cc, &iov);
983 PARA_NOTICE_LOG("calling com_%s() for %s@%s\n", cc->cmd->name,
984 cc->u->name, peername);
985 ret = cc->cmd->handler(cc);
987 mutex_lock(mmd_mutex);
989 mutex_unlock(mmd_mutex);
993 if (send_strerror(cc, -ret) >= 0)
994 send_sb(&cc->scc, NULL, 0, SBD_EXIT__FAILURE, true);
996 PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
1000 mutex_lock(mmd_mutex);
1001 if (cc->cmd && (cc->cmd->perms & AFS_WRITE) && ret >= 0)
1003 mmd->active_connections--;
1004 mutex_unlock(mmd_mutex);
1006 ret = send_sb(&cc->scc, NULL, 0, SBD_EXIT__SUCCESS, true);
1008 PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
1010 sc_free(cc->scc.recv);
1011 sc_free(cc->scc.send);
1012 exit(ret < 0? EXIT_FAILURE : EXIT_SUCCESS);