2 * Copyright (C) 1997-2012 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. */
12 #include <sys/types.h>
20 #include "server.cmdline.h"
33 #include "user_list.h"
34 #include "server_command_list.h"
35 #include "afs_command_list.h"
39 /** Commands including options must be shorter than this. */
40 #define MAX_COMMAND_LEN 32768
43 extern struct misc_meta_data *mmd;
44 extern struct sender senders[];
45 int send_afs_status(struct command_context *cc, int parser_friendly);
47 static void dummy(__a_unused int s)
51 static void mmd_dup(struct misc_meta_data *new_mmd)
53 mutex_lock(mmd_mutex);
55 mutex_unlock(mmd_mutex);
59 * Compute human readable string containing vss status for given integer value.
61 * We don't want to use vss_playing() and friends here because we take a
62 * snapshot of the mmd struct and use the copy for computing the state of the
63 * vss. If the real data were used, we would take the mmd lock for a rather
64 * long time or risk to get an inconsistent view.
66 static char *vss_status_tohuman(unsigned int flags)
68 if (flags & VSS_PLAYING)
69 return para_strdup("playing");
71 return para_strdup("stopped");
72 return para_strdup("paused");
76 * return human readable permission string. Never returns NULL.
78 static char *cmd_perms_itohuman(unsigned int perms)
80 char *msg = para_malloc(5 * sizeof(char));
82 msg[0] = perms & AFS_READ? 'a' : '-';
83 msg[1] = perms & AFS_WRITE? 'A' : '-';
84 msg[2] = perms & VSS_READ? 'v' : '-';
85 msg[3] = perms & VSS_WRITE? 'V' : '-';
93 static char *vss_get_status_flags(unsigned int flags)
95 char *msg = para_malloc(5 * sizeof(char));
97 msg[0] = (flags & VSS_PLAYING)? 'P' : '_';
98 msg[1] = (flags & VSS_NOMORE)? 'O' : '_';
99 msg[2] = (flags & VSS_NEXT)? 'N' : '_';
100 msg[3] = (flags & VSS_REPOS)? 'R' : '_';
105 static char *get_status(struct misc_meta_data *nmmd, int parser_friendly)
108 char *status, *flags; /* vss status info */
109 /* nobody updates our version of "now" */
110 char *ut = get_server_uptime_str(NULL);
111 long offset = (nmmd->offset + 500) / 1000;
112 struct timeval current_time;
114 struct para_buffer b = {.flags = parser_friendly? PBF_SIZE_PREFIX : 0};
116 /* report real status */
117 status = vss_status_tohuman(nmmd->vss_status_flags);
118 flags = vss_get_status_flags(nmmd->vss_status_flags);
119 if (nmmd->size) { /* parent currently has an audio file open */
120 localtime_r(&nmmd->mtime, &mtime_tm);
121 strftime(mtime, 29, "%b %d %Y", &mtime_tm);
123 gettimeofday(¤t_time, NULL);
125 * The calls to WRITE_STATUS_ITEM() below never fail because
126 * b->max_size is zero (unlimited), see para_printf(). However, clang
127 * is not smart enough to prove this and complains nevertheless.
128 * Casting the return value to void silences clang.
130 (void)WRITE_STATUS_ITEM(&b, SI_FILE_SIZE, "%zu\n", nmmd->size / 1024);
131 (void)WRITE_STATUS_ITEM(&b, SI_MTIME, "%s\n", mtime);
132 (void)WRITE_STATUS_ITEM(&b, SI_STATUS, "%s\n", status);
133 (void)WRITE_STATUS_ITEM(&b, SI_STATUS_FLAGS, "%s\n", flags);
134 (void)WRITE_STATUS_ITEM(&b, SI_OFFSET, "%li\n", offset);
135 (void)WRITE_STATUS_ITEM(&b, SI_AFS_MODE, "%s\n", mmd->afs_mode_string);
136 (void)WRITE_STATUS_ITEM(&b, SI_STREAM_START, "%lu.%lu\n",
137 (long unsigned)nmmd->stream_start.tv_sec,
138 (long unsigned)nmmd->stream_start.tv_usec);
139 (void)WRITE_STATUS_ITEM(&b, SI_CURRENT_TIME, "%lu.%lu\n",
140 (long unsigned)current_time.tv_sec,
141 (long unsigned)current_time.tv_usec);
148 static int check_sender_args(int argc, char * const * argv, struct sender_command_data *scd)
151 /* this has to match sender.h */
152 const char *subcmds[] = {"add", "delete", "allow", "deny", "on", "off", NULL};
154 scd->sender_num = -1;
156 return -E_COMMAND_SYNTAX;
157 for (i = 0; senders[i].name; i++)
158 if (!strcmp(senders[i].name, argv[1]))
160 PARA_DEBUG_LOG("%d:%s\n", argc, argv[1]);
161 if (!senders[i].name)
162 return -E_COMMAND_SYNTAX;
164 for (i = 0; subcmds[i]; i++)
165 if (!strcmp(subcmds[i], argv[2]))
168 return -E_COMMAND_SYNTAX;
170 if (!senders[scd->sender_num].client_cmds[scd->cmd_num])
171 return -E_SENDER_CMD;
172 switch (scd->cmd_num) {
176 return -E_COMMAND_SYNTAX;
180 if (argc != 4 || parse_cidr(argv[3], scd->host,
181 sizeof(scd->host), &scd->netmask) == NULL)
182 return -E_COMMAND_SYNTAX;
187 return -E_COMMAND_SYNTAX;
188 return parse_fec_url(argv[3], scd);
190 return -E_COMMAND_SYNTAX;
196 * Send a sideband packet through a blocking file descriptor.
198 * \param scc fd and crypto keys.
199 * \param buf The buffer to send.
200 * \param numbytes The size of \a buf.
201 * \param band The sideband designator of this packet.
202 * \param dont_free If true, never deallocate \a buf.
204 * The nonblock flag must be disabled for the file descriptor given by \a scc.
206 * Stream cipher encryption is automatically activated if neccessary via the
207 * sideband transformation, depending on the value of \a band.
211 * \sa \ref send_sb_va().
213 int send_sb(struct stream_cipher_context *scc, void *buf, size_t numbytes,
214 int band, bool dont_free)
217 struct sb_context *sbc;
219 struct sb_buffer sbb = SBB_INIT(band, buf, numbytes);
220 sb_transformation trafo = band < SBD_PROCEED? NULL : sc_trafo;
222 sbc = sb_new_send(&sbb, dont_free, trafo, scc->send);
224 ret = sb_get_send_buffers(sbc, iov);
225 ret = xwritev(scc->fd, iov, ret);
228 } while (sb_sent(sbc, ret) == false);
236 * Create a variable sized buffer and send it as a sideband packet.
238 * \param scc Passed to \ref send_sb.
239 * \param band See \ref send_sb.
240 * \param fmt The format string.
242 * \return The return value of the underlying call to \ref send_sb.
244 __printf_3_4 int send_sb_va(struct stream_cipher_context *scc, int band,
245 const char *fmt, ...)
252 ret = xvasprintf(&msg, fmt, ap);
254 return send_sb(scc, msg, ret, band, false);
258 * Send a sideband packet through a blocking file descriptor.
260 * \param scc fd and crypto keys.
261 * \param expected_band The expected band designator.
262 * \param max_size Passed to \ref sb_new_recv().
263 * \param result Body of the sideband packet is returned here.
265 * If \a expected_band is not \p SBD_ANY, the band designator of the received
266 * sideband packet is compared to \a expected_band and a mismatch is considered
271 int recv_sb(struct stream_cipher_context *scc,
272 enum sb_designator expected_band,
273 size_t max_size, struct iovec *result)
276 struct sb_context *sbc;
278 struct sb_buffer sbb;
279 sb_transformation trafo;
281 trafo = expected_band != SBD_ANY && expected_band < SBD_PROCEED?
283 sbc = sb_new_recv(max_size, trafo, scc->recv);
285 sb_get_recv_buffer(sbc, &iov);
286 ret = recv_bin_buffer(scc->fd, iov.iov_base, iov.iov_len);
291 ret = sb_received(sbc, ret, &sbb);
298 if (expected_band != SBD_ANY && sbb.band != expected_band)
307 int com_sender(struct command_context *cc)
311 struct sender_command_data scd;
314 for (i = 0; senders[i].name; i++) {
315 char *tmp = make_message("%s%s\n",
316 msg? msg : "", senders[i].name);
320 ret = sc_send_buffer(&cc->scc, msg);
324 ret = check_sender_args(cc->argc, cc->argv, &scd);
326 if (scd.sender_num < 0)
328 msg = senders[scd.sender_num].help();
329 ret = sc_send_buffer(&cc->scc, msg);
334 switch (scd.cmd_num) {
337 assert(senders[scd.sender_num].resolve_target);
338 ret = senders[scd.sender_num].resolve_target(cc->argv[3], &scd);
343 for (i = 0; i < 10; i++) {
344 mutex_lock(mmd_mutex);
345 if (mmd->sender_cmd_data.cmd_num >= 0) {
346 mutex_unlock(mmd_mutex);
350 memcpy(&mmd->sender_cmd_data, &scd, sizeof(scd));
351 mutex_unlock(mmd_mutex);
354 return (i < 10)? 1 : -E_LOCK;
358 int com_si(struct command_context *cc)
362 char *sender_info = NULL;
365 return -E_COMMAND_SYNTAX;
366 mutex_lock(mmd_mutex);
367 for (i = 0; senders[i].name; i++) {
368 char *info = senders[i].info();
369 sender_info = para_strcat(sender_info, info);
372 ut = get_server_uptime_str(now);
373 ret = sc_send_va_buffer(&cc->scc, "version: " GIT_VERSION "\n"
374 "up: %s\nplayed: %u\n"
377 "connections (active/accepted/total): %u/%u/%u\n"
378 "current loglevel: %s\n"
379 "supported audio formats: %s\n"
384 mmd->active_connections,
388 SERVER_AUDIO_FORMATS,
391 mutex_unlock(mmd_mutex);
398 int com_version(struct command_context *cc)
401 return -E_COMMAND_SYNTAX;
402 return sc_send_buffer(&cc->scc, VERSION_TEXT("server")
403 "built: " BUILD_DATE "\n"
404 UNAME_RS ", " CC_VERSION "\n"
408 #define EMPTY_STATUS_ITEMS \
413 ITEM(ATTRIBUTES_BITMAP) \
414 ITEM(ATTRIBUTES_TXT) \
425 ITEM(SECONDS_TOTAL) \
437 * Write a list of audio-file related status items with empty values.
439 * This is used by vss when currently no audio file is open.
441 static char *empty_status_items(int parser_friendly)
445 #define ITEM(x) "0004 %02x:\n"
448 #define ITEM(x) , SI_ ## x
453 #define ITEM(x) "%s:\n"
456 #define ITEM(x) ,status_item_list[SI_ ## x]
461 #undef EMPTY_STATUS_ITEMS
464 int com_stat(struct command_context *cc)
467 struct misc_meta_data tmp, *nmmd = &tmp;
470 int parser_friendly = 0;
472 para_sigaction(SIGUSR1, dummy);
474 for (i = 1; i < cc->argc; i++) {
475 const char *arg = cc->argv[i];
478 if (!strcmp(arg, "--")) {
482 if (!strncmp(arg, "-n=", 3)) {
483 ret = para_atoi32(arg + 3, &num);
488 if (!strcmp(arg, "-p")) {
492 return -E_COMMAND_SYNTAX;
495 return -E_COMMAND_SYNTAX;
498 s = get_status(nmmd, parser_friendly);
499 ret = sc_send_buffer(&cc->scc, s);
503 if (nmmd->vss_status_flags & VSS_NEXT) {
506 esi = empty_status_items(parser_friendly);
507 ret = sc_send_buffer(&cc->scc, esi);
511 send_afs_status(cc, parser_friendly);
513 if (num > 0 && !--num)
517 return -E_SERVER_CRASH;
523 static int send_list_of_commands(struct stream_cipher_context *scc, struct server_command *cmd,
528 for (i = 1; cmd->name; cmd++, i++) {
529 char *perms = cmd_perms_itohuman(cmd->perms);
530 ret = sc_send_va_buffer(scc, "%s\t%s\t%s\t%s\n", cmd->name,
541 /* returns string that must be freed by the caller */
542 static struct server_command *get_cmd_ptr(const char *name, char **handler)
544 struct server_command *cmd;
546 for (cmd = server_cmds; cmd->name; cmd++)
547 if (!strcmp(cmd->name, name)) {
549 *handler = para_strdup("server"); /* server commands */
552 /* not found, look for commands supported by afs */
553 for (cmd = afs_cmds; cmd->name; cmd++)
554 if (!strcmp(cmd->name, name)) {
556 *handler = para_strdup("afs");
563 int com_help(struct command_context *cc)
565 struct server_command *cmd;
566 char *perms, *handler;
570 /* no argument given, print list of commands */
571 if ((ret = send_list_of_commands(&cc->scc, server_cmds, "server")) < 0)
573 return send_list_of_commands(&cc->scc, afs_cmds, "afs");
575 /* argument given for help */
576 cmd = get_cmd_ptr(cc->argv[1], &handler);
579 perms = cmd_perms_itohuman(cmd->perms);
580 ret = sc_send_va_buffer(&cc->scc,
599 int com_hup(struct command_context *cc)
602 return -E_COMMAND_SYNTAX;
603 kill(getppid(), SIGHUP);
608 int com_term(struct command_context *cc)
611 return -E_COMMAND_SYNTAX;
612 kill(getppid(), SIGTERM);
616 int com_play(struct command_context *cc)
619 return -E_COMMAND_SYNTAX;
620 mutex_lock(mmd_mutex);
621 mmd->new_vss_status_flags |= VSS_PLAYING;
622 mmd->new_vss_status_flags &= ~VSS_NOMORE;
623 mutex_unlock(mmd_mutex);
628 int com_stop(struct command_context *cc)
631 return -E_COMMAND_SYNTAX;
632 mutex_lock(mmd_mutex);
633 mmd->new_vss_status_flags &= ~VSS_PLAYING;
634 mmd->new_vss_status_flags &= ~VSS_REPOS;
635 mmd->new_vss_status_flags |= VSS_NEXT;
636 mutex_unlock(mmd_mutex);
641 int com_pause(struct command_context *cc)
644 return -E_COMMAND_SYNTAX;
645 mutex_lock(mmd_mutex);
646 if (!vss_paused() && !vss_stopped()) {
648 mmd->new_vss_status_flags &= ~VSS_PLAYING;
649 mmd->new_vss_status_flags &= ~VSS_NEXT;
651 mutex_unlock(mmd_mutex);
656 int com_next(struct command_context *cc)
659 return -E_COMMAND_SYNTAX;
660 mutex_lock(mmd_mutex);
662 mmd->new_vss_status_flags |= VSS_NEXT;
663 mutex_unlock(mmd_mutex);
668 int com_nomore(struct command_context *cc)
671 return -E_COMMAND_SYNTAX;
672 mutex_lock(mmd_mutex);
673 if (vss_playing() || vss_paused())
674 mmd->new_vss_status_flags |= VSS_NOMORE;
675 mutex_unlock(mmd_mutex);
680 int com_ff(struct command_context *cc)
683 int ret, backwards = 0;
688 return -E_COMMAND_SYNTAX;
689 if (!(ret = sscanf(cc->argv[1], "%u%c", &i, &c)))
690 return -E_COMMAND_SYNTAX;
691 if (ret > 1 && c == '-')
692 backwards = 1; /* jmp backwards */
693 mutex_lock(mmd_mutex);
694 ret = -E_NO_AUDIO_FILE;
695 if (!mmd->afd.afhi.chunks_total || !mmd->afd.afhi.seconds_total)
697 promille = (1000 * mmd->current_chunk) / mmd->afd.afhi.chunks_total;
699 promille -= 1000 * i / mmd->afd.afhi.seconds_total;
701 promille += 1000 * i / mmd->afd.afhi.seconds_total;
704 if (promille > 1000) {
705 mmd->new_vss_status_flags |= VSS_NEXT;
708 mmd->repos_request = (mmd->afd.afhi.chunks_total * promille) / 1000;
709 mmd->new_vss_status_flags |= VSS_REPOS;
710 mmd->new_vss_status_flags &= ~VSS_NEXT;
714 mutex_unlock(mmd_mutex);
719 int com_jmp(struct command_context *cc)
725 return -E_COMMAND_SYNTAX;
726 if (sscanf(cc->argv[1], "%lu", &i) <= 0)
727 return -E_COMMAND_SYNTAX;
728 mutex_lock(mmd_mutex);
729 ret = -E_NO_AUDIO_FILE;
730 if (!mmd->afd.afhi.chunks_total)
734 PARA_INFO_LOG("jumping to %lu%%\n", i);
735 mmd->repos_request = (mmd->afd.afhi.chunks_total * i + 50)/ 100;
736 PARA_INFO_LOG("sent: %lu, offset before jmp: %lu\n",
737 mmd->chunks_sent, mmd->offset);
738 mmd->new_vss_status_flags |= VSS_REPOS;
739 mmd->new_vss_status_flags &= ~VSS_NEXT;
743 mutex_unlock(mmd_mutex);
748 * check if perms are sufficient to exec a command having perms cmd_perms.
749 * Returns 0 if perms are sufficient, -E_PERM otherwise.
751 static int check_perms(unsigned int perms, struct server_command *cmd_ptr)
753 PARA_DEBUG_LOG("checking permissions\n");
754 return (cmd_ptr->perms & perms) < cmd_ptr->perms ? -E_PERM : 0;
758 * Parse first string from *cmd and lookup in table of valid commands.
759 * On error, NULL is returned.
761 static struct server_command *parse_cmd(const char *cmdstr)
766 sscanf(cmdstr, "%200s%n", buf, &n);
770 return get_cmd_ptr(buf, NULL);
773 static int read_command(struct stream_cipher_context *scc, char **result)
777 char *command = NULL;
783 ret = sc_recv_buffer(scc, buf, sizeof(buf));
789 ret = -E_COMMAND_SYNTAX;
790 if (command && numbytes + strlen(command) > MAX_COMMAND_LEN) /* DOS */
792 command = para_strcat(command, buf);
793 p = strstr(command, EOC_MSG);
799 ret = command? 1 : -E_COMMAND_SYNTAX;
809 static void reset_signals(void)
811 para_sigaction(SIGCHLD, SIG_IGN);
812 para_sigaction(SIGINT, SIG_DFL);
813 para_sigaction(SIGTERM, SIG_DFL);
814 para_sigaction(SIGHUP, SIG_DFL);
817 static int parse_auth_request(char *buf, int len, struct user **u,
821 char *p, *username, **features = NULL;
822 size_t auth_rq_len = strlen(AUTH_REQUEST_MSG);
825 *use_sideband = false;
826 if (len < auth_rq_len + 2)
827 return -E_AUTH_REQUEST;
828 if (strncmp(buf, AUTH_REQUEST_MSG, auth_rq_len) != 0)
829 return -E_AUTH_REQUEST;
830 username = buf + auth_rq_len;
831 p = strchr(username, ' ');
835 return -E_AUTH_REQUEST;
838 create_argv(p, ",", &features);
839 for (i = 0; features[i]; i++) {
840 if (strcmp(features[i], "sideband") == 0)
841 *use_sideband = true;
843 ret = -E_BAD_FEATURE;
848 PARA_DEBUG_LOG("received auth request for user %s (sideband = %s)\n",
849 username, *use_sideband? "true" : "false");
850 *u = lookup_user(username);
857 #define HANDSHAKE_BUFSIZE 4096
860 * Perform user authentication and execute a command.
862 * \param fd The file descriptor to send output to.
863 * \param peername Identifies the connecting peer.
865 * Whenever para_server accepts an incoming tcp connection on
866 * the port it listens on, it forks and the resulting child
867 * calls this function.
869 * An RSA-based challenge/response is used to authenticate
870 * the peer. It that authentication succeeds, a random
871 * session key is generated and sent back to the peer,
872 * encrypted with its RSA public key. From this point on,
873 * all transfers are crypted with this session key.
875 * Next it is checked if the peer supplied a valid server command or a command
876 * for the audio file selector. If yes, and if the user has sufficient
877 * permissions to execute that command, the function calls the corresponding
878 * command handler which does argument checking and further processing.
880 * In order to cope with a DOS attacks, a timeout is set up
881 * which terminates the function if the connection was not
882 * authenticated when the timeout expires.
884 * \sa alarm(2), crypt.c, crypt.h
886 __noreturn void handle_connect(int fd, const char *peername)
889 unsigned char rand_buf[CHALLENGE_SIZE + 2 * SESSION_KEY_LEN];
890 unsigned char challenge_hash[HASH_SIZE];
891 char *p, *command = NULL, *buf = para_malloc(HANDSHAKE_BUFSIZE) /* must be on the heap */;
893 struct command_context cc_struct = {.peer = peername}, *cc = &cc_struct;
897 /* we need a blocking fd here as recv() might return EAGAIN otherwise. */
898 ret = mark_fd_blocking(fd);
901 /* send Welcome message */
902 ret = write_va_buffer(fd, "This is para_server, version "
903 PACKAGE_VERSION ".\n"
904 "Features: sideband,foo\n"
908 /* recv auth request line */
909 ret = recv_buffer(fd, buf, HANDSHAKE_BUFSIZE);
912 ret = parse_auth_request(buf, ret, &cc->u, &cc->use_sideband);
915 p = buf + strlen(AUTH_REQUEST_MSG);
916 PARA_DEBUG_LOG("received auth request for user %s\n", p);
917 cc->u = lookup_user(p);
919 get_random_bytes_or_die(rand_buf, sizeof(rand_buf));
920 ret = pub_encrypt(cc->u->pubkey, rand_buf, sizeof(rand_buf),
921 (unsigned char *)buf);
927 * We don't want to reveal our user names, so we send a
928 * challenge to the client even if the user does not exist, and
929 * fail the authentication later.
932 get_random_bytes_or_die((unsigned char *)buf, numbytes);
934 PARA_DEBUG_LOG("sending %u byte challenge + rc4 keys (%zu bytes)\n",
935 CHALLENGE_SIZE, numbytes);
936 if (cc->use_sideband) {
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;
949 ret = write_all(fd, buf, numbytes);
952 /* recv challenge response */
953 ret = recv_bin_buffer(fd, buf, HASH_SIZE);
958 PARA_DEBUG_LOG("received %zu bytes challenge response\n", numbytes);
963 * The correct response is the hash of the first CHALLENGE_SIZE bytes
964 * of the random data.
967 if (numbytes != HASH_SIZE)
969 hash_function((char *)rand_buf, CHALLENGE_SIZE, challenge_hash);
970 if (memcmp(challenge_hash, buf, HASH_SIZE))
972 /* auth successful */
974 PARA_INFO_LOG("good auth for %s\n", cc->u->name);
975 /* init stream cipher keys with the second part of the random buffer */
976 cc->scc.recv = sc_new(rand_buf + CHALLENGE_SIZE, SESSION_KEY_LEN);
977 cc->scc.send = sc_new(rand_buf + CHALLENGE_SIZE + SESSION_KEY_LEN, SESSION_KEY_LEN);
978 if (cc->use_sideband)
979 ret = send_sb(&cc->scc, NULL, 0, SBD_PROCEED, false);
981 ret = sc_send_buffer(&cc->scc, PROCEED_MSG);
984 ret = read_command(&cc->scc, &command);
985 if (ret == -E_COMMAND_SYNTAX)
990 cc->cmd = parse_cmd(command);
993 /* valid command, check permissions */
994 ret = check_perms(cc->u->perms, cc->cmd);
997 /* valid command and sufficient perms */
998 ret = create_argv(command, "\n", &cc->argv);
1002 PARA_NOTICE_LOG("calling com_%s() for %s@%s\n", cc->cmd->name,
1003 cc->u->name, peername);
1004 ret = cc->cmd->handler(cc);
1005 free_argv(cc->argv);
1006 mutex_lock(mmd_mutex);
1007 mmd->num_commands++;
1008 mutex_unlock(mmd_mutex);
1012 sc_send_va_buffer(&cc->scc, "%s\n", para_strerror(-ret));
1014 PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
1018 sc_free(cc->scc.recv);
1019 sc_free(cc->scc.send);
1020 mutex_lock(mmd_mutex);
1021 if (cc->cmd && (cc->cmd->perms & AFS_WRITE) && ret >= 0)
1023 mmd->active_connections--;
1024 mutex_unlock(mmd_mutex);
1025 exit(ret < 0? EXIT_FAILURE : EXIT_SUCCESS);