X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fexim_monitor%2Fem_menu.c;h=6deb909da5b6d44e2888770d25945678d7356eb4;hb=af542dcfa62fc2341e8253f10c5c778b887444b9;hp=1ed70bb91bd99a7a1b51aa708463ddbe304b755a;hpb=184e88237dea64ce48076cdd0184612d057cbafd;p=exim.git diff --git a/src/exim_monitor/em_menu.c b/src/exim_monitor/em_menu.c index 1ed70bb91..6deb909da 100644 --- a/src/exim_monitor/em_menu.c +++ b/src/exim_monitor/em_menu.c @@ -1,10 +1,8 @@ -/* $Cambridge: exim/src/exim_monitor/em_menu.c,v 1.4 2007/01/08 10:50:17 ph10 Exp $ */ - /************************************************* * Exim Monitor * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2007 */ +/* Copyright (c) University of Cambridge 1995 - 2016 */ /* See the file NOTICE for conditions of use and distribution. */ @@ -135,32 +133,33 @@ menu_is_up = FALSE; * Display the message log * *************************************************/ -static void msglogAction(Widget w, XtPointer client_data, XtPointer call_data) +static void +msglogAction(Widget w, XtPointer client_data, XtPointer call_data) { int i; -uschar buffer[256]; -Widget text = text_create((uschar *)client_data, text_depth); -FILE *f = NULL; +Widget text = text_create(US client_data, text_depth); +uschar * fname = NULL; +FILE * f = NULL; w = w; /* Keep picky compilers happy */ call_data = call_data; /* End up with the split version, so message looks right when non-exist */ -for (i = 0; i < (spool_is_split? 2:1); i++) +for (i = 0; i < (spool_is_split ? 2:1); i++) { - message_subdir[0] = (i != 0)? ((uschar *)client_data)[5] : 0; - sprintf(CS buffer, "%s/msglog/%s/%s", spool_directory, message_subdir, - (uschar *)client_data); - f = fopen(CS buffer, "r"); - if (f != NULL) break; + message_subdir[0] = i != 0 ? (US client_data)[5] : 0; + fname = spool_fname(US"msglog", message_subdir, US client_data, US""); + if ((f = fopen(CS fname, "r"))) + break; } -if (f == NULL) - text_showf(text, "%s: %s\n", buffer, strerror(errno)); +if (!f) + text_showf(text, "%s: %s\n", fname, strerror(errno)); else { - while (Ufgets(buffer, 256, f) != NULL) text_show(text, buffer); + uschar buffer[256]; + while (Ufgets(buffer, sizeof(buffer), f) != NULL) text_show(text, buffer); fclose(f); } } @@ -171,10 +170,10 @@ else * Display the message body * *************************************************/ -static void bodyAction(Widget w, XtPointer client_data, XtPointer call_data) +static void +bodyAction(Widget w, XtPointer client_data, XtPointer call_data) { int i; -uschar buffer[256]; Widget text = text_create((uschar *)client_data, text_depth); FILE *f = NULL; @@ -183,19 +182,21 @@ call_data = call_data; for (i = 0; i < (spool_is_split? 2:1); i++) { - message_subdir[0] = (i != 0)? ((uschar *)client_data)[5] : 0; - sprintf(CS buffer, "%s/input/%s/%s-D", spool_directory, message_subdir, - (uschar *)client_data); - f = fopen(CS buffer, "r"); - if (f != NULL) break; + uschar * fname; + message_subdir[0] = i != 0 ? ((uschar *)client_data)[5] : 0; + fname = spool_fname(US"input", message_subdir, US client_data, US"-D"); + if ((f = fopen(CS fname, "r"))) + break; } if (f == NULL) text_showf(text, "Failed to open file: %s\n", strerror(errno)); else { + uschar buffer[256]; int count = 0; - while (Ufgets(buffer, 256, f) != NULL) + + while (Ufgets(buffer, sizeof(buffer), f) != NULL) { text_show(text, buffer); count += Ustrlen(buffer); @@ -275,8 +276,12 @@ if (pipe(pipe_fd) != 0) return; } -fcntl(pipe_fd[0], F_SETFL, O_NONBLOCK); -fcntl(pipe_fd[1], F_SETFL, O_NONBLOCK); +if ( fcntl(pipe_fd[0], F_SETFL, O_NONBLOCK) + || fcntl(pipe_fd[1], F_SETFL, O_NONBLOCK)) + { + perror("set nonblocking on pipe"); + exit(1); + } /* Delivering a message can take some time, and we want to show the output as it goes along. This requires subprocesses and is coded below. For @@ -375,7 +380,7 @@ if ((pid = fork()) == 0) /* Main process - set up an item for the main ticker to watch. */ -if (pid < 0) text_showf(text, "Failed to fork: %s\n", strerror(pid)); else +if (pid < 0) text_showf(text, "Failed to fork: %s\n", strerror(errno)); else { pipe_item *p = (pipe_item *)store_malloc(sizeof(pipe_item)); @@ -553,7 +558,8 @@ static void addrecipAction(Widget w, XtPointer client_data, XtPointer call_data) { w = w; /* Keep picky compilers happy */ call_data = call_data; -Ustrcpy(actioned_message, (uschar *)client_data); +Ustrncpy(actioned_message, client_data, 24); +actioned_message[23] = '\0'; action_required = US"-Mar"; dialog_ref_widget = menushell; create_dialog(US"Recipient address to add?", US""); @@ -569,7 +575,8 @@ static void markdelAction(Widget w, XtPointer client_data, XtPointer call_data) { w = w; /* Keep picky compilers happy */ call_data = call_data; -Ustrcpy(actioned_message, (uschar *)client_data); +Ustrncpy(actioned_message, client_data, 24); +actioned_message[23] = '\0'; action_required = US"-Mmd"; dialog_ref_widget = menushell; create_dialog(US"Recipient address to mark delivered?", US""); @@ -584,7 +591,7 @@ static void markalldelAction(Widget w, XtPointer client_data, XtPointer call_dat { w = w; /* Keep picky compilers happy */ call_data = call_data; -ActOnMessage((uschar *)client_data, US"-Mmad", US""); +ActOnMessage(US client_data, US"-Mmad", US""); } @@ -599,9 +606,10 @@ queue_item *q; uschar *sender; w = w; /* Keep picky compilers happy */ call_data = call_data; -Ustrcpy(actioned_message, (uschar *)client_data); +Ustrncpy(actioned_message, client_data, 24); +actioned_message[23] = '\0'; q = find_queue(actioned_message, queue_noop, 0); -sender = (q == NULL)? US"" : (q->sender[0] == 0)? US"<>" : q->sender; +sender = !q ? US"" : q->sender[0] == 0 ? US"<>" : q->sender; action_required = US"-Mes"; dialog_ref_widget = menushell; create_dialog(US"New sender address?", sender);