project
stringclasses
633 values
commit_id
stringlengths
7
81
target
int64
0
1
func
stringlengths
5
484k
cwe
stringclasses
131 values
big_vul_idx
float64
0
189k
idx
int64
0
522k
hash
stringlengths
34
39
size
float64
1
24k
message
stringlengths
0
11.5k
dataset
stringclasses
1 value
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void receive_pwdfile(LOGBOOK *lbs, char *server, char *error_str) { char str[256], url[256], pwd[256], *buffer, *buf, *p; int i, status, version, fh, ssl; error_str[0] = 0; do { combine_url(lbs, server, "", url, sizeof(url), &ssl); strlcpy(str, url, sizeof(str)); strcat(str, "?cmd=GetPwdFile"); // request password file if (retrieve_url(lbs, str, ssl, &buffer, TRUE) < 0) { *strchr(str, '?') = 0; sprintf(error_str, "Cannot contact elogd server at http://%s", str); return; } /* check version */ p = strstr(buffer, "ELOG HTTP "); if (!p) { sprintf(error_str, "Remote server is not an ELOG server"); xfree(buffer); return; } version = atoi(p + 10) * 100 + atoi(p + 12) * 10 + atoi(p + 14); if (version < 254) { strlcpy(str, p + 10, 10); if (strchr(str, '\r')) *strchr(str, '\r') = 0; sprintf(error_str, "Incorrect remote ELOG server version %s, must be 2.5.4 or later", str); xfree(buffer); return; } /* evaluate status */ p = strchr(buffer, ' '); if (p == NULL) { xfree(buffer); *strchr(str, '?') = 0; sprintf(error_str, "Received invalid response from elogd server at http://%s", str); xfree(buffer); return; } p++; status = atoi(p); if (status != 200 && status != 302 && status != 404) { xfree(buffer); *strchr(str, '?') = 0; sprintf(error_str, "Received invalid response from elogd server at http://%s", str); return; } p = strstr(buffer, "\r\n\r\n"); if (p == NULL) { xfree(buffer); sprintf(error_str, loc("Cannot receive \"%s\""), str); return; } p += 4; /* check for logbook access */ if (strstr(p, loc("Please login")) || strstr(p, "GetPwdFile") || status == 302) { if (strstr(buffer, "?fail=")) eprintf("\nInvalid username or password."); if (strstr(p, loc("Please login")) == NULL && strstr(p, "GetPwdFile") && isparam("unm")) eprintf("\nUser \"%s\" has no admin rights on remote server.", getparam("unm")); /* ask for username and password */ eprintf("\nPlease enter admin username to access\n%s: ", url); fgets(str, sizeof(str), stdin); while (str[strlen(str) - 1] == '\r' || str[strlen(str) - 1] == '\n') str[strlen(str) - 1] = 0; setparam("unm", str); eprintf("\nPlease enter admin password to access\n%s: ", url); read_password(str, sizeof(str)); eprintf("\n"); while (str[strlen(str) - 1] == '\r' || str[strlen(str) - 1] == '\n') str[strlen(str) - 1] = 0; do_crypt(str, pwd, sizeof(pwd)); setparam("upwd", pwd); status = 0; } } while (status != 200); get_password_file(lbs, str, sizeof(str)); fh = open(str, O_CREAT | O_RDWR | O_BINARY, 0644); if (fh < 0) { sprintf(error_str, loc("Cannot open file <b>%s</b>"), str); strcat(error_str, ": "); strcat(error_str, strerror(errno)); return; } buf = (char *) xmalloc(2 * strlen(p)); strlcpy(buf, p, 2 * strlen(p)); adjust_crlf(buf, 2 * strlen(p)); i = write(fh, buf, strlen(buf)); if (i < (int) strlen(buf)) { sprintf(error_str, loc("Cannot write to <b>%s</b>"), str); strcat(error_str, ": "); strcat(error_str, strerror(errno)); close(fh); xfree(buf); xfree(buffer); return; } TRUNCATE(fh); close(fh); xfree(buf); xfree(buffer); }
CWE-79
null
519,227
46822743569422654615774553184668241457
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int msg_compare(const void *m1, const void *m2) { return strcoll(((MSG_LIST *) m1)->string, ((MSG_LIST *) m2)->string); }
CWE-79
null
519,228
73773030272329703394215313920397021720
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void set_sid_cookie(LOGBOOK *lbs, char *sid, char *full_name) { char str[256], lb_name[256], exp[80]; BOOL global; rsprintf("HTTP/1.1 302 Found\r\n"); rsprintf("Server: ELOG HTTP %s-%s\r\n", VERSION, git_revision()); if (keep_alive) { rsprintf("Connection: Keep-Alive\r\n"); rsprintf("Keep-Alive: timeout=60, max=10\r\n"); } if (lbs) strcpy(lb_name, lbs->name); else strcpy(lb_name, "global"); /* get optional expriation from configuration file */ if (getcfg(lb_name, "Login expiration", str, sizeof(str)) || atof(str) > 0) strcpy(exp, str); else if (isparam("remember")) { strcpy(exp, "744"); /* one month by default = 31*24 */ } else exp[0] = 0; /* check if cookies should be global */ global = getcfg("global", "Password file", str, sizeof(str)); /* set the session ID cookie */ set_cookie(lbs, "sid", sid, global, exp); /* set the use full name cookie */ set_cookie(lbs, "ufnm", full_name, global, exp); /* set "remember me" cookie on login */ if (isparam("remember")) set_cookie(lbs, "urem", "1", global, "8760"); /* one year = 24*365 */ else set_cookie(lbs, "urem", "0", global, "8760"); set_redir(lbs, isparam("redir") ? getparam("redir") : ""); }
CWE-79
null
519,229
59919959015074899417011490220721930768
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void xmlencode(char *text) { int i; for (i = 0; i < (int) strlen(text); i++) { switch (text[i]) { case '<': rsprintf("&lt;"); break; case '>': rsprintf("&gt;"); break; case '&': rsprintf("&amp;"); break; case '\"': rsprintf("&quot;"); break; default: rsprintf("%c", text[i]); } } }
CWE-79
null
519,230
27145848168942111845577996110420521291
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
BOOL logged_in(LOGBOOK *lbs) { if (isparam("unm")) { if (check_login_user(lbs, getparam("unm")) && check_login(lbs, getparam("sid"))) return TRUE; } return FALSE; }
CWE-79
null
519,231
12809141692937677681270142586422636240
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void show_elog_entry(LOGBOOK *lbs, char *dec_path, char *command) { int size, i, j, k, n, n_log, status, fh, length, message_error, index, n_hidden, message_id, orig_message_id, format_flags[MAX_N_ATTR], att_hide[MAX_ATTACHMENTS], att_inline[MAX_ATTACHMENTS], n_attachments, n_lines, n_disp_attr, attr_index[MAX_N_ATTR], thumb_status, max_n_lines; char str[2 * NAME_LENGTH], str2[NAME_LENGTH], ref[256], file_enc[256], attrib[MAX_N_ATTR][NAME_LENGTH]; char date[80], text[TEXT_SIZE], menu_str[1000], cmd[256], script[256], orig_tag[80], reply_tag[MAX_REPLY_TO * 10], display[NAME_LENGTH], attachment[MAX_ATTACHMENTS][MAX_PATH_LENGTH], encoding[80], locked_by[256], att[256], lattr[256], mid[80], menu_item[MAX_N_LIST][NAME_LENGTH], format[80], slist[MAX_N_ATTR + 10][NAME_LENGTH], file_name[MAX_PATH_LENGTH], gattr[MAX_N_ATTR][NAME_LENGTH], svalue[MAX_N_ATTR + 10][NAME_LENGTH], *p, lbk_list[MAX_N_LIST][NAME_LENGTH], comment[256], class_name[80], class_value[80], fl[8][NAME_LENGTH], list[MAX_N_ATTR][NAME_LENGTH], domain[256], subdir[256], draft[256]; FILE *f; BOOL first, show_text, display_inline, subtable, email, att_links; struct tm *pts; struct tm ts; struct stat st; time_t ltime, entry_ltime; message_id = atoi(dec_path); message_error = EL_SUCCESS; _current_message_id = message_id; email = (strstr(command, "email") != NULL); att_links = (strstr(command, "att-links") != NULL); /* check for custom form to display entry */ if (getcfg(lbs->name, "Custom display form", str, sizeof(str))) { /* check if file starts with an absolute directory */ if (str[0] == DIR_SEPARATOR || str[1] == ':') strcpy(file_name, str); else { strlcpy(file_name, logbook_dir, sizeof(file_name)); strlcat(file_name, str, sizeof(file_name)); } send_file_direct(str); return; } /* check for guest access */ if (!getcfg(lbs->name, "Guest Menu commands", menu_str, sizeof(menu_str)) || logged_in(lbs)) getcfg(lbs->name, "Menu commands", menu_str, sizeof(menu_str)); /* default menu commands */ if (menu_str[0] == 0) { strcpy(menu_str, "List, New, Edit, Delete, Reply, Duplicate, Find, "); if (getcfg(lbs->name, "Password file", str, sizeof(str))) { strcat(menu_str, "Config, Logout, "); } else { strcat(menu_str, "Config, "); } strcat(menu_str, "Help"); } else { /* check for admin command */ n = strbreak(menu_str, menu_item, MAX_N_LIST, ",", FALSE); menu_str[0] = 0; for (i = 0; i < n; i++) { if (strcmp(menu_item[i], "Admin") == 0) { if (!is_admin_user(lbs, getparam("unm"))) continue; } strcat(menu_str, menu_item[i]); if (i < n - 1) strcat(menu_str, ", "); } } /*---- check next/previous message -------------------------------*/ if (strieq(command, loc("Next")) || strieq(command, loc("Previous")) || strieq(command, loc("Last")) || strieq(command, loc("First"))) { orig_message_id = message_id; if (strieq(command, loc("Last"))) message_id = el_search_message(lbs, EL_LAST, 0, FALSE); if (strieq(command, loc("First"))) message_id = el_search_message(lbs, EL_FIRST, 0, FALSE); /* avoid display of "invalid id '0'", if "start page = 0?cmd=Last" */ if (!message_id) dec_path[0] = 0; first = TRUE; do { if (strieq(command, loc("Next"))) message_id = el_search_message(lbs, EL_NEXT, message_id, FALSE); if (strieq(command, loc("Previous"))) message_id = el_search_message(lbs, EL_PREV, message_id, FALSE); if (!first) { if (strieq(command, loc("First"))) message_id = el_search_message(lbs, EL_NEXT, message_id, FALSE); if (strieq(command, loc("Last"))) message_id = el_search_message(lbs, EL_PREV, message_id, FALSE); } else first = FALSE; if (message_id == 0) { if (strieq(command, loc("Next"))) message_error = EL_LAST_MSG; else message_error = EL_FIRST_MSG; message_id = orig_message_id; break; } size = sizeof(text); el_retrieve(lbs, message_id, date, attr_list, attrib, lbs->n_attr, text, &size, orig_tag, reply_tag, attachment, encoding, locked_by, draft); /* check for locked attributes */ for (i = 0; i < lbs->n_attr; i++) { sprintf(lattr, "l%s", attr_list[i]); if (isparam(lattr) == '1' && !(isparam(attr_list[i]) && strieq(getparam(attr_list[i]), attrib[i]))) break; } if (i < lbs->n_attr) continue; /* check for attribute filter if not browsing */ if (!isparam("browsing")) { for (i = 0; i < lbs->n_attr; i++) { if (isparam(attr_list[i]) && !(isparam(attr_list[i]) && strieq(getparam(attr_list[i]), attrib[i]))) break; } if (i < lbs->n_attr) continue; } sprintf(str, "%d", message_id); for (i = 0; i < lbs->n_attr; i++) { sprintf(lattr, "l%s", attr_list[i]); if (isparam(lattr) == '1') { if (strchr(str, '?') == NULL) sprintf(str + strlen(str), "?%s=1", lattr); else sprintf(str + strlen(str), "&amp;%s=1", lattr); } } redirect(lbs, str); return; } while (TRUE); } /*---- check for valid URL ---------------------------------------*/ if (dec_path[0] && atoi(dec_path) == 0) { strencode2(str2, dec_path, sizeof(str2)); sprintf(str, "%s: <b>%s</b>", loc("Invalid URL"), str2); show_error(str); return; } /*---- get current message ---------------------------------------*/ if (message_id == 0) message_id = el_search_message(lbs, EL_LAST, 0, FALSE); status = 0; reply_tag[0] = orig_tag[0] = 0; if (message_id) { size = sizeof(text); status = el_retrieve(lbs, message_id, date, attr_list, attrib, lbs->n_attr, text, &size, orig_tag, reply_tag, attachment, encoding, locked_by, draft); if (status != EL_SUCCESS) message_error = status; else { if (_logging_level > 2) { sprintf(str, "READ entry #%d", message_id); write_logfile(lbs, str); } } } else message_error = EL_EMPTY; /*---- check for conditional attribute ----*/ evaluate_conditions(lbs, attrib); /*---- header ----*/ /* header */ if (status == EL_SUCCESS && message_error != EL_EMPTY) { str[0] = 0; if (getcfg(lbs->name, "Page Title", str, sizeof(str))) { i = build_subst_list(lbs, slist, svalue, attrib, TRUE); sprintf(mid, "%d", message_id); add_subst_list(slist, svalue, "message id", mid, &i); add_subst_time(lbs, slist, svalue, "entry time", date, &i, 0); strsubst_list(str, sizeof(str), slist, svalue, i); strip_html(str); } else strcpy(str, "ELOG"); if (email) { /* embed CSS */ show_html_header(lbs, FALSE, str, TRUE, FALSE, NULL, TRUE, 0); rsprintf("<body>\n"); } else { sprintf(ref, "%d", message_id); strlcpy(script, "OnLoad=\"document.onkeypress=browse;\"", sizeof(script)); if (str[0]) show_standard_header(lbs, TRUE, str, ref, FALSE, NULL, script, 0); else show_standard_header(lbs, TRUE, lbs->name, ref, FALSE, NULL, script, 0); } } else show_standard_header(lbs, TRUE, "", "", FALSE, NULL, NULL, 0); /*---- title ----*/ if (email) rsprintf("<table class=\"frame\" cellpadding=\"0\" cellspacing=\"0\">\n"); else show_standard_title(lbs, "", 0); /*---- menu buttons ----*/ if (!email) { rsprintf("<tr><td class=\"menuframe\">\n"); rsprintf("<table width=\"100%%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n"); rsprintf("<tr>\n"); /*---- next/previous buttons ----*/ if (!getcfg(lbs->name, "Enable browsing", str, sizeof(str)) || atoi(str) == 1) { rsprintf("<td class=\"menu1a\">\n"); /* check if first.png exists, just put link there if not */ strlcpy(file_name, resource_dir, sizeof(file_name)); if (file_name[0] && file_name[strlen(file_name) - 1] != DIR_SEPARATOR) strlcat(file_name, DIR_SEPARATOR_STR, sizeof(file_name)); strlcat(file_name, "themes", sizeof(file_name)); strlcat(file_name, DIR_SEPARATOR_STR, sizeof(file_name)); if (theme_name[0]) { strlcat(file_name, theme_name, sizeof(file_name)); strlcat(file_name, DIR_SEPARATOR_STR, sizeof(file_name)); } strlcat(file_name, "first.png", sizeof(file_name)); if (stat(file_name, &st) >= 0) { rsprintf("<input type=image name=cmd_first alt=\"%s\" title=\"%s\" src=\"first.png\">\n", loc("First entry, Ctrl-Home"), loc("First entry, Ctrl-Home")); rsprintf("<input type=image name=cmd_previous alt=\"%s\" title=\"%s\" src=\"previous.png\">\n", loc("Previous entry, Ctrl-PgUp"), loc("Previous entry, Ctrl-PgUp")); rsprintf("<input type=image name=cmd_next alt=\"%s\" title=\"%s\" src=\"next.png\">\n", loc("Next entry, Ctrl-PgDn"), loc("Next entry, Ctrl-PgDn")); rsprintf("<input type=image name=cmd_last alt=\"%s\" title=\"%s\" src=\"last.png\">\n", loc("Last entry, Ctrl-End"), loc("Last entry, Ctrl-End")); } else { rsprintf("<a href=\"%d?cmd=%s\">|&lt;</a>&nbsp;\n", message_id, loc("First")); rsprintf("<a href=\"%d?cmd=%s\">&lt;</a>&nbsp;\n", message_id, loc("Previous")); rsprintf("<a href=\"%d?cmd=%s\">&gt;</a>&nbsp;\n", message_id, loc("Next")); rsprintf("<a href=\"%d?cmd=%s\">&gt;|</a>&nbsp;\n", message_id, loc("Last")); } rsprintf("</td>\n"); } n = strbreak(menu_str, menu_item, MAX_N_LIST, ",", FALSE); rsprintf("<td class=\"menu1\">\n"); for (i = 0; i < n; i++) { /* display menu item */ strcpy(cmd, menu_item[i]); /* only display allowed commands */ if (!is_user_allowed(lbs, cmd)) continue; if (strieq(cmd, "Copy to") || strieq(cmd, "Move to")) { rsprintf("&nbsp;<input type=submit name=cmd value=\"%s\">\n", loc(cmd)); if (strieq(cmd, "Copy to")) rsprintf("<select name=destc>\n"); else rsprintf("<select name=destm>\n"); if (getcfg(lbs->name, cmd, str, sizeof(str))) { n_log = strbreak(str, lbk_list, MAX_N_LIST, ",", FALSE); for (j = 0; j < n_log; j++) rsprintf("<option value=\"%s\">%s\n", lbk_list[j], lbk_list[j]); } else { for (j = 0;; j++) { if (!enumgrp(j, str)) break; if (!is_logbook(str)) continue; if (strieq(str, lbs->name)) continue; rsprintf("<option value=\"%s\">%s\n", str, str); } } rsprintf("</select>\n"); if (i < n - 1) rsprintf("&nbsp|\n"); } else { strlcpy(str, loc(menu_item[i]), sizeof(str)); url_encode(str, sizeof(str)); if (strieq(menu_item[i], "list")) { if (getcfg(lbs->name, "Back to main", str, sizeof(str)) && atoi(str) == 1) rsprintf("&nbsp;<a href=\"../\">%s</a>&nbsp;\n", loc(menu_item[i])); else rsprintf("&nbsp;<a href=\".?id=%d\">%s</a>&nbsp;\n", message_id, loc(menu_item[i])); } else rsprintf("&nbsp;<a href=\"%d?cmd=%s\">%s</a>&nbsp;\n", message_id, str, loc(menu_item[i])); if (i < n - 1) rsprintf("|\n"); else rsprintf("\n"); } } rsprintf("</td>\n\n"); rsprintf("</table></td></tr>\n\n"); /*---- menu text ----*/ if (getcfg(lbs->name, "menu text", str, sizeof(str))) { FILE *file; char filename[256], *buf; rsprintf("<tr><td class=\"menuframe\"><span class=\"menu1\">\n"); /* check if file starts with an absolute directory */ if (str[0] == DIR_SEPARATOR || str[1] == ':') strcpy(filename, str); else { strlcpy(filename, logbook_dir, sizeof(filename)); strlcat(filename, str, sizeof(filename)); } file = fopen(filename, "rb"); if (file != NULL) { fseek(file, 0, SEEK_END); size = TELL(fileno(file)); fseek(file, 0, SEEK_SET); buf = xmalloc(size + 1); fread(buf, 1, size, file); buf[size] = 0; fclose(file); rsputs(buf); } else rsprintf("<center><b>Error: file <i>\"%s\"</i> not found</b></center>", filename); rsprintf("</span></td></tr>"); } } // if (!email) /*---- message ----*/ if (reply_tag[0] || orig_tag[0]) show_elog_thread(lbs, message_id, email, 0); if (message_error == EL_EMPTY) rsprintf("<tr><td class=\"errormsg\" colspan=2>%s</td></tr>\n", loc("Logbook is empty")); else if (message_error == EL_NO_MSG) rsprintf("<tr><td class=\"errormsg\" colspan=2>%s</td></tr>\n", loc("This entry has been deleted")); else { /* overall message table */ rsprintf("<tr><td><table class=\"listframe\" width=\"100%%\" cellspacing=\"0\" cellpadding=\"0\">\n"); /* check for locked attributes */ for (i = 0; i < lbs->n_attr; i++) { sprintf(lattr, "l%s", attr_list[i]); if (isparam(lattr) == '1') break; } if (i < lbs->n_attr) { if (isparam(attr_list[i])) sprintf(str, " %s <i>\"%s = %s\"</i>", loc("with"), attr_list[i], getparam(attr_list[i])); } else str[0] = 0; if (message_error == EL_LAST_MSG) rsprintf("<tr><td class=\"notifymsg\" colspan=2>%s %s</td></tr>\n", loc("This is the last entry"), str); if (message_error == EL_FIRST_MSG) rsprintf("<tr><td class=\"notifymsg\" colspan=2>%s %s</td></tr>\n", loc("This is the first entry"), str); /* check for mail submissions */ if (isparam("suppress")) { rsprintf("<tr><td class=\"notifymsg\" colspan=2>%s</td></tr>\n", loc("Email notification suppressed")); } else if (isparam("error")) { strencode2(str, getparam("error"), sizeof(str)); rsprintf("<tr><td class=\"errormsg\" colspan=2>%s</td></tr>\n", str); } else { for (i = 0;; i++) { sprintf(str, "mail%d", i); if (isparam(str)) { if (i == 0) rsprintf("<tr><td class=\"notifymsg\" colspan=2>"); strencode2(str, getparam(str), sizeof(str)); rsprintf("%s <b>%s</b><br>\n", loc("Email sent to"), str); } else break; } if (i > 0) rsprintf("</tr>\n"); } /*---- display message ID ----*/ _current_message_id = message_id; if (email) { rsprintf("<tr><td class=\"title1\">\n"); if (strstr(command, "oldemail") != NULL) rsprintf("%s:", loc("An old ELOG entry has been updated")); else rsprintf("%s:", loc("A new ELOG entry has been submitted")); rsprintf("</td></tr>\n"); } if (locked_by[0]) { sprintf(str, "%s %s", loc("Entry is currently edited by"), locked_by); rsprintf ("<tr><td nowrap colspan=2 class=\"errormsg\"><img src=\"stop.png\" alt=\"%s\" title=\"%s\">\n", loc("stop"), loc("stop")); rsprintf("%s.<br>%s.<br>%s.</td></tr>\n", str, loc("You can \"steal\" the lock by editing this entry"), loc("You might however then overwrite each other's modifications")); } else { if (draft[0]) { rsprintf("<tr><td nowrap colspan=2 class=\"errormsg\">%s\n", loc("This is a draft message, edit and submit it to make it permanent")); rsprintf("&nbsp;<input type=button value=\"%s\" onClick=\"window.location.href='%d?cmd=%s';\">", loc("Edit"), message_id, loc("Edit")); rsprintf("</td></tr>\n"); } } rsprintf("<tr><td class=\"attribhead\">\n"); for (i = 0; i < lbs->n_attr; i++) { strencode2(str, attrib[i], sizeof(str)); rsprintf("<input type=hidden name=\"%s\" value=\"%s\">\n", attr_list[i], str); } /* browsing flag to distinguish "/../<attr>=<value>" from browsing */ rsprintf("<input type=hidden name=browsing value=1>\n"); if (getcfg(lbs->name, "ID display", display, sizeof(display))) { j = build_subst_list(lbs, (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, attrib, TRUE); sprintf(str, "%d", message_id); add_subst_list((char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, "message id", str, &j); add_subst_time(lbs, (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, "entry time", date, &j, 0); strsubst_list(display, sizeof(display), (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, j); } else sprintf(display, "%d", message_id); if (email) { compose_base_url(lbs, str, sizeof(str), TRUE); sprintf(str + strlen(str), "%d", message_id); rsprintf("%s:&nbsp;<b>%s</b>&nbsp;&nbsp;", loc("Logbook"), lbs->name); rsprintf("%s:&nbsp;<a href=\"%s\"><b>%d</b></a>", loc("Message ID"), str, message_id); } else rsprintf("%s:&nbsp;<b>%s</b>\n", loc("Message ID"), display); /*---- display date ----*/ if (!getcfg(lbs->name, "Time format", format, sizeof(format))) strcpy(format, DEFAULT_TIME_FORMAT); entry_ltime = date_to_ltime(date); pts = localtime(&entry_ltime); assert(pts); my_strftime(str, sizeof(str), format, pts); rsprintf("&nbsp;&nbsp;&nbsp;&nbsp;%s:&nbsp;<b>%s</b>\n", loc("Entry time"), str); /*---- link to original message or reply ----*/ if (message_error != EL_FILE_ERROR && (reply_tag[0] || orig_tag[0])) { if (orig_tag[0]) { if (email) compose_base_url(lbs, ref, sizeof(ref), TRUE); else ref[0] = 0; sprintf(ref + strlen(ref), "%s", orig_tag); rsprintf("&nbsp;&nbsp;&nbsp;&nbsp;%s:&nbsp;", loc("In reply to")); rsprintf("<b><a href=\"%s\">%s</a></b>\n", ref, orig_tag); } if (reply_tag[0]) { rsprintf("&nbsp;&nbsp;&nbsp;&nbsp;%s:&nbsp;<b>", loc("Reply to this")); p = strtok(reply_tag, ","); do { if (email) compose_base_url(lbs, ref, sizeof(ref), TRUE); else ref[0] = 0; sprintf(ref + strlen(ref), "%s", p); rsprintf("<a href=\"%s\">%s</a>\n", ref, p); p = strtok(NULL, ","); if (p) rsprintf("&nbsp; \n"); } while (p); rsprintf("</b>\n"); } } rsprintf("</td></tr>\n"); /*---- display attributes ----*/ /* retrieve attribute flags */ for (i = 0; i < lbs->n_attr; i++) { format_flags[i] = 0; sprintf(str, "Format %s", attr_list[i]); if (getcfg(lbs->name, str, format, sizeof(format))) { n = strbreak(format, fl, 8, ",", FALSE); if (n > 0) format_flags[i] = atoi(fl[0]); } } /* 2 column table for all attributes */ rsprintf("<tr><td><table width=\"100%%\" cellpadding=\"0\" cellspacing=\"0\">"); subtable = 0; /* generate list of attributes to show */ if (getcfg(lbs->name, "Show attributes", str, sizeof(str))) { n_disp_attr = strbreak(str, list, MAX_N_ATTR, ",", FALSE); for (i = 0; i < n_disp_attr; i++) { for (j = 0; j < lbs->n_attr; j++) if (strieq(attr_list[j], list[i])) break; if (!strieq(attr_list[j], list[i])) /* attribute not found */ j = 0; attr_index[i] = j; } } else { for (i = 0; i < lbs->n_attr; i++) attr_index[i] = i; n_disp_attr = lbs->n_attr; } for (j = 0; j < n_disp_attr; j++) { i = attr_index[j]; if (getcfg(lbs->name, "Password file", str, sizeof(str)) && getcfg(lbs->name, "Guest display", str, sizeof(str)) && !isparam("unm")) { n = strbreak(str, gattr, MAX_N_ATTR, ",", FALSE); for (k = 0; k < n; k++) if (strieq(gattr[k], attr_list[i])) break; if (k == n) continue; } strcpy(class_name, "attribname"); strcpy(class_value, "attribvalue"); sprintf(str, "Format %s", attr_list[i]); if (getcfg(lbs->name, str, format, sizeof(format))) { n = strbreak(format, fl, 8, ",", FALSE); if (n > 1) strlcpy(class_name, fl[1], sizeof(class_name)); if (n > 2) strlcpy(class_value, fl[2], sizeof(class_value)); } if (format_flags[i] & AFF_SAME_LINE) /* if attribute on same line, do nothing */ rsprintf(""); else if (i < lbs->n_attr - 1 && (format_flags[i + 1] & AFF_SAME_LINE)) { /* if next attribute on same line, start a new subtable */ rsprintf("<tr><td colspan=2><table width=\"100%%\" cellpadding=\"0\" cellspacing=\"0\"><tr>"); subtable = 1; } else /* for normal attribute, start new row */ rsprintf("<tr>"); sprintf(lattr, "l%s", attr_list[i]); /* display cell with optional tooltip */ sprintf(str, "Tooltip %s", attr_list[i]); if (getcfg(lbs->name, str, comment, sizeof(comment))) rsprintf("<td nowrap title=\"%s\" class=\"%s\">", comment, class_name); else rsprintf("<td nowrap class=\"%s\">", class_name); if (getcfg(lbs->name, "Filtered browsing", str, sizeof(str)) && atoi(str) == 1) { if (isparam(lattr) == '1') rsprintf("<input type=\"checkbox\" checked name=\"%s\" value=\"1\">&nbsp;", lattr); else rsprintf("<input alt=\"text\" title=\"text\"type=\"checkbox\" name=\"%s\" value=\"1\">&nbsp;", lattr); } /* display checkbox for boolean attributes */ if (strieq(attr_options[i][0], "boolean")) { if (atoi(attrib[i]) == 1) rsprintf("%s:</td><td class=\"%s\"><input type=checkbox checked disabled></td>\n", attr_list[i], class_value); else rsprintf("%s:</td><td class=\"%s\"><input type=checkbox disabled></td>\n", attr_list[i], class_value); } /* display image for icon */ else if (attr_flags[i] & AF_ICON) { rsprintf("%s:</td><td class=\"%s\">\n", attr_list[i], class_value); if (attrib[i][0]) { sprintf(str, "Icon comment %s", attrib[i]); getcfg(lbs->name, str, comment, sizeof(comment)); if (comment[0]) rsprintf("<img src=\"icons/%s\" alt=\"%s\" title=\"%s\">", attrib[i], comment, comment); else rsprintf("<img src=\"icons/%s\" alt=\"%s\" title=\"%s\">", attrib[i], attrib[i], attrib[i]); } rsprintf("&nbsp;</td>\n"); } else if ((attr_flags[i] & (AF_MULTI | AF_MUSERLIST | AF_MUSEREMAIL)) && (format_flags[i] & AFF_MULTI_LINE)) { rsprintf("%s:</td><td class=\"%s\">\n", attr_list[i], class_value); /* separate options into individual lines */ strlcpy(str, attrib[i], sizeof(str)); p = strtok(str, "|"); while (p) { while (*p == ' ') p++; rsputs2(lbs, email, p); p = strtok(NULL, "|"); if (p) rsprintf("<br>"); } rsprintf("</td>\n"); } else if (attr_flags[i] & AF_DATE) { sprintf(str, "Date format %s", attr_list[i]); if (!getcfg(lbs->name, str, format, sizeof(format))) if (!getcfg(lbs->name, "Date format", format, sizeof(format))) strcpy(format, DEFAULT_DATE_FORMAT); ltime = atoi(attrib[i]); pts = localtime(&ltime); assert(pts); if (ltime == 0) strcpy(str, "-"); else my_strftime(str, sizeof(str), format, pts); rsprintf("%s:</td><td class=\"%s\">%s&nbsp;</td>\n", attr_list[i], class_value, str); } else if (attr_flags[i] & AF_DATETIME) { sprintf(str, "Time format %s", attr_list[i]); if (!getcfg(lbs->name, str, format, sizeof(format))) if (!getcfg(lbs->name, "Time format", format, sizeof(format))) strcpy(format, DEFAULT_TIME_FORMAT); ltime = atoi(attrib[i]); pts = localtime(&ltime); assert(pts); if (ltime == 0) strcpy(str, "-"); else my_strftime(str, sizeof(str), format, pts); rsprintf("%s:</td><td class=\"%s\">%s&nbsp;</td>\n", attr_list[i], class_value, str); } else { rsprintf("%s:</td><td class=\"%s\">\n", attr_list[i], class_value); sprintf(str, "Change %s", attr_list[i]); if (getcfg(lbs->name, str, display, sizeof(display))) { k = build_subst_list(lbs, (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, attrib, TRUE); sprintf(str, "%d", message_id); add_subst_list((char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, "message id", str, &k); add_subst_time(lbs, (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, "entry time", date, &k, attr_flags[i]); strsubst_list(display, sizeof(display), (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, k); } else strcpy(display, attrib[i]); if (is_html(display) && !is_script(display) && html_allowed(lbs)) rsputs(display); else rsputs2(lbs, email, display); rsprintf("&nbsp;</td>\n"); } if (i < lbs->n_attr - 1 && (format_flags[i + 1] & AFF_SAME_LINE) == 0) { /* if next attribute not on same line, close row or subtable */ if (subtable) { rsprintf("</table></td></tr>\n"); subtable = 0; } else rsprintf("</tr>"); } /* if last attribute, close row or subtable */ if (i == lbs->n_attr - 1) { if (subtable) { rsprintf("</table></td></tr>\n"); subtable = 0; } else rsprintf("</tr>"); } } rsputs("</table></td></tr>\n"); // 2 column table rsputs("</table><!-- listframe -->\n"); rsputs("</td></tr>\n"); /*---- message text ----*/ show_text = !getcfg(lbs->name, "Show text", str, sizeof(str)) || atoi(str) == 1; if (getcfg(lbs->name, "Password file", str, sizeof(str)) && getcfg(lbs->name, "Guest display", str, sizeof(str)) && !isparam("unm")) { n = strbreak(str, gattr, MAX_N_ATTR, ",", FALSE); for (j = 0; j < n; j++) if (strieq(gattr[j], "text")) break; if (j == n) show_text = FALSE; } if (show_text) { rsprintf("<tr><td class=\"messageframe\">"); if (strieq(encoding, "html")) { if (email) replace_inline_img(lbs, text); rsputs(text); } else if (strieq(encoding, "ELCode")) { rsputs_elcode(lbs, email, text); } else { rsputs("<pre class=\"messagepre\">"); rsputs2(lbs, email, text); rsputs("</pre>"); } rsputs("</td></tr>\n"); n_hidden = 0; for (i = 0, n_attachments = 0; i < MAX_ATTACHMENTS; i++) { att_inline[i] = 0; att_hide[i] = getcfg(lbs->name, "Show attachments", str, sizeof(str)) && atoi(str) == 0; if (is_inline_attachment(encoding, message_id, text, i, attachment[i])) att_inline[i] = 1; if (attachment[i][0]) n_attachments++; } if (isparam("hide")) { strlcpy(str, getparam("hide"), sizeof(str)); p = strtok(str, ","); while (p != NULL) { if (atoi(p) < MAX_ATTACHMENTS) { att_hide[atoi(p)] = 1; n_hidden++; } p = strtok(NULL, ","); } } if (isparam("show")) { strlcpy(str, getparam("show"), sizeof(str)); p = strtok(str, ","); while (p != NULL) { if (atoi(p) < MAX_ATTACHMENTS) { att_hide[atoi(p)] = 0; } p = strtok(NULL, ","); } } for (index = 0; index < MAX_ATTACHMENTS; index++) { if (attachment[index][0] && strlen(attachment[index]) > 14 && !att_inline[index]) { for (i = 0; i < (int) strlen(attachment[index]); i++) att[i] = toupper(attachment[index][i]); att[i] = 0; /* determine size of attachment */ strlcpy(file_name, lbs->data_dir, sizeof(file_name)); generate_subdir_name(attachment[index], subdir, sizeof(subdir)); strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment[index], sizeof(file_name)); thumb_status = create_thumbnail(lbs, file_name); length = 0; fh = open(file_name, O_RDONLY | O_BINARY); if (fh > 0) { lseek(fh, 0, SEEK_END); length = TELL(fh); close(fh); } strlcpy(str, attachment[index], sizeof(str)); str[13] = 0; strcpy(file_enc, attachment[index] + 14); url_encode(file_enc, sizeof(file_enc)); /* for file names with special characters like "+" */ if (email && !att_links) { retrieve_domain(domain, sizeof(domain)); sprintf(ref, "cid:att%d@%s", index, domain); } else if (email) { compose_base_url(lbs, ref, sizeof(ref), TRUE); sprintf(ref + strlen(ref), "%s", str); sprintf(ref + strlen(ref), "/%s", file_enc); } else { sprintf(ref, "%s/%s", str, file_enc); } /* overall table */ rsprintf("<tr><td><table class=\"listframe\" width=\"100%%\" cellspacing=0>\n"); rsprintf("<tr><td nowrap width=\"10%%\" class=\"attribname\">%s %d:</td>\n", loc("Attachment"), index + 1); if (email && !att_links) rsprintf("<td class=\"attribvalue\">%s\n", attachment[index] + 14); else rsprintf("<td class=\"attribvalue\"><a href=\"%s\" target=\"_blank\">%s</a>\n", ref, attachment[index] + 14); rsprintf("&nbsp;<span class=\"bytes\">"); if (length < 1024) rsprintf("%d Bytes", length); else if (length < 1024 * 1024) rsprintf("%d kB", length / 1024); else rsprintf("%1.3lf MB", length / 1024.0 / 1024.0); rsprintf("</span>\n"); /* retrieve submission date */ memset(&ts, 0, sizeof(ts)); ts.tm_mon = (attachment[index][2] - '0') * 10 + attachment[index][3] - '0' - 1; ts.tm_mday = (attachment[index][4] - '0') * 10 + attachment[index][5] - '0'; ts.tm_year = (attachment[index][0] - '0') * 10 + attachment[index][1] - '0'; ts.tm_hour = (attachment[index][7] - '0') * 10 + attachment[index][8] - '0'; ts.tm_min = (attachment[index][9] - '0') * 10 + attachment[index][10] - '0'; ts.tm_sec = (attachment[index][11] - '0') * 10 + attachment[index][12] - '0'; if (ts.tm_year < 90) ts.tm_year += 100; ltime = mktime(&ts); /* show upload date/time only if different from entry date/time */ if (abs((int) (ltime - entry_ltime)) > 3600) { if (!getcfg(lbs->name, "Time format", format, sizeof(format))) strcpy(format, DEFAULT_TIME_FORMAT); my_strftime(str, sizeof(str), format, &ts); rsprintf("&nbsp;<span class=\"uploaded\">"); rsprintf("Uploaded %s", str); rsprintf("</span>\n"); } /* determine if displayed inline */ display_inline = is_image(file_name) || is_ascii(file_name); if (chkext(att, ".PS") || chkext(att, ".PDF")) display_inline = 0; if ((chkext(att, ".HTM") || chkext(att, ".HTML")) && is_full_html(file_name)) display_inline = 0; if (thumb_status) display_inline = 1; if (display_inline) { /* hide this / show this */ if (!email) { rsprintf("<span class=\"bytes\">"); rsprintf("&nbsp;|&nbsp;"); if (att_hide[index]) { rsprintf("<a href=\"%d?hide=", message_id); for (i = 0; i < MAX_ATTACHMENTS; i++) if (att_hide[i] && i != index) { rsprintf("%d,", i); } rsprintf("&amp;show=%d", index); rsprintf("\">%s</a>", loc("Show")); } else { rsprintf("<a href=\"%d?hide=", message_id); for (i = 0; i < MAX_ATTACHMENTS; i++) if (att_hide[i] || i == index) { rsprintf("%d,", i); } rsprintf("\">%s</a>", loc("Hide")); } /* hide all */ if (n_hidden < n_attachments) { rsprintf("&nbsp;|&nbsp;<a href=\"%d?hide=", message_id); for (i = 0; i < MAX_ATTACHMENTS; i++) if (attachment[i][0]) { rsprintf("%d,", i); } rsprintf("\">%s</a>", loc("Hide all")); } /* show all */ if (n_hidden > 0) { for (i = 0; i < MAX_ATTACHMENTS; i++) if (att_hide[i]) break; if (i < MAX_ATTACHMENTS) { rsprintf("&nbsp;|&nbsp;<a href=\"%d?show=", message_id); for (i = 0; i < MAX_ATTACHMENTS; i++) if (att_hide[i]) rsprintf("%d,", i); rsprintf("\">%s</a>", loc("Show all")); } } rsprintf("</span>\n"); } } rsprintf("</td></tr></table></td></tr>\n"); strlcpy(file_name, lbs->data_dir, sizeof(file_name)); generate_subdir_name(attachment[index], subdir, sizeof(subdir)); strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment[index], sizeof(file_name)); if (!att_hide[index] && display_inline) { if (thumb_status) { rsprintf("<tr><td class=\"attachmentframe\">\n"); if (thumb_status == 3) { rsprintf("<font color=red><b>%s</b></font>\n", loc("Cannot create thumbnail, please check ImageMagick installation")); } else { if (thumb_status == 2 && !email) { for (i = 0;; i++) { strlcpy(str, file_name, sizeof(str)); if (chkext(file_name, ".pdf") || chkext(file_name, ".ps")) if (strrchr(str, '.')) *strrchr(str, '.') = 0; sprintf(str + strlen(str), "-%d.png", i); if (file_exist(str)) { strlcpy(str, ref, sizeof(str)); if (chkext(file_name, ".pdf") || chkext(file_name, ".ps")) if (strrchr(str, '.')) *strrchr(str, '.') = 0; sprintf(str + strlen(str), "-%d.png", i); rsprintf("<a name=\"att%d\" href=\"%s\">\n", index + 1, ref); rsprintf("<img src=\"%s\" alt=\"%s\" title=\"%s\"></a>\n", str, attachment[index] + 14, attachment[index] + 14); } else break; } } else { if (!email) { rsprintf("<a name=\"att%d\" href=\"%s\">\n", index + 1, ref); strlcpy(str, ref, sizeof(str)); if (chkext(file_name, ".pdf") || chkext(file_name, ".ps")) if (strrchr(str, '.')) *strrchr(str, '.') = 0; strlcat(str, ".png", sizeof(str)); rsprintf("<img src=\"%s\" alt=\"%s\" title=\"%s\"></a>\n", str, attachment[index] + 14, attachment[index] + 14); } } } rsprintf("</td></tr>\n\n"); } else if (is_image(att)) { if (!email) { rsprintf("<tr><td class=\"attachmentframe\">\n"); rsprintf("<a name=\"att%d\"></a>\n", index + 1); rsprintf("<img src=\"%s\" alt=\"%s\" title=\"%s\">\n", ref, attachment[index] + 14, attachment[index] + 14); rsprintf("</td></tr>\n\n"); } } else { if (is_ascii(file_name)) { /* display attachment */ rsprintf("<tr><td class=\"messageframe\">\n"); /* anchor for references */ rsprintf("<a name=\"att%d\"></a>\n", index + 1); if (!chkext(att, ".HTML")) rsprintf("<pre class=\"messagepre\">"); f = fopen(file_name, "rt"); n_lines = 0; if (getcfg(lbs->name, "Attachment lines", str, sizeof(str))) max_n_lines = atoi(str); else max_n_lines = 300; if (f != NULL) { while (!feof(f)) { str[0] = 0; fgets(str, sizeof(str), f); if (n_lines < max_n_lines) { if (!chkext(att, ".HTML")) rsputs2(lbs, email, str); else rsputs(str); } n_lines++; } fclose(f); } if (!chkext(att, ".HTML")) rsprintf("</pre>"); rsprintf("\n"); if (max_n_lines == 0) rsprintf("<i><b>%d lines</b></i>\n", n_lines); else if (n_lines > max_n_lines) rsprintf("<i><b>... %d more lines ...</b></i>\n", n_lines - max_n_lines); rsprintf("</td></tr>\n"); } } } } } } } /* overall table (class "frame" from show_standard_header) */ rsprintf("\r\n</table><!-- show_standard_title -->\r\n"); show_bottom_text(lbs); if (!email) rsprintf("</form>\n"); rsprintf("</body></html>\r\n"); }
CWE-79
null
519,232
249841539360165151077677661526585724139
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int el_lock_message(LOGBOOK *lbs, int message_id, char *user, BOOL lock) /* lock message for editing */ { int size; char date[80], attrib[MAX_N_ATTR][NAME_LENGTH], text[TEXT_SIZE], in_reply_to[80], reply_to[MAX_REPLY_TO * 10], encoding[80], locked_by[256], draft[256]; char att_file[MAX_ATTACHMENTS][256]; /* retrieve message */ size = sizeof(text); el_retrieve(lbs, message_id, date, attr_list, attrib, lbs->n_attr, text, &size, in_reply_to, reply_to, att_file, encoding, locked_by, draft); /* submit message, unlocked if block == FALSE */ el_submit(lbs, message_id, TRUE, date, attr_list, attrib, lbs->n_attr, text, in_reply_to, reply_to, encoding, att_file, FALSE, lock ? user : NULL, draft); return EL_SUCCESS; }
CWE-79
null
519,233
335794541445903304185176018203272757951
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void strip_html(char *s) { char *p; while ((p = strchr(s, '<')) != NULL) { if (strchr(p, '>')) memmove(p, strchr(p, '>') + 1, strlen(strchr(p, '>') + 1) + 1); else *p = 0; } }
CWE-79
null
519,234
82552232406113800285359712642804843658
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void format_email_attachments(LOGBOOK *lbs, int message_id, int attachment_type, char att_file[MAX_ATTACHMENTS][256], char *mail_text, int size, char *multipart_boundary, int content_id) { int i, index, n_att, fh, n, is_inline, length; char str[256], file_name[256], buffer[256], domain[256], subdir[256]; /* count attachments */ for (n_att = 0; att_file[n_att][0] && n_att < MAX_ATTACHMENTS; n_att++); for (index = 0; index < MAX_ATTACHMENTS; index++) { if (att_file[index][0] == 0) continue; is_inline = is_inline_attachment(getparam("encoding"), message_id, getparam("text"), index, att_file[index]); if (attachment_type == 1 && is_inline) continue; if (attachment_type == 2 && !is_inline) continue; snprintf(mail_text + strlen(mail_text), size - strlen(mail_text) - 1, "\r\n--%s\r\n", multipart_boundary); /* return proper Content-Type for file type */ for (i = 0; i < (int) strlen(att_file[index]) && i < (int) sizeof(str) - 1; i++) str[i] = toupper(att_file[index][i]); str[i] = 0; for (i = 0; filetype[i].ext[0]; i++) if (strstr(str, filetype[i].ext)) break; if (filetype[i].ext[0]) snprintf(str, sizeof(str), "Content-Type: %s; name=\"%s\"\r\n", filetype[i].type, att_file[index] + 14); else if (strchr(str, '.') == NULL) snprintf(str, sizeof(str), "Content-Type: text/plain; name=\"%s\"\r\n", att_file[index] + 14); else snprintf(str, sizeof(str), "Content-Type: application/octet-stream; name=\"%s\"\r\n", att_file[index] + 14); strlcat(mail_text, str, size); strlcat(mail_text, "Content-Transfer-Encoding: BASE64\r\n", size); if (content_id) { retrieve_domain(domain, sizeof(domain)); snprintf(mail_text + strlen(mail_text), size - strlen(mail_text) - 1, "Content-ID: <att%d@%s>\r\n", index, domain); snprintf(mail_text + strlen(mail_text), size - strlen(mail_text) - 1, "Content-Disposition: inline; filename=\"%s\"\r\n\r\n", att_file[index] + 14); } else snprintf(mail_text + strlen(mail_text), size - strlen(mail_text) - 1, "Content-Disposition: attachment; filename=\"%s\"\r\n\r\n", att_file[index] + 14); /* encode file */ strlcpy(file_name, lbs->data_dir, sizeof(file_name)); generate_subdir_name(att_file[index], subdir, sizeof(subdir)); strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, att_file[index], sizeof(file_name)); if (is_image(file_name)) { get_thumb_name(file_name, str, sizeof(str), 0); if (str[0]) strlcpy(file_name, str, sizeof(file_name)); } fh = open(file_name, O_RDONLY | O_BINARY); length = strlen(mail_text); if (fh > 0) { do { n = my_read(fh, buffer, 45); if (n <= 0) break; base64_bufenc((unsigned char *) buffer, n, str); if (length + (int) strlen(str) + 2 < size) { strcpy(mail_text + length, str); length += strlen(str); strcpy(mail_text + length, "\r\n"); length += 2; } } while (1); close(fh); } } }
CWE-79
null
519,235
210647993199075814739439472936987788031
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void synchronize(LOGBOOK *lbs, int mode) { int i; char str[256], pwd[256]; if (mode == SYNC_HTML) { show_html_header(NULL, FALSE, loc("Synchronization"), TRUE, FALSE, NULL, FALSE, 0); rsprintf("<body>\n"); } if (lbs == NULL) { for (i = 0; lb_list[i].name[0]; i++) if (getcfg(lb_list[i].name, "mirror server", str, sizeof(str))) { if (exist_top_group() && getcfg_topgroup()) if (lb_list[i].top_group[0] && !strieq(lb_list[i].top_group, getcfg_topgroup())) continue; /* skip if excluded */ if (getcfg(lb_list[i].name, "Mirror exclude", str, sizeof(str)) && atoi(str) == 1) continue; /* if called by cron, set user name and password */ if (mode == SYNC_CRON && getcfg(lb_list[i].name, "mirror user", str, sizeof(str))) { if (get_user_line(&lb_list[i], str, pwd, NULL, NULL, NULL, NULL, NULL) == EL_SUCCESS) { setparam("unm", str); setparam("upwd", pwd); } } synchronize_logbook(&lb_list[i], mode, TRUE); } } else synchronize_logbook(lbs, mode, FALSE); if (mode == SYNC_HTML) { rsprintf("<table width=\"100%%\" cellpadding=\"1\" cellspacing=\"0\""); rsprintf("<tr><td class=\"seltitle\"><a href=\".\">%s</a></td></tr>\n", loc("Back")); rsprintf("</table><p>\n"); rsprintf("</body></html>\n"); flush_return_buffer(); keep_alive = FALSE; } }
CWE-79
null
519,236
291351882149708966947783667428723002608
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int ss_daemon_init() { #ifdef OS_UNIX /* only implemented for UNIX */ int i, fd, pid; if ((pid = fork()) < 0) return FAILURE; else if (pid != 0) _exit(EXIT_SUCCESS); /* parent finished, exit without atexit hook */ /* child continues here */ /* try and use up stdin, stdout and stderr, so other routines writing to stdout etc won't cause havoc. Copied from smbd */ for (i = 0; i < 3; i++) { close(i); fd = open("/dev/null", O_RDWR, 0); if (fd < 0) fd = open("/dev/null", O_WRONLY, 0); if (fd < 0) { eprintf("Can't open /dev/null"); return FAILURE; } if (fd != i) { eprintf("Did not get file descriptor"); return FAILURE; } } setsid(); /* become session leader */ chdir("/"); /* change working direcotry (not on NFS!) */ umask(0); /* clear our file mode creation mask */ #endif return SUCCESS; }
CWE-79
null
519,237
18070045991493195748335662837490357815
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void show_bottom_text_login(LOGBOOK *lbs) { char str[NAME_LENGTH], slist[20][NAME_LENGTH], svalue[20][NAME_LENGTH]; int i, size; if (getcfg(lbs->name, "bottom text login", str, sizeof(str))) { FILE *f; char file_name[256], *buf; if (str[0]) { /* check if file starts with an absolute directory */ if (str[0] == DIR_SEPARATOR || str[1] == ':') strcpy(file_name, str); else { strlcpy(file_name, logbook_dir, sizeof(file_name)); strlcat(file_name, str, sizeof(file_name)); } f = fopen(file_name, "rb"); if (f != NULL) { fseek(f, 0, SEEK_END); size = TELL(fileno(f)); fseek(f, 0, SEEK_SET); buf = xmalloc(size + 100); fread(buf, 1, size, f); buf[size] = 0; fclose(f); if (lbs != NULL) { i = build_subst_list(lbs, slist, svalue, NULL, TRUE); strsubst_list(buf, size + 100, slist, svalue, i); } rsputs(buf); xfree(buf); } else { if (lbs != NULL) { i = build_subst_list(lbs, slist, svalue, NULL, TRUE); strsubst_list(str, sizeof(str), slist, svalue, i); } rsputs(str); } } } else /* add little logo */ rsprintf ("<center><a class=\"bottomlink\" title=\"%s\" href=\"https://elog.psi.ch/elog/\">ELOG V%s-%s</a></center>", loc("Goto ELOG home page"), VERSION, git_revision()); }
CWE-79
null
519,238
260409178536534788332613398674810650855
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
LBLIST *get_subgroup(LBLIST pgrp, char *logbook) /* retrieve parent of group member "logbook" (which might be group by itself) */ { int i; for (i = 0; i < pgrp->n_members; i++) { /* check if logbook is current member */ if (strieq(logbook, pgrp->member[i]->name)) return &(pgrp->member[i]); /* check if logbook is in subgroup of current member */ if (pgrp->member[i]->n_members > 0 && get_subgroup(pgrp->member[i], logbook)) return get_subgroup(pgrp->member[i], logbook); } return NULL; }
CWE-79
null
519,239
335132937091636770371833654977078625616
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void show_elog_thread(LOGBOOK *lbs, int message_id, int absolute_links, int highlight_mid) { int size, head_id, n_display, n_attr_disp; char date[80], attrib[MAX_N_ATTR][NAME_LENGTH], *text, in_reply_to[80], reply_to[MAX_REPLY_TO * 10], attachment[MAX_ATTACHMENTS][MAX_PATH_LENGTH], encoding[80], locked_by[256], draft[256], disp_attr[MAX_N_ATTR + 4][NAME_LENGTH]; char *p; text = (char *) xmalloc(TEXT_SIZE); /* retrieve message */ size = TEXT_SIZE; el_retrieve(lbs, message_id, date, attr_list, attrib, lbs->n_attr, text, &size, in_reply_to, reply_to, attachment, encoding, locked_by, draft); /* find message head */ if (atoi(in_reply_to)) head_id = find_thread_head(lbs, atoi(in_reply_to)); else head_id = message_id; n_attr_disp = lbs->n_attr + 2; strcpy(disp_attr[0], loc("ID")); strcpy(disp_attr[1], loc("Date")); memcpy(disp_attr + 2, attr_list, sizeof(attr_list)); size = TEXT_SIZE; el_retrieve(lbs, head_id, date, attr_list, attrib, lbs->n_attr, text, &size, in_reply_to, reply_to, attachment, encoding, locked_by, draft); rsprintf("<tr><td><table width=\"100%%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n"); display_line(lbs, head_id, 0, "Threaded", 1, 0, FALSE, 0, FALSE, FALSE, date, in_reply_to, reply_to, n_attr_disp, disp_attr, NULL, attrib, lbs->n_attr, text, FALSE, attachment, encoding, 0, &n_display, locked_by, message_id, NULL, highlight_mid, absolute_links, draft); if (reply_to[0]) { p = reply_to; do { display_reply(lbs, atoi(p), FALSE, 1, 0, n_attr_disp, disp_attr, FALSE, 1, message_id, NULL, highlight_mid, absolute_links); while (*p && isdigit(*p)) p++; while (*p && (*p == ',' || *p == ' ')) p++; } while (*p); } rsprintf("</table>\n"); rsprintf("</td></tr>\n"); xfree(text); }
CWE-79
null
519,240
19479820971805912479659011814805337523
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void compare_attributes(LOGBOOK *lbs, int message_id, char attrib[MAX_N_ATTR][NAME_LENGTH], int *n) { int status, i, n_reply; char reply_to[MAX_REPLY_TO * 10], *attr, *list; attr = xmalloc(MAX_N_ATTR * NAME_LENGTH); assert(attr); status = el_retrieve(lbs, message_id, NULL, attr_list, (char (*)[NAME_LENGTH]) attr, lbs->n_attr, NULL, NULL, NULL, reply_to, NULL, NULL, NULL, NULL); if (status != EL_SUCCESS) { xfree(attr); return; } if (*n == 0) memcpy(attrib, attr, sizeof(MAX_N_ATTR * NAME_LENGTH)); else { for (i = 0; i < lbs->n_attr; i++) if (!strieq(attrib[i], attr + i * NAME_LENGTH)) sprintf(attrib[i], "- %s -", loc("keep original values")); } (*n)++; if (isparam("elmode") && strieq(getparam("elmode"), "threaded")) { list = xmalloc(MAX_N_ATTR * NAME_LENGTH); assert(list); // go through all replies in threaded mode n_reply = strbreak(reply_to, (char (*)[NAME_LENGTH]) list, MAX_N_ATTR, ",", FALSE); for (i = 0; i < n_reply; i++) { compare_attributes(lbs, atoi(list + i * NAME_LENGTH), attrib, n); xfree(list); } } xfree(attr); }
CWE-79
null
519,241
223275295550443499080280976192586848026
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void split_url(const char *url, char *host, int *port, char *subdir, char *param) { const char *p; char str[256]; if (host) host[0] = 0; if (port) *port = 80; if (subdir) subdir[0] = 0; if (param) param[0] = 0; p = url; if (strncmp(url, "http://", 7) == 0) p += 7; if (strncmp(url, "https://", 8) == 0) p += 8; strncpy(str, p, sizeof(str)); if (strchr(str, '/')) { if (subdir) strncpy(subdir, strchr(str, '/'), 256); *strchr(str, '/') = 0; } if (strchr(str, '?')) { if (subdir) strncpy(subdir, strchr(str, '?'), 256); *strchr(str, '?') = 0; } if (strchr(str, ':')) { if (port) *port = atoi(strchr(str, ':') + 1); *strchr(str, ':') = 0; } if (host) strcpy(host, str); if (subdir) { if (strchr(subdir, '?')) { strncpy(param, strchr(subdir, '?'), 256); *strchr(subdir, '?') = 0; } if (subdir[0] == 0) strcpy(subdir, "/"); } }
CWE-79
null
519,242
284489429107493196811922873577918801947
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void el_decode_intlist(char *message, char *key, char *result, int size) { int i; if (result == NULL) return; *result = 0; el_decode(message, key, result, size); /* remove any non allowed characters */ for (i = 0; i < size && i < (int) strlen(result); i++) if (!isdigit(result[i]) && result[i] != ' ' && result[i] != ',') result[i] = ' '; }
CWE-79
null
519,243
260168616970786914738722522532738742959
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int is_group(char *group) { int i; for (i = 0; i < n_lb_config; i++) if (strieq(group, lb_config[i].section_name)) return 1; return 0; }
CWE-79
null
519,244
243329260798827904864244517667291694855
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void rsicon(char *name, char *comment, char *elcode) { rsprintf("<img align=\"middle\" name=\"%s\" src=\"icons/elc_%s.png\" alt=\"%s\" title=\"%s\" border=\"0\"", name, name, comment, comment); rsprintf(" onclick=\"elcode(document.form1.Text, '','%s')\"", elcode); rsprintf(" onmousedown=\"document.images.%s.src='icons/eld_%s.png'\"", name, name); rsprintf(" onmouseup=\"document.images.%s.src='icons/elc_%s.png'\"", name, name); rsprintf(" onmouseover=\"this.style.cursor='pointer';\" />"); }
CWE-79
null
519,245
297710691362391677559115000287922252924
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int show_md5_page(LOGBOOK *lbs) { int i, j; char *buffer, error_str[256]; unsigned char digest[16]; /* header */ rsprintf("HTTP/1.1 200 Document follows\r\n"); rsprintf("Server: ELOG HTTP %s-%s\r\n", VERSION, git_revision()); rsprintf("Accept-Ranges: bytes\r\n"); rsprintf("Connection: close\r\n"); rsprintf("Content-Type: text/plain;charset=%s\r\n", DEFAULT_HTTP_CHARSET); rsprintf("Pragma: no-cache\r\n"); rsprintf("Cache-control: private, max-age=0, no-cache, no-store\r\n\r\n"); /* calculate MD5 for logbook section in config file */ load_config_section(lbs->name, &buffer, error_str); if (error_str[0]) rsprintf("<h2>%s</h2>", error_str); else { rsprintf("ID: %6d MD5:", 0); remove_crlf(buffer); MD5_checksum(buffer, strlen(buffer), digest); for (i = 0; i < 16; i++) rsprintf("%02X", digest[i]); rsprintf("\n"); } xfree(buffer); /* show MD5's of logbook entries */ for (i = 0; i < *lbs->n_el_index; i++) { rsprintf("ID: %6d MD5:", lbs->el_index[i].message_id); for (j = 0; j < 16; j++) rsprintf("%02X", lbs->el_index[i].md5_digest[j]); rsprintf("\n"); } keep_alive = FALSE; return EL_SUCCESS; }
CWE-79
null
519,246
205802989275820055942251592851661223332
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void show_page_navigation(LOGBOOK *lbs, int n_msg, int page_n, int n_page) { int i, num_pages, skip, max_n_msg; char ref[256], str[256]; if (!page_n || n_msg <= n_page) return; rsprintf("<tr><td class=\"menuframe\"><span class=\"menu3\">\n"); rsprintf("%s \n", loc("Goto page")); if (page_n > 1) { sprintf(ref, "page%d", page_n - 1); build_ref(ref, sizeof(ref), "", "", "", ""); rsprintf("<a href=\"%s\">%s</a>&nbsp;&nbsp;", ref, loc("Previous")); } if (page_n && n_msg > n_page) { /* number of pages */ num_pages = (n_msg - 1) / n_page + 1; skip = FALSE; for (i = 1; i <= num_pages; i++) { sprintf(ref, "page%d", i); build_ref(ref, sizeof(ref), "", "", "", ""); if (i <= 3 || (i >= page_n - 1 && i <= page_n + 1) || i >= num_pages - 2) { if (i > 1 && !skip) rsprintf(", \n"); skip = FALSE; } else { if (!skip) rsprintf("&nbsp;...&nbsp;"); skip = TRUE; } if (skip) continue; if (page_n == i) rsprintf("%d", i); else rsprintf("<a href=\"%s\">%d</a>", ref, i); /* if (i == num_pages ) rsprintf("&nbsp;&nbsp;\n"); else rsprintf(", "); */ } rsprintf("&nbsp;&nbsp;\n"); } if (page_n != -1 && n_page < n_msg && page_n * n_page < n_msg) { sprintf(ref, "page%d", page_n + 1); build_ref(ref, sizeof(ref), "", "", "", ""); rsprintf("<a href=\"%s\">%s</a>&nbsp;&nbsp;", ref, loc("Next")); } if (getcfg(lbs->name, "All display limit", str, sizeof(str))) max_n_msg = atoi(str); else max_n_msg = 500; if (page_n != -1 && n_page < n_msg && n_msg < max_n_msg) { sprintf(ref, "page"); build_ref(ref, sizeof(ref), "", "", "", ""); rsprintf("<a href=\"%s\">%s</a>\n", ref, loc("All")); } rsprintf("</span></td></tr>\n"); }
CWE-79
null
519,247
101801723397591872348187179244792640194
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void display_line(LOGBOOK *lbs, int message_id, int number, char *mode, int expand, int level, BOOL printable, int n_line, int show_attachments, int show_att_column, char *date, char *in_reply_to, char *reply_to, int n_attr_disp, char disp_attr[MAX_N_ATTR + 4][NAME_LENGTH], BOOL disp_attr_link[MAX_N_ATTR + 4], char attrib[MAX_N_ATTR][NAME_LENGTH], int n_attr, char *text, BOOL show_text, char attachment[MAX_ATTACHMENTS][MAX_PATH_LENGTH], char *encoding, BOOL select, int *n_display, char *locked_by, int highlight, regex_t *re_buf, int highlight_mid, int absolute_link, char *draft) { char str[NAME_LENGTH], ref[256], *nowrap, rowstyle[80], tdstyle[80], format[256], file_name[MAX_PATH_LENGTH], *slist, *svalue, comment[256], param[80], subdir[256]; char display[NAME_LENGTH], attr_icon[80]; int i, j, n, i_line, index, colspan, n_attachments, line_len, thumb_status, max_line_len, n_lines, max_n_lines; BOOL skip_comma; FILE *f; struct tm *pts; time_t ltime; slist = (char *) xmalloc((MAX_N_ATTR + 10) * NAME_LENGTH); svalue = (char *) xmalloc((MAX_N_ATTR + 10) * NAME_LENGTH); _current_message_id = message_id; ref[0] = 0; if (absolute_link) compose_base_url(lbs, ref, sizeof(ref), FALSE); sprintf(ref + strlen(ref), "../%s/%d", lbs->name_enc, message_id); if (strieq(mode, "Summary")) { if (draft && draft[0]) strcpy(rowstyle, "listdraft"); else if (highlight_mid == message_id) { if (number % 2 == 1) strcpy(rowstyle, "list1h"); else strcpy(rowstyle, "list2h"); } else { if (number % 2 == 1) strcpy(rowstyle, "list1"); else strcpy(rowstyle, "list2"); } } else if (strieq(mode, "Full")) { if (highlight_mid == message_id) strcpy(rowstyle, "list1h"); else strcpy(rowstyle, "list1"); } else if (strieq(mode, "Threaded")) { if (draft && draft[0]) strcpy(rowstyle, "threaddraft"); else if (highlight) { if (highlight == message_id) strcpy(rowstyle, "thread"); else strcpy(rowstyle, "threadreply"); } else { if (highlight_mid == message_id) { if (level == 0) strcpy(rowstyle, "threadh"); else strcpy(rowstyle, "threadreply"); } else { if (level == 0) strcpy(rowstyle, "thread"); else strcpy(rowstyle, "threadreply"); } } } rsprintf("<tr>"); /* check attributes for row style */ for (i = 0; i < n_attr; i++) { if (attrib[i][0] == 0) sprintf(str, "Style %s \"\"", attr_list[i]); else sprintf(str, "Style %s %s", attr_list[i], attrib[i]); if (getcfg(lbs->name, str, display, sizeof(display))) { sprintf(str, "%s\" style=\"%s", rowstyle, display); strlcpy(rowstyle, str, sizeof(rowstyle)); break; } } /* only single cell for threaded display */ if (strieq(mode, "Threaded")) { rsprintf("<td align=left class=\"%s\">", rowstyle); if (locked_by && locked_by[0]) { sprintf(str, "%s %s", loc("Entry is currently edited by"), locked_by); rsprintf("<img src=\"stop.png\" alt=\"%s\" title=\"%s\">&nbsp;", str, str); } /* show select box */ if (select && level == 0) rsprintf("<input type=checkbox name=\"s%d\" value=%d>\n", (*n_display)++, message_id); for (i = 0; i < level; i++) rsprintf("&nbsp;&nbsp;&nbsp;"); /* display "+" if expandable */ if (expand == 0 && (reply_to[0] || in_reply_to[0])) rsprintf("+&nbsp;"); } nowrap = printable ? "" : "nowrap"; skip_comma = FALSE; if (getcfg(lbs->name, "List conditions", str, sizeof(str)) && atoi(str) == 1) evaluate_conditions(lbs, attrib); if (strieq(mode, "Threaded") && getcfg(lbs->name, "Thread display", display, sizeof(display))) { /* check if to use icon from attributes */ attr_icon[0] = 0; if (getcfg(lbs->name, "Thread icon", attr_icon, sizeof(attr_icon))) { for (i = 0; i < n_attr; i++) if (strieq(attr_list[i], attr_icon)) break; if (i < n_attr && attrib[i][0]) strcpy(attr_icon, attrib[i]); else attr_icon[0] = 0; } if (highlight != message_id) rsprintf("\n<a href=\"%s\">", ref); if (attr_icon[0]) rsprintf("\n<img border=0 src=\"icons/%s\" alt=\"%s\" title=\"%s\">\n&nbsp;", attr_icon, attr_icon, attr_icon); else { /* display standard icons */ if (level == 0) rsprintf("\n<img border=0 src=\"entry.png\" alt=\"%s\" title=\"%s\">\n&nbsp;", loc("Entry"), loc("Entry")); else rsprintf("\n<img border=0 src=\"reply.png\" alt=\"%s\" title=\"%s\">\n&nbsp;", loc("Reply"), loc("Reply")); } if (highlight != message_id) rsprintf("</a>\n"); j = build_subst_list(lbs, (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, attrib, TRUE); sprintf(str, "%d", message_id); add_subst_list((char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, "message id", str, &j); add_subst_time(lbs, (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, "entry time", date, &j, 0); strsubst_list(display, sizeof(display), (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, j); if (highlight != message_id) rsprintf("\n<a href=\"%s\">\n", ref); else rsprintf("\n<b>"); if (is_html(display) && !is_script(display) && html_allowed(lbs)) rsputs(display); else rsputs2(lbs, absolute_link, display); rsputs("&nbsp;"); for (i = n = 0; i < MAX_ATTACHMENTS; i++) if (attachment && attachment[i][0]) n++; if (n > 5) { if (highlight != message_id) rsprintf("<a href=\"%s\">", ref); rsprintf("<b>%dx", n); rsprintf("<img border=\"0\" align=\"absmiddle\" src=\"attachment.png\"></b></a>"); } else { for (i = 0; i < MAX_ATTACHMENTS; i++) if (attachment && attachment[i][0]) { strlcpy(str, attachment[i], sizeof(str)); str[13] = 0; sprintf(ref, "../%s/%s/%s", lbs->name, str, attachment[i] + 14); url_encode(ref, sizeof(ref)); /* for file names with special characters like "+" */ rsprintf("<a href=\"%s\" target=\"_blank\">", ref); rsprintf ("<img border=\"0\" align=\"absmiddle\" src=\"attachment.png\" alt=\"%s\" title=\"%s\"></a>", attachment[i] + 14, attachment[i] + 14); } } if (highlight != message_id) rsprintf("</a>\n", ref); else rsprintf("</b>\n"); } else { /* show select box */ if (select && !strieq(mode, "Threaded")) { rsprintf("<td class=\"%s\">", rowstyle); rsprintf("<input type=checkbox name=\"s%d\" value=%d>\n", (*n_display)++, message_id); rsprintf("</td>\n"); } if (strieq(mode, "Threaded")) { if (highlight != message_id) rsprintf("\n<a href=\"%s\">\n", ref); else rsprintf("\n<b>"); } skip_comma = TRUE; for (index = 0; index < n_attr_disp; index++) { if (strieq(disp_attr[index], loc("ID"))) { if (strieq(mode, "Threaded")) { if (level == 0) rsprintf("\n<img border=0 src=\"entry.png\" alt=\"%s\" title=\"%s\">&nbsp;", loc("Entry"), loc("Entry")); else rsprintf("\n<img border=0 src=\"reply.png\" alt=\"%s\" title=\"%s\">&nbsp;", loc("Reply"), loc("Reply")); } else { rsprintf("<td class=\"%s\">", rowstyle); if (locked_by && locked_by[0]) { sprintf(str, "%s %s", loc("Entry is currently edited by"), locked_by); rsprintf("\n<img src=\"stop.png\" alt=\"%s\" title=\"%s\">&nbsp;", str, str); } if (draft && draft[0]) { strlcpy(display, loc("Draft"), sizeof(display)); } else { if (getcfg(lbs->name, "ID display", display, sizeof(display))) { j = build_subst_list(lbs, (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, attrib, TRUE); sprintf(str, "%d", message_id); add_subst_list((char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, "message id", str, &j); add_subst_time(lbs, (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, "entry time", date, &j, 0); strsubst_list(display, sizeof(display), (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, j); } else sprintf(display, "%d", message_id); } rsprintf("\n<a href=\"%s\">&nbsp;&nbsp;%s&nbsp;&nbsp;</a>\n", ref, display); rsprintf("</td>\n"); } } if (strieq(disp_attr[index], loc("Logbook"))) { if (strieq(mode, "Threaded")) { if (skip_comma) { rsprintf(" %s", lbs->name); skip_comma = FALSE; } else rsprintf(", %s", lbs->name); } else { if (disp_attr_link == NULL || disp_attr_link[index]) rsprintf("\n<td class=\"%s\" %s><a href=\"%s\">%s</a></td>\n", rowstyle, nowrap, ref, lbs->name); else rsprintf("\n<td class=\"%s\" %s>%s</td>\n", rowstyle, nowrap, lbs->name); } } if (strieq(disp_attr[index], loc("Edit"))) { if (!strieq(mode, "Threaded")) { rsprintf("\n<td class=\"%s\" %s><a href=\"%s?cmd=%s\">", rowstyle, nowrap, ref, loc("Edit")); rsprintf("\n<img src=\"edit.png\" border=0 alt=\"%s\" title=\"%s\"></a></td>\n", loc("Edit entry"), loc("Edit entry")); } } if (strieq(disp_attr[index], loc("Delete"))) { if (!strieq(mode, "Threaded")) { rsprintf("\n<td class=\"%s\" %s><a href=\"%s?cmd=%s\">", rowstyle, nowrap, ref, loc("Delete")); rsprintf("\n<img src=\"delete.png\" border=0 alt=\"%s\" title=\"%s\"></a></td>\n", loc("Delete entry"), loc("Delete entry")); } } if (strieq(disp_attr[index], loc("Date"))) { if (!getcfg(lbs->name, "Time format", format, sizeof(format))) strcpy(format, DEFAULT_TIME_FORMAT); ltime = date_to_ltime(date); pts = localtime(&ltime); assert(pts); my_strftime(str, sizeof(str), format, pts); if (strieq(mode, "Threaded")) { if (skip_comma) { rsprintf(" %s", str); skip_comma = FALSE; } else rsprintf(", %s", str); } else { if (disp_attr_link == NULL || disp_attr_link[index]) rsprintf("\n<td class=\"%s\" %s><a href=\"%s\">%s</a></td>\n", rowstyle, nowrap, ref, str); else rsprintf("\n<td class=\"%s\" %s>%s</td>\n", rowstyle, nowrap, str); } } for (i = 0; i < n_attr; i++) if (strieq(disp_attr[index], attr_list[i])) { /* check attributes for cell style */ strlcpy(tdstyle, rowstyle, sizeof(tdstyle)); sprintf(str, "Cell Style %s %s", attr_list[i], attrib[i]); if (getcfg(lbs->name, str, display, sizeof(display))) { sprintf(str, "%s\" style=\"%s", rowstyle, display); strlcpy(tdstyle, str, sizeof(rowstyle)); } if (strieq(mode, "Threaded")) { if (strieq(attr_options[i][0], "boolean")) { if (atoi(attrib[i]) == 1) { if (skip_comma) { rsprintf(" "); skip_comma = FALSE; } else rsprintf(", "); if (is_html(attrib[i]) && !is_script(attrib[i]) && html_allowed(lbs)) rsputs(attrib[i]); else rsputs2(lbs, absolute_link, attrib[i]); rsprintf("&nbsp"); } } else if (attr_flags[i] & AF_DATE) { if (skip_comma) { rsprintf(" "); skip_comma = FALSE; } else rsprintf(", "); sprintf(str, "Date format %s", attr_list[i]); if (!getcfg(lbs->name, str, format, sizeof(format))) if (!getcfg(lbs->name, "Date format", format, sizeof(format))) strcpy(format, DEFAULT_DATE_FORMAT); ltime = atoi(attrib[i]); pts = localtime(&ltime); assert(pts); if (ltime == 0) strcpy(str, "-"); else my_strftime(str, sizeof(str), format, pts); rsputs(str); } else if (attr_flags[i] & AF_DATETIME) { if (skip_comma) { rsprintf(" "); skip_comma = FALSE; } else rsprintf(", "); sprintf(str, "Time format %s", attr_list[i]); if (!getcfg(lbs->name, str, format, sizeof(format))) if (!getcfg(lbs->name, "Time format", format, sizeof(format))) strcpy(format, DEFAULT_TIME_FORMAT); ltime = atoi(attrib[i]); pts = localtime(&ltime); assert(pts); if (ltime == 0) strcpy(str, "-"); else my_strftime(str, sizeof(str), format, pts); rsputs(str); } else if (attr_flags[i] & AF_ICON) { sprintf(str, "Icon comment %s", attrib[i]); getcfg(lbs->name, str, comment, sizeof(comment)); if (!comment[0]) strcpy(comment, attrib[i]); if (attrib[i][0]) rsprintf("&nbsp;\n<img border=0 src=\"icons/%s\" alt=\"%s\" title=\"%s\">&nbsp;", attrib[i], comment, comment); } else { if (skip_comma) { rsprintf(" "); skip_comma = FALSE; } else rsprintf(", "); if (is_html(attrib[i]) && !is_script(attrib[i]) && html_allowed(lbs)) rsputs(attrib[i]); else rsputs2(lbs, absolute_link, attrib[i]); } } else { if (strieq(attr_options[i][0], "boolean")) { if (atoi(attrib[i]) == 1) rsprintf("\n<td class=\"%s\"><input type=checkbox checked disabled></td>\n", tdstyle); else rsprintf("\n<td class=\"%s\"><input type=checkbox disabled></td>\n", tdstyle); } else if (attr_flags[i] & AF_DATE) { sprintf(str, "Date format %s", attr_list[i]); if (!getcfg(lbs->name, str, format, sizeof(format))) if (!getcfg(lbs->name, "Date format", format, sizeof(format))) strcpy(format, DEFAULT_DATE_FORMAT); ltime = atoi(attrib[i]); pts = localtime(&ltime); assert(pts); if (ltime == 0) strcpy(str, "-"); else my_strftime(str, sizeof(str), format, pts); if (disp_attr_link == NULL || disp_attr_link[index]) rsprintf("\n<td class=\"%s\" %s><a href=\"%s\">%s</a></td>\n", tdstyle, nowrap, ref, str); else rsprintf("\n<td class=\"%s\" %s>%s</td>\n", tdstyle, nowrap, str); } else if (attr_flags[i] & AF_DATETIME) { sprintf(str, "Time format %s", attr_list[i]); if (!getcfg(lbs->name, str, format, sizeof(format))) if (!getcfg(lbs->name, "Time format", format, sizeof(format))) strcpy(format, DEFAULT_TIME_FORMAT); ltime = atoi(attrib[i]); pts = localtime(&ltime); assert(pts); if (ltime == 0) strcpy(str, "-"); else my_strftime(str, sizeof(str), format, pts); if (disp_attr_link == NULL || disp_attr_link[index]) rsprintf("\n<td class=\"%s\" %s><a href=\"%s\">%s</a></td>\n", tdstyle, nowrap, ref, str); else rsprintf("\n<td class=\"%s\" %s>%s</td>\n", tdstyle, nowrap, str); } else if (attr_flags[i] & AF_ICON) { rsprintf("<td class=\"%s\">", rowstyle); sprintf(str, "Icon comment %s", attrib[i]); getcfg(lbs->name, str, comment, sizeof(comment)); if (!comment[0]) strcpy(comment, attrib[i]); if (attrib[i][0]) rsprintf("\n<img border=0 src=\"icons/%s\" alt=\"%s\" title=\"%s\">", attrib[i], comment, comment); rsprintf("&nbsp;</td>"); } else { rsprintf("<td class=\"%s\">", tdstyle); if (disp_attr_link == NULL || disp_attr_link[index]) rsprintf("<a href=\"%s\">", ref); sprintf(str, "List Change %s", attr_list[i]); if (getcfg(lbs->name, str, display, sizeof(display))) { j = build_subst_list(lbs, (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, attrib, TRUE); sprintf(str, "%d", message_id); add_subst_list((char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, "message id", str, &j); add_subst_time(lbs, (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, "entry time", date, &j, 0); strsubst_list(display, sizeof(display), (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, j); } else strcpy(display, attrib[i]); if (is_html(display) && !is_script(display) && html_allowed(lbs)) rsputs(display); else { if (isparam(attr_list[i])) { highlight_searchtext(re_buf + 1 + i, display, str, TRUE); strlcpy(display, str, sizeof(display)); } else if (isparam("subtext") && isparam("sall") && atoi(getparam("sall"))) { highlight_searchtext(re_buf, display, str, TRUE); strlcpy(display, str, sizeof(display)); } rsputs2(lbs, absolute_link, display); } if (disp_attr_link == NULL || disp_attr_link[index]) rsprintf("</a>"); /* at least one space to produce non-empty table cell */ if (!display[0]) rsprintf("&nbsp;"); rsprintf("</td>"); } } } } if (strieq(mode, "Threaded")) { rsputs("&nbsp;"); for (i = n = 0; i < MAX_ATTACHMENTS; i++) if (attachment && attachment[i][0]) n++; if (n > 5) { if (highlight != message_id) rsprintf("<a href=\"%s\">", ref); rsprintf("<b>%dx", n); rsprintf("<img border=\"0\" align=\"absmiddle\" src=\"attachment.png\"></b></a>"); } else { for (i = 0; i < MAX_ATTACHMENTS; i++) if (attachment && attachment[i][0]) { strlcpy(str, attachment[i], sizeof(str)); str[13] = 0; sprintf(ref, "../%s/%s/%s", lbs->name, str, attachment[i] + 14); url_encode(ref, sizeof(ref)); /* for file names with special characters like "+" */ rsprintf("<a href=\"%s\" target=\"_blank\">", ref); rsprintf ("<img border=\"0\" align=\"absmiddle\" src=\"attachment.png\" alt=\"%s\" title=\"%s\"></a>", attachment[i] + 14, attachment[i] + 14); } } if (highlight != message_id) rsprintf("</a>\n"); else rsprintf("</b>\n"); } } if (strieq(mode, "Threaded") && expand > 1 && show_text) { rsprintf("</td></tr>\n"); rsprintf("<tr><td class=\"summary\">"); if (expand == 2) { for (i = i_line = line_len = 0; i < (int) sizeof(str) - 1; i++, line_len++) { str[i] = text[i]; if (line_break(text + i, encoding)) { i_line++; line_len = 0; } else /* limit line length to 150 characters */ if (line_len > 150 && text[i] == ' ') { str[i] = '\n'; i_line++; line_len = 0; } if (i_line == n_line) break; } str[i] = 0; /* only show text, not to rip apart HTML documents, e.g. only the start of a table */ if (strieq(encoding, "HTML")) strip_html(str); if (str[0]) strencode_nouml(str); else rsputs("&nbsp;"); } else { if (strieq(encoding, "plain")) { rsputs("<pre>"); if (text[0]) rsputs2(lbs, absolute_link, text); else rsputs("&nbsp;"); rsputs("</pre>"); } else if (strieq(encoding, "ELCode")) rsputs_elcode(lbs, FALSE, text); else if (text[0]) rsputs(text); else rsputs("&nbsp;"); } rsprintf("</td></tr>\n"); } if (strieq(mode, "Summary") && n_line > 0 && show_text) { rsprintf("<td class=\"summary\">"); if (getcfg(lbs->name, "Summary line length", param, sizeof(param))) max_line_len = atoi(param); else max_line_len = n_line >= 10 ? 140 : 40; for (i = i_line = line_len = 0; i < (int) sizeof(str) - 1; line_len++, i++) { str[i] = text[i]; if (line_break(text + i, encoding)) { i_line++; line_len = 0; } else /* limit line length to max_line_len characters */ if (line_len > max_line_len && text[i] == ' ') { str[i] = '\n'; i_line++; line_len = 0; } if (i_line == n_line) break; } str[i] = 0; /* only show text, not to rip apart HTML documents, e.g. only the start of a table */ if (strieq(encoding, "HTML")) strip_html(str); if (str[0]) strencode_nouml(str); else rsputs("&nbsp;"); rsputs("</td>\n"); } if (show_att_column) { /* show attachment icons */ rsputs("<td class=\"listatt\">&nbsp;"); for (i = n = 0; i < MAX_ATTACHMENTS; i++) if (attachment && attachment[i][0]) n++; if (n > 5) { if (highlight != message_id) rsprintf("<a href=\"%s\">", ref); rsprintf("<b>%dx", n); rsprintf("<img border=\"0\" align=\"absmiddle\" src=\"attachment.png\"></b></a>"); } else { for (i = 0; i < MAX_ATTACHMENTS; i++) if (attachment && attachment[i][0]) { strlcpy(str, attachment[i], sizeof(str)); str[13] = 0; sprintf(ref, "../%s/%s/%s", lbs->name, str, attachment[i] + 14); url_encode(ref, sizeof(ref)); /* for file names with special characters like "+" */ rsprintf("<a href=\"%s\" target=\"_blank\">", ref); rsprintf ("<img border=\"0\" align=\"absmiddle\" src=\"attachment.png\" alt=\"%s\" title=\"%s\"></a>", attachment[i] + 14, attachment[i] + 14); } } rsputs("&nbsp;</td>"); } colspan = n_attr_disp; if (select) colspan++; if (strieq(mode, "Full") && show_text) { if (!getcfg(lbs->name, "Show text", str, sizeof(str)) || atoi(str) == 1) { rsprintf("<tr><td class=\"messagelist\" colspan=%d>", colspan); if (strieq(encoding, "plain")) { rsputs("<pre>"); rsputs2(lbs, absolute_link, text); rsputs("</pre>"); } else if (strieq(encoding, "ELCode")) rsputs_elcode(lbs, FALSE, text); else rsputs(text); rsprintf("</td></tr>\n"); } /* count number of attachments */ n_attachments = 0; if (show_attachments) { for (index = 0; index < MAX_ATTACHMENTS; index++) { if (attachment[index][0]) { /* check if attachment is inlined */ sprintf(str, "[img]elog:/%d[/img]", index + 1); if (strieq(encoding, "ELCode") && stristr(text, str)) continue; n_attachments++; } } } for (index = 0; index < MAX_ATTACHMENTS; index++) { if (show_attachments && attachment[index][0]) { /* check if attachment is inlined */ if (is_inline_attachment(encoding, message_id, text, index, attachment[index])) continue; strlcpy(str, attachment[index], sizeof(str)); str[13] = 0; sprintf(ref, "../%s/%s/%s", lbs->name, str, attachment[index] + 14); url_encode(ref, sizeof(ref)); /* for file names with special characters like "+" */ strlcpy(file_name, lbs->data_dir, sizeof(file_name)); generate_subdir_name(attachment[index], subdir, sizeof(subdir)); strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment[index], sizeof(file_name)); thumb_status = create_thumbnail(lbs, file_name); if (!show_attachments) { rsprintf("<a href=\"%s\" target=\"_blank\">%s</a>&nbsp;&nbsp;&nbsp;&nbsp; ", ref, attachment[index] + 14); } else { if (thumb_status) { rsprintf ("<tr><td colspan=%d class=\"attachment\">%s %d: <a href=\"%s\" target=\"_blank\">%s</a>\n", colspan, loc("Attachment"), index + 1, ref, attachment[index] + 14); if (show_attachments) { rsprintf("<tr><td colspan=%d class=\"attachmentframe\">\n", colspan); if (thumb_status == 2) { for (i = 0;; i++) { strlcpy(str, file_name, sizeof(str)); if (chkext(str, ".pdf") || chkext(str, ".ps")) if (strrchr(str, '.')) *strrchr(str, '.') = 0; sprintf(str + strlen(str), "-%d.png", i); if (file_exist(str)) { strlcpy(str, ref, sizeof(str)); if (chkext(file_name, ".pdf") || chkext(file_name, ".ps")) if (strrchr(str, '.')) *strrchr(str, '.') = 0; sprintf(str + strlen(str), "-%d.png", i); rsprintf("<a name=\"att%d\" href=\"%s\">\n", index + 1, ref); rsprintf("<img src=\"%s\" alt=\"%s\" title=\"%s\"></a>\n", str, attachment[index] + 14, attachment[index] + 14); } else break; } } else { rsprintf("<a name=\"att%d\" href=\"%s\">\n", index + 1, ref); strlcpy(str, ref, sizeof(str)); if (chkext(str, ".pdf") || chkext(str, ".ps")) if (strrchr(str, '.')) *strrchr(str, '.') = 0; strlcat(str, ".png", sizeof(str)); rsprintf("<img src=\"%s\" alt=\"%s\" title=\"%s\"></a>\n", str, attachment[index] + 14, attachment[index] + 14); } rsprintf("</td></tr>\n\n"); } } else { if (is_image(attachment[index])) { rsprintf ("<tr><td colspan=%d class=\"attachment\">%s %d: <a href=\"%s\" target=\"_blank\">%s</a>\n", colspan, loc("Attachment"), index + 1, ref, attachment[index] + 14); if (show_attachments) { rsprintf("</td></tr><tr>"); rsprintf("<td colspan=%d class=\"attachmentframe\">", colspan); rsprintf("<img src=\"%s\" alt=\"%s\" title=\"%s\">", ref, attachment[index] + 14, attachment[index] + 14); rsprintf("</td></tr>\n"); } } else { rsprintf ("<tr><td colspan=%d class=\"attachment\">%s %d: <a href=\"%s\" target=\"_blank\">%s</a>\n", colspan, loc("Attachment"), index + 1, ref, attachment[index] + 14); strlcpy(file_name, lbs->data_dir, sizeof(file_name)); generate_subdir_name(attachment[index], subdir, sizeof(subdir)); strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment[index], sizeof(file_name)); if (is_ascii(file_name) && !chkext(attachment[index], ".PS") && !chkext(attachment[index], ".PDF") && !chkext(attachment[index], ".EPS") && !chkext(attachment[index], ".SVG") && !chkext(attachment[index], ".HTM") && !chkext(attachment[index], ".HTML") && show_attachments) { rsprintf("</td></tr>\n"); /* display attachment */ rsprintf("<tr><td colspan=%d class=\"messageframe\">\n", colspan); /* anchor for references */ rsprintf("<a name=\"att%d\"></a>\n", index + 1); /* display attachment */ if (!chkext(attachment[index], ".HTML")) rsprintf("<pre class=\"messagepre\">"); strlcpy(file_name, lbs->data_dir, sizeof(file_name)); generate_subdir_name(attachment[index], subdir, sizeof(subdir)); strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment[index], sizeof(file_name)); f = fopen(file_name, "rt"); n_lines = 0; if (getcfg(lbs->name, "Attachment lines", str, sizeof(str))) max_n_lines = atoi(str); else max_n_lines = 300; if (f != NULL) { while (!feof(f)) { str[0] = 0; fgets(str, sizeof(str), f); if (n_lines < max_n_lines) { if (!chkext(attachment[index], ".HTML")) rsputs2(lbs, absolute_link, str); else rsputs(str); } n_lines++; } fclose(f); } if (!chkext(attachment[index], ".HTML")) rsprintf("</pre>"); rsprintf("\n"); if (max_n_lines == 0) rsprintf("<i><b>%d lines</b></i>\n", n_lines); else if (n_lines > max_n_lines) rsprintf("<i><b>... %d more lines ...</b></i>\n", n_lines - max_n_lines); } rsprintf("</td></tr>\n"); } } } } } } xfree(slist); xfree(svalue); }
CWE-79
null
519,248
200237550950510536397328403320485124766
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
BOOL is_command_allowed(LOGBOOK *lbs, char *command, int message_id) { char str[1000], menu_str[1000], other_str[1000]; char menu_item[MAX_N_LIST][NAME_LENGTH]; int i, n; if (command[0] == 0) return TRUE; /* check for guest access */ if (!getcfg(lbs->name, "Guest Menu commands", menu_str, sizeof(menu_str)) || logged_in(lbs)) getcfg(lbs->name, "Menu commands", menu_str, sizeof(menu_str)); /* default menu commands */ if (menu_str[0] == 0) { strcpy(menu_str, "List, New, Edit, Delete, Reply, Duplicate, Synchronize, Find, "); if (getcfg(lbs->name, "Password file", str, sizeof(str))) { if (is_admin_user(lbs, getparam("unm"))) { strcat(menu_str, "Admin, "); strcat(menu_str, "Change config file, "); strcat(menu_str, "Delete this logbook, "); strcat(menu_str, "Rename this logbook, "); strcat(menu_str, "Create new logbook, "); strcat(menu_str, "GetPwdFile, "); if (is_admin_user(NULL, getparam("unm"))) { if (lbs->top_group[0]) { sprintf(str, "Change [global %s]", lbs->top_group); strcat(menu_str, str); strcat(menu_str, ", "); } if (!lbs->top_group[0] || (is_admin_user(NULL, getparam("unm")))) { strcat(menu_str, "Change [global]"); strcat(menu_str, ", "); } } } strcat(menu_str, "Config, Logout, "); } else { strcat(menu_str, "Config, "); strcat(menu_str, "Change [global], "); strcat(menu_str, "Delete this logbook, "); strcat(menu_str, "Rename this logbook, "); strcat(menu_str, "Create new logbook, "); } strcat(menu_str, "Help, HelpELCode, "); } else { /* check for admin command */ n = strbreak(menu_str, menu_item, MAX_N_LIST, ",", FALSE); menu_str[0] = 0; for (i = 0; i < n; i++) { if (strcmp(menu_item[i], "Admin") == 0) { if (!is_admin_user(lbs, getparam("unm"))) continue; } strcat(menu_str, menu_item[i]); strcat(menu_str, ", "); } strcat(menu_str, "HelpELCode, Synchronize, "); if (is_admin_user(lbs, getparam("unm"))) { strcat(menu_str, "Change config file, "); strcat(menu_str, "Delete this logbook, "); strcat(menu_str, "Rename this logbook, "); strcat(menu_str, "Create new logbook, "); strcat(menu_str, "GetPwdFile, "); if (is_admin_user(NULL, getparam("unm"))) { if (lbs->top_group[0]) { sprintf(str, "Change [global %s]", lbs->top_group); strcat(menu_str, str); strcat(menu_str, ", "); } if (!lbs->top_group[0] || (is_admin_user(NULL, getparam("unm")))) { strcat(menu_str, "Change [global]"); strcat(menu_str, ", "); } } } } /* check list menu commands */ str[0] = 0; if (!getcfg(lbs->name, "Guest List Menu commands", str, sizeof(str)) || logged_in(lbs)) getcfg(lbs->name, "list menu commands", str, sizeof(str)); if (!str[0]) { if (!getcfg(lbs->name, "Guest Find Menu commands", str, sizeof(str)) || logged_in(lbs)) getcfg(lbs->name, "Find Menu commands", str, sizeof(str)); } if (str[0]) strlcat(menu_str, str, sizeof(menu_str)); else { strlcat(menu_str, "New, Find, Select, Last x, Help, HelpELCode, ", sizeof(menu_str)); if (getcfg(lbs->name, "Password file", str, sizeof(str))) strlcat(menu_str, "Admin, Config, Logout, ", sizeof(menu_str)); else strlcat(menu_str, "Config, ", sizeof(menu_str)); } strlcpy(other_str, "Preview, Back, Search, Download, Import, CSV Import, XML Import, ", sizeof(other_str)); strlcat(other_str, "Cancel, First, Last, Previous, Next, Requested, Forgot, ", sizeof(other_str)); /* only allow Submit & Co if "New" is allowed */ if (stristr(menu_str, "New,") || stristr(menu_str, "Edit")) strlcat(other_str, "Update, Upload, Submit, Save, ", sizeof(other_str)); /* add save for new user registration */ if (isparam("new_user_name")) strlcat(other_str, "Save, ", sizeof(other_str)); /* admin commands */ if (is_admin_user(lbs, getparam("unm"))) { strlcat(other_str, "Remove user, New user, Activate, ", sizeof(other_str)); } else if (getcfg(lbs->name, "Self register", str, sizeof(str)) && atoi(str) > 0) { strlcat(other_str, "Remove user, New user, ", sizeof(other_str)); } /* allow always edit of draft messages */ if (is_draft(lbs, message_id)) strlcat(other_str, "Edit, ", sizeof(other_str)); /* allow change password if "config" possible */ if (strieq(command, loc("Change password")) && stristr(menu_str, "Config")) { return TRUE; } /* exclude non-localized submit for elog */ else if (command[0] && strieq(command, "Submit") && (stristr(menu_str, "New,") || stristr(menu_str, "Edit"))) { return TRUE; } /* exclude other non-localized commands */ else if (command[0] && strieq(command, "GetMD5")) { return TRUE; } else if (command[0] && strieq(command, "IM")) { return TRUE; } /* check if command is present in the menu list */ else if (command[0]) { n = strbreak(menu_str, menu_item, MAX_N_LIST, ",", FALSE); for (i = 0; i < n; i++) if (strieq(command, menu_item[i]) || strieq(command, loc(menu_item[i]))) break; if (i == n) { n = strbreak(other_str, menu_item, MAX_N_LIST, ",", FALSE); for (i = 0; i < n; i++) if (strieq(command, menu_item[i]) || strieq(command, loc(menu_item[i]))) break; if (i == n) return FALSE; } } return TRUE; }
CWE-79
null
519,249
236357299542153503227229987390588290240
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int getcfg(char *group, char *param, char *value, int vsize) /* Read parameter from configuration file. - if group == [global] and top group exists, read from [global <top group>] - if parameter not in [global <top group>], read from [global] - if group is logbook, read from logbook section - if parameter not in [<logbook>], read from [global <top group>] or [global] */ { char str[256]; int status; /* if group is [global] and top group exists, read from there */ if (strieq(group, "global") && getcfg_topgroup()) { sprintf(str, "global %s", getcfg_topgroup()); status = getcfg(str, param, value, vsize); if (status) return status; } /* first check if parameter is under condition */ if (_condition[0]) { status = getcfg_simple(group, param, value, vsize, TRUE); if (status) return status; } status = getcfg_simple(group, param, value, vsize, FALSE); if (status) return status; /* if parameter not found in logbook, look in [global] section */ if (!group || is_logbook(group)) return getcfg("global", param, value, vsize); return 0; }
CWE-79
null
519,250
179493967057040579282087854262522887380
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int xvasprintf(char **ptr, const char *format, va_list ap) { int n; va_list save; #ifdef va_copy va_copy(save, ap); #else #ifdef __va_copy __va_copy(save, ap); #else save = ap; #endif #endif n = vasprintf(ptr, format, save); if (n == -1 || !*ptr) { printf("Not enough memory"); exit(EXIT_FAILURE); } return n; }
CWE-79
null
519,251
59024138722928113289293266811122055327
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int save_config(char *buffer, char *error) { int fh, i; char *buf; error[0] = 0; fh = open(config_file, O_RDWR | O_BINARY | O_CREAT, 0644); if (fh < 0) { sprintf(error, loc("Cannot open file <b>%s</b>"), config_file); strcat(error, ": "); strcat(error, strerror(errno)); return 0; } buf = (char *) xmalloc(strlen(buffer) * 2); strlcpy(buf, buffer, strlen(buffer) * 2); adjust_crlf(buf, strlen(buffer) * 2); i = write(fh, buf, strlen(buf)); if (i < (int) strlen(buf)) { sprintf(error, loc("Cannot write to <b>%s</b>"), config_file); strcat(error, ": "); strcat(error, strerror(errno)); close(fh); return 0; } TRUNCATE(fh); close(fh); /* force re-read of config file */ check_config_file(TRUE); return 1; }
CWE-79
null
519,252
13464984552493986092078047743526321857
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int delete_logbook(LOGBOOK *lbs, char *error) { int fh, i, length; char *buf, *p1, *p2; error[0] = 0; fh = open(config_file, O_RDWR | O_BINARY, 644); if (fh < 0) { sprintf(error, loc("Cannot open file <b>%s</b>"), config_file); strcat(error, ": "); strcat(error, strerror(errno)); return 0; } /* remove logbook name in groups */ change_logbook_in_group(lbs, ""); /* read previous contents */ length = lseek(fh, 0, SEEK_END); lseek(fh, 0, SEEK_SET); buf = xmalloc(length + 1); read(fh, buf, length); buf[length] = 0; /* find logbook config */ p1 = (char *) find_section(buf, lbs->name); p2 = (char *) find_next_section(p1 + 1); if (p2) { i = strlen(p2) + 1; strlcpy(p1, p2, i); } else *p1 = 0; lseek(fh, 0, SEEK_SET); i = write(fh, buf, strlen(buf)); if (i < (int) strlen(buf)) { sprintf(error, loc("Cannot write to <b>%s</b>"), config_file); strcat(error, ": "); strcat(error, strerror(errno)); close(fh); xfree(buf); return 0; } TRUNCATE(fh); close(fh); xfree(buf); /* force re-read of config file */ check_config_file(TRUE); el_index_logbooks(); return 1; }
CWE-79
null
519,253
60891852702880295731345727645638426990
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void show_elog_delete(LOGBOOK *lbs, int message_id) { int i, status, reply = 0, next, nsel; char str[256], str2[256], in_reply_to[80], reply_to[MAX_REPLY_TO * 10], owner[256]; char attrib[MAX_N_ATTR][NAME_LENGTH], mode[80]; /* check for editing interval */ if (isparam("nsel")) { for (i = 0; i < atoi(getparam("nsel")); i++) { sprintf(str, "s%d", i); if (isparam(str)) { status = check_edit_time(lbs, atoi(getparam(str))); if (!status) { return; } } } } else if (message_id) { status = check_edit_time(lbs, message_id); if (!status) { return; } } /* redirect if confirm = NO */ if (isparam("confirm") && strcmp(getparam("confirm"), loc("No")) == 0) { if (message_id) { sprintf(str, "%d", message_id); redirect(lbs, str); } else { strlcpy(str, isparam("lastcmd") ? getparam("lastcmd") : "", sizeof(str)); url_decode(str); redirect(lbs, str); } return; } if (isparam("elmode")) strlcpy(mode, getparam("elmode"), sizeof(mode)); if (isparam("confirm")) { if (strcmp(getparam("confirm"), loc("Yes")) == 0) { if (message_id) { /* delete message */ status = el_delete_message(lbs, message_id, TRUE, NULL, TRUE, TRUE); if (status != EL_SUCCESS) { sprintf(str, "%s = %d", loc("Error deleting message: status"), status); show_error(str); return; } else { strlcpy(str, isparam("nextmsg") ? getparam("nextmsg") : "", sizeof(str)); if (atoi(str) == 0) sprintf(str, "%d", el_search_message(lbs, EL_LAST, 0, TRUE)); if (atoi(str) == 0) redirect(lbs, ""); else redirect(lbs, str); return; } } else { if (isparam("nsel")) { for (i = 0; i < atoi(getparam("nsel")); i++) { sprintf(str, "s%d", i); if (isparam(str)) { if (strieq(mode, "threaded")) status = el_delete_message(lbs, atoi(getparam(str)), TRUE, NULL, TRUE, TRUE); else status = el_delete_message(lbs, atoi(getparam(str)), TRUE, NULL, TRUE, FALSE); } } } redirect(lbs, isparam("lastcmd") ? getparam("lastcmd") : ""); return; } } } else { /* check if at least one message is selected */ if (!message_id) { nsel = isparam("nsel") ? atoi(getparam("nsel")) : 0; for (i = 0; i < nsel; i++) { sprintf(str, "s%d", i); if (isparam(str)) break; } if (i == nsel) { show_error(loc("No entry selected for deletion")); return; } } /* check for author */ if (getcfg(lbs->name, "Restrict edit", str, sizeof(str)) && atoi(str) == 1) { /* get message for reply/edit */ el_retrieve(lbs, message_id, NULL, attr_list, attrib, lbs->n_attr, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); if (!is_author(lbs, attrib, owner)) { strencode2(str2, owner, sizeof(str2)); sprintf(str, loc("Only user <b>%s</b> can delete this entry"), str2); show_error(str); return; } } /* header */ if (message_id) sprintf(str, "%d", message_id); else str[0] = 0; show_standard_header(lbs, TRUE, "Delete ELog entry", str, FALSE, NULL, NULL, 0); rsprintf("<table class=\"dlgframe\" cellspacing=0 align=center>"); rsprintf("<tr><td class=\"dlgtitle\">\n"); /* define hidden field for command */ rsprintf("<input type=hidden name=cmd value=\"%s\">\n", loc("Delete")); if (!message_id) { rsprintf("%s</td></tr>\n", loc("Are you sure to delete these messages?")); rsprintf("<tr><td align=center class=\"dlgform\">\n"); if (isparam("nsel")) rsprintf("<input type=hidden name=nsel value=%s>\n", getparam("nsel")); if (isparam("lastcmd")) { strlcpy(str, getparam("lastcmd"), sizeof(str)); rsprintf("<input type=hidden name=lastcmd value=\"%s\">\n", str); } if (isparam("nsel")) { reply = FALSE; for (i = 0; i < atoi(getparam("nsel")); i++) { sprintf(str, "s%d", i); if (isparam(str)) { rsprintf("#%s ", getparam(str)); rsprintf("<input type=hidden name=%s value=%s>\n", str, getparam(str)); } if (!reply) { el_retrieve(lbs, isparam(str) ? atoi(getparam(str)) : 0, NULL, attr_list, NULL, 0, NULL, NULL, in_reply_to, reply_to, NULL, NULL, NULL, NULL); if (reply_to[0]) reply = TRUE; } } } rsprintf("</td></tr>\n"); if (reply && strieq(mode, "threaded")) rsprintf("<tr><td align=center class=\"dlgform\">%s</td></tr>\n", loc("and all their replies")); } else { rsprintf("%s</td></tr>\n", loc("Are you sure to delete this entry?")); /* check for replies */ /* retrieve original message */ el_retrieve(lbs, message_id, NULL, attr_list, NULL, 0, NULL, NULL, in_reply_to, reply_to, NULL, NULL, NULL, NULL); if (reply_to[0]) rsprintf("<tr><td align=center class=\"dlgform\">#%d<br>%s</td></tr>\n", message_id, loc("and all its replies")); else rsprintf("<tr><td align=center class=\"dlgform\">#%d</td></tr>\n", message_id); /* put link to next message */ next = el_search_message(lbs, EL_NEXT, message_id, TRUE); rsprintf("<input type=hidden name=nextmsg value=%d>\n", next); } rsprintf("<tr><td align=center class=\"dlgform\"><input type=submit name=confirm value=\"%s\">\n", loc("Yes")); rsprintf("<input type=submit name=confirm value=\"%s\">\n", loc("No")); rsprintf("</td></tr>\n\n"); } rsprintf("</table>\n"); show_bottom_text(lbs); rsprintf("</body></html>\r\n"); }
CWE-79
null
519,254
155517537541578135935968246910243489956
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int html_allowed(LOGBOOK *lbs) { char str[80]; return (getcfg(lbs->name, "Allow HTML", str, sizeof(str)) && atoi(str) == 1); }
CWE-79
null
519,255
297876234024530070626413387727012388432
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm) { return strftime(s, max, fmt, tm); }
CWE-79
null
519,256
298299734152239328618946421939962309559
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void set_cookie(LOGBOOK *lbs, char *name, char *value, BOOL global, char *expiration) { char lb_name[256], str[NAME_LENGTH], format[80]; double exp; time_t now; struct tm *gmt; if (lbs) strcpy(lb_name, lbs->name); else strcpy(lb_name, "global"); if (value != NULL) rsprintf("Set-Cookie: %s=%s;", name, value); else rsprintf("Set-Cookie: %s;", name); /* add path */ if (global) { /* path for all logbooks */ if (getcfg(lb_name, "URL", str, sizeof(str))) { extract_path(str); url_encode(str, sizeof(str)); rsprintf(" path=/%s;", str); } else rsprintf(" path=/;"); } else { /* path for individual logbook */ if (getcfg(lb_name, "URL", str, sizeof(str))) { extract_path(str); url_encode(str, sizeof(str)); if (str[0]) rsprintf(" path=/%s/%s;", str, lbs->name_enc); else rsprintf(" path=/%s;", lbs->name_enc); } else rsprintf(" path=/%s;", lbs->name_enc); } exp = atof(expiration); /* to clear a cookie, set expiration date to yesterday */ if (value != NULL && value[0] == 0) exp = -24; /* add expriation date */ if (exp != 0 && exp < 100000) { time(&now); now += (int) (3600 * exp); gmt = gmtime(&now); strcpy(format, "%A, %d-%b-%y %H:%M:%S GMT"); strftime(str, sizeof(str), format, gmt); rsprintf(" expires=%s;", str); } rsprintf("\r\n"); }
CWE-79
null
519,257
146719493541251166158663406310470490199
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int scan_attributes(char *logbook) /* scan configuration file for attributes and fill attr_list, attr_options and attr_flags arrays */ { char list[10000], str[NAME_LENGTH], str2[NAME_LENGTH], type[NAME_LENGTH], tmp_list[MAX_N_ATTR][NAME_LENGTH]; int i, j, n, m, n_options; if (getcfg(logbook, "Attributes", list, sizeof(list))) { /* reset attribute flags */ memset(attr_flags, 0, sizeof(attr_flags)); /* get attribute list */ memset(attr_list, 0, sizeof(attr_list)); n = strbreak(list, attr_list, MAX_N_ATTR, ",", FALSE); /* check for forbidden attributes */ for (i = 0; i < n; i++) { if (strieq(attr_list[i], "id") || strieq(attr_list[i], "text") || strieq(attr_list[i], "date") || strieq(attr_list[i], "encoding") || strieq(attr_list[i], "reply to") || strieq(attr_list[i], "locked by") || strieq(attr_list[i], "in reply to") || strieq(attr_list[i], "attachment")) { snprintf(str, sizeof(str), loc("Attribute \"%s\" is not allowed in config file"), attr_list[i]); show_error(str); return -1; } } /* get options lists for attributes */ memset(attr_options, 0, sizeof(attr_options)); for (i = 0; i < n; i++) { n_options = 0; snprintf(str, sizeof(str), "Options %s", attr_list[i]); if (getcfg(logbook, str, list, sizeof(list))) n_options = strbreak(list, attr_options[i], MAX_N_LIST, ",", FALSE); snprintf(str, sizeof(str), "MOptions %s", attr_list[i]); if (getcfg(logbook, str, list, sizeof(list))) { n_options = strbreak(list, attr_options[i], MAX_N_LIST, ",", FALSE); attr_flags[i] |= AF_MULTI; } snprintf(str, sizeof(str), "ROptions %s", attr_list[i]); if (getcfg(logbook, str, list, sizeof(list))) { n_options = strbreak(list, attr_options[i], MAX_N_LIST, ",", FALSE); attr_flags[i] |= AF_RADIO; } snprintf(str, sizeof(str), "IOptions %s", attr_list[i]); if (getcfg(logbook, str, list, sizeof(list))) { n_options = strbreak(list, attr_options[i], MAX_N_LIST, ",", FALSE); attr_flags[i] |= AF_ICON; } snprintf(str2, sizeof(str2), "Sort Attribute Options %s", attr_list[i]); if (n_options && getcfg(logbook, str2, str, sizeof(str)) && atoi(str) == 1) { qsort(attr_options[i], n_options, NAME_LENGTH, ascii_compare2); } } /* check if attribute required */ getcfg(logbook, "Required Attributes", list, sizeof(list)); m = strbreak(list, tmp_list, MAX_N_ATTR, ",", FALSE); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) if (strieq(attr_list[j], tmp_list[i])) attr_flags[j] |= AF_REQUIRED; } /* check if locked attribute */ getcfg(logbook, "Locked Attributes", list, sizeof(list)); m = strbreak(list, tmp_list, MAX_N_ATTR, ",", FALSE); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) if (strieq(attr_list[j], tmp_list[i])) attr_flags[j] |= AF_LOCKED; } /* check if fixed attribute for Edit */ getcfg(logbook, "Fixed Attributes Edit", list, sizeof(list)); m = strbreak(list, tmp_list, MAX_N_ATTR, ",", FALSE); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) if (strieq(attr_list[j], tmp_list[i])) attr_flags[j] |= AF_FIXED_EDIT; } /* check if fixed attribute for Reply */ getcfg(logbook, "Fixed Attributes Reply", list, sizeof(list)); m = strbreak(list, tmp_list, MAX_N_ATTR, ",", FALSE); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) if (strieq(attr_list[j], tmp_list[i])) attr_flags[j] |= AF_FIXED_REPLY; } /* check for extendable options */ getcfg(logbook, "Extendable Options", list, sizeof(list)); m = strbreak(list, tmp_list, MAX_N_ATTR, ",", FALSE); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) if (strieq(attr_list[j], tmp_list[i])) attr_flags[j] |= AF_EXTENDABLE; } for (i = 0; i < n; i++) { snprintf(str, sizeof(str), "Type %s", attr_list[i]); if (getcfg(logbook, str, type, sizeof(type))) { if (strieq(type, "date")) attr_flags[i] |= AF_DATE; if (strieq(type, "datetime")) attr_flags[i] |= AF_DATETIME; if (strieq(type, "time")) attr_flags[i] |= AF_TIME; if (strieq(type, "numeric")) attr_flags[i] |= AF_NUMERIC; if (strieq(type, "userlist")) attr_flags[i] |= AF_USERLIST; if (strieq(type, "muserlist")) attr_flags[i] |= AF_MUSERLIST; if (strieq(type, "useremail")) attr_flags[i] |= AF_USEREMAIL; if (strieq(type, "museremail")) attr_flags[i] |= AF_MUSEREMAIL; } } } else { memcpy(attr_list, attr_list_default, sizeof(attr_list_default)); memcpy(attr_options, attr_options_default, sizeof(attr_options_default)); memcpy(attr_flags, attr_flags_default, sizeof(attr_flags_default)); n = 4; } return n; }
CWE-79
null
519,258
78979724574169426930001874759638697414
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int adjust_config(char *url) { int fh, i, length; char *buf, *buf2, *p1, *p2; char str[256]; fh = open(config_file, O_RDWR | O_BINARY, 0644); if (fh < 0) { sprintf(str, loc("Cannot open file <b>%s</b>"), config_file); strcat(str, ": "); strcat(str, strerror(errno)); eputs(str); return 0; } /* read previous contents */ length = lseek(fh, 0, SEEK_END); lseek(fh, 0, SEEK_SET); buf = (char *) xmalloc(2 * length + 1000); read(fh, buf, length); buf[length] = 0; /* add mirror server */ p1 = stristr(buf, "Mirror server ="); if (p1 != NULL) { p2 = strchr(p1, '\n'); if (p2 && *(p2 - 1) == '\r') p2--; } else { p1 = strstr(buf, "[global]"); if (p1 == NULL) { eputs("Cannot find [global] section in config file."); return 0; } p1 = strchr(p1, '\n'); while (*p1 == '\n' || *p1 == '\r') p1++; p2 = p1; } /* save tail */ buf2 = NULL; if (p2) buf2 = xstrdup(p2); sprintf(p1, "Mirror server = %s\r\n", url); strlcat(p1, buf2, length + 1000); xfree(buf2); eprintf("Option \"Mirror server = %s\" added to config file.\n", url); /* outcomment "URL = xxx" */ p1 = strstr(buf, "URL ="); if (p1 != NULL) { /* save tail */ buf2 = xstrdup(p1); /* add comment */ sprintf(p1, "; Following line has been outcommented after cloning\r\n"); strlcat(p1, "; ", length + 1000); strlcat(p1, buf2, length + 1000); xfree(buf2); eputs("Option \"URL = xxx\" has been outcommented from config file."); } adjust_crlf(buf, 2 * length + 1000); lseek(fh, 0, SEEK_SET); i = write(fh, buf, strlen(buf)); if (i < (int) strlen(buf)) { sprintf(str, loc("Cannot write to <b>%s</b>"), config_file); strcat(str, ": "); strcat(str, strerror(errno)); eputs(str); close(fh); xfree(buf); return 0; } TRUNCATE(fh); close(fh); xfree(buf); return 1; }
CWE-79
null
519,259
278527581165386133154787175841353777449
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int retrieve_remote_md5(LOGBOOK *lbs, char *host, MD5_INDEX **md5_index, char *error_str) { int i, n, id, x, version, ssl; char *text, *p, url[256], str[1000]; *md5_index = NULL; combine_url(lbs, host, "?cmd=GetMD5", url, sizeof(url), &ssl); text = NULL; error_str[0] = 0; if (retrieve_url(lbs, url, ssl, &text, TRUE) < 0) { sprintf(error_str, loc("Cannot connect to remote server \"%s\""), host); return -1; } p = strstr(text, "ELOG HTTP "); if (!p) { if (isparam("debug")) rsputs(text); strlcpy(error_str, loc("Remote server is not an ELOG server"), 256); xfree(text); return -1; } version = atoi(p + 10) * 100 + atoi(p + 12) * 10 + atoi(p + 14); if (version < 250) { if (isparam("debug")) rsputs(text); memset(str, 0, sizeof(str)); strncpy(str, p + 10, 5); sprintf(error_str, loc("Incorrect remote ELOG server version %s"), str); xfree(text); return -1; } p = strstr(text, "Location: "); if (p) { if (isparam("debug")) rsputs(text); if (strstr(text, "?fail=")) sprintf(error_str, loc("Invalid user name \"%s\" or password for remote logbook"), isparam("unm") ? getparam("unm") : ""); else { strlcpy(str, p + 9, sizeof(str)); if (strchr(str, '?')) *strchr(str, '?') = 0; strlcpy(error_str, loc("URL is redirected to:"), 256); strlcat(error_str, str, 256); } return -3; } p = strstr(text, "\r\n\r\n"); if (!p) { if (isparam("debug")) rsputs(text); strlcpy(error_str, loc("Invalid HTTP header"), 256); xfree(text); return -1; } for (n = 0;; n++) { p = strstr(p, "ID:"); if (!p) break; p += 3; id = atoi(p); p = strstr(p, "MD5:"); if (!p) break; p += 4; if (n == 0) *md5_index = (MD5_INDEX *) xmalloc(sizeof(MD5_INDEX)); else *md5_index = (MD5_INDEX *) xrealloc(*md5_index, (n + 1) * sizeof(MD5_INDEX)); (*md5_index)[n].message_id = id; for (i = 0; i < 16; i++) { sscanf(p + 2 * i, "%02X", &x); (*md5_index)[n].md5_digest[i] = (unsigned char) x; } } if (n == 0) { if (isparam("debug")) rsputs(text); if (strstr(text, "Login")) { strlcpy(error_str, loc("No user name supplied to access remote logbook"), 256); xfree(text); return -2; } else strlcpy(error_str, loc("Error accessing remote logbook"), 256); } xfree(text); return n; }
CWE-79
null
519,260
34533440381058520934909799026331060905
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int ss_file_find(const char *path, char *pattern, char **plist) /******************************************************************** Routine: ss_file_find Purpose: Return list of files matching 'pattern' from the 'path' location Input: char *path Name of a file in file system to check char *pattern pattern string (wildcard allowed) Output: char **plist pointer to the file list Function value: int Number of files matching request \********************************************************************/ { #ifdef OS_UNIX DIR *dir_pointer; struct dirent *dp; int i; if ((dir_pointer = opendir(path)) == NULL) return 0; *plist = (char *) xmalloc(MAX_PATH_LENGTH); i = 0; for (dp = readdir(dir_pointer); dp != NULL; dp = readdir(dir_pointer)) { if (fnmatch1(pattern, dp->d_name) == 0) { *plist = (char *) xrealloc(*plist, (i + 1) * MAX_PATH_LENGTH); strncpy(*plist + (i * MAX_PATH_LENGTH), dp->d_name, strlen(dp->d_name)); *(*plist + (i * MAX_PATH_LENGTH) + strlen(dp->d_name)) = '\0'; i++; } } closedir(dir_pointer); return i; #endif #ifdef OS_WINNT HANDLE pffile; LPWIN32_FIND_DATA lpfdata; char str[255]; int i, first; strlcpy(str, path, sizeof(str)); strlcat(str, "\\", sizeof(str)); strlcat(str, pattern, sizeof(str)); first = 1; i = 0; lpfdata = xmalloc(sizeof(WIN32_FIND_DATA)); *plist = (char *) xmalloc(MAX_PATH_LENGTH); pffile = FindFirstFile(str, lpfdata); if (pffile == INVALID_HANDLE_VALUE) return 0; first = 0; *plist = (char *) xrealloc(*plist, (i + 1) * MAX_PATH_LENGTH); strncpy(*plist + (i * MAX_PATH_LENGTH), lpfdata->cFileName, strlen(lpfdata->cFileName)); *(*plist + (i * MAX_PATH_LENGTH) + strlen(lpfdata->cFileName)) = '\0'; i++; while (FindNextFile(pffile, lpfdata)) { *plist = (char *) xrealloc(*plist, (i + 1) * MAX_PATH_LENGTH); strncpy(*plist + (i * MAX_PATH_LENGTH), lpfdata->cFileName, strlen(lpfdata->cFileName)); *(*plist + (i * MAX_PATH_LENGTH) + strlen(lpfdata->cFileName)) = '\0'; i++; } xfree(lpfdata); return i; #endif }
CWE-79
null
519,261
35362697981660210886708034886723643179
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int is_inline_attachment(char *encoding, int message_id, char *text, int i, char *att) { char str[256], att_enc[256], domain[256], *pt, *p; if (text == NULL) return 0; if (strieq(encoding, "ELCode")) { sprintf(str, "[img]elog:/%d[/img]", i + 1); if (stristr(text, str)) return 1; sprintf(str, "[img]elog:%d/%d[/img]", message_id, i + 1); if (stristr(text, str)) return 1; } else if (strieq(encoding, "HTML")) { strlcpy(att_enc, att, sizeof(att_enc)); att_enc[13] = '/'; pt = text; while (*pt && stristr(pt, att_enc)) { /* make sure that it's really an inline image */ for (p = stristr(pt, att_enc); p > pt; p--) if (*p == '<') break; if (p > pt) { strncpy(str, p, 5); if (stristr(str, "<img ")) return 1; } pt = stristr(pt, att_enc) + 1; } retrieve_domain(domain, sizeof(domain)); sprintf(str, "cid:att%d@%s", i, domain); if (*text && stristr(text, str)) return 1; } return 0; }
CWE-79
null
519,262
293717478240323194660639972946213315342
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void generate_subdir_name(char *file_name, char *subdir, int size) { char fn[MAX_PATH_LENGTH], path[MAX_PATH_LENGTH]; int year; // extract path from file_name strlcpy(path, file_name, size); if (strrchr(path, DIR_SEPARATOR)) *(strrchr(path, DIR_SEPARATOR) + 1) = 0; // extract file name if (strrchr(file_name, DIR_SEPARATOR)) strlcpy(fn, strrchr(file_name, DIR_SEPARATOR) + 1, sizeof(fn)); else strlcpy(fn, file_name, sizeof(fn)); // create subdir from name year = (fn[0] - '0') * 10 + (fn[1] - '0'); // month = (fn[2]-'0')*10+(fn[3]-'0'); if (year < 80) sprintf(subdir, "20%02d", year); else sprintf(subdir, "19%02d", year); strlcat(subdir, DIR_SEPARATOR_STR, size); }
CWE-79
null
519,263
264643437423821814250337656639938786219
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int is_image(char *att) { return (stristr(att, ".GIF") != NULL) || (stristr(att, ".JPG") != NULL) || (stristr(att, ".JPEG") != NULL) || (stristr(att, ".PNG") != NULL) || (stristr(att, ".SVG") != NULL); }
CWE-79
null
519,264
12090952844433036979221790879261222561
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void get_rfc2822_date(char *date, int size, time_t ltime) { time_t now; char buf[256]; int offset; struct tm *ts; /* switch locale temporarily back to english to comply with RFC2822 date format */ setlocale(LC_ALL, "C"); if (ltime == 0) time(&now); else now = ltime; ts = localtime(&now); assert(ts); strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S", ts); offset = (-(int) my_timezone()); if (ts->tm_isdst) offset += 3600; snprintf(date, size - 1, "%s %+03d%02d", buf, (int) (offset / 3600), (int) ((abs((int) offset) / 60) % 60)); }
CWE-79
null
519,265
162954710300328400309834187672028339652
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void el_delete_attachment(LOGBOOK *lbs, char *file_name) { int i; char str[MAX_PATH_LENGTH], subdir[MAX_PATH_LENGTH]; strlcpy(str, lbs->data_dir, sizeof(str)); generate_subdir_name(file_name, subdir, sizeof(subdir)); strlcat(str, subdir, sizeof(str)); strlcat(str, file_name, sizeof(str)); remove(str); strlcat(str, ".png", sizeof(str)); remove(str); for (i = 0;; i++) { strlcpy(str, lbs->data_dir, sizeof(str)); strlcat(str, subdir, sizeof(str)); strlcat(str, file_name, sizeof(str)); sprintf(str + strlen(str), "-%d.png", i); if (file_exist(str)) { remove(str); continue; } strlcpy(str, lbs->data_dir, sizeof(str)); strlcat(str, subdir, sizeof(str)); strlcat(str, file_name, sizeof(str)); if (strrchr(str, '.')) *strrchr(str, '.') = 0; sprintf(str + strlen(str), "-%d.png", i); if (file_exist(str)) { remove(str); continue; } break; } }
CWE-79
null
519,266
331994661561800954627520926590485160993
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void str_escape(char *ps, int size) /********************************************************************\ Encode the given string in-place by adding \\ escapes for `$"\ \********************************************************************/ { unsigned char *pd, *p; unsigned char str[NAME_LENGTH]; pd = str; p = (unsigned char *) ps; while (*p && pd < str + 250) { if (strchr("'$\"\\", *p)) { *pd++ = '\\'; *pd++ = *p++; } else { *pd++ = *p++; } } *pd = '\0'; strlcpy(ps, (char *) str, size); }
CWE-79
null
519,267
295977210635013038217730672683797560742
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int add_attribute_option(LOGBOOK *lbs, char *attrname, char *attrvalue, char *condition) { int fh, i, length; char str[NAME_LENGTH], av_encoded[NAME_LENGTH], *buf, *buf2, *p1, *p2, *p3; fh = open(config_file, O_RDWR | O_BINARY, 0644); if (fh < 0) { sprintf(str, loc("Cannot open file <b>%s</b>"), config_file); strcat(str, ": "); strcat(str, strerror(errno)); show_error(str); return 0; } /* do not allow HTML code in value */ strencode2(av_encoded, attrvalue, sizeof(av_encoded)); /* read previous contents */ length = lseek(fh, 0, SEEK_END); lseek(fh, 0, SEEK_SET); buf = xmalloc(length + strlen(av_encoded) + 3); read(fh, buf, length); buf[length] = 0; /* find location of options */ if (condition && condition[0]) set_condition(condition); else set_condition(""); sprintf(str, "Options %s", attrname); p1 = (char *) find_param(buf, lbs->name, str); if (p1 == NULL) { sprintf(str, "MOptions %s", attrname); p1 = (char *) find_param(buf, lbs->name, str); } if (p1 == NULL) { sprintf(str, "ROptions %s", attrname); p1 = (char *) find_param(buf, lbs->name, str); } if (p1 == NULL) return 0; p2 = strchr(p1, '\n'); if (p2 && *(p2 - 1) == '\r') p2--; /* save tail */ buf2 = NULL; if (p2) buf2 = xstrdup(p2); /* add option */ p3 = strchr(p1, '\n'); if (p3 == NULL) p3 = p1 + strlen(p1); while (*(p3 - 1) == '\n' || *(p3 - 1) == '\r' || *(p3 - 1) == ' ' || *(p3 - 1) == '\t') p3--; sprintf(p3, ", %s", av_encoded); if (p2) { strlcat(buf, buf2, length + strlen(av_encoded) + 3); xfree(buf2); } lseek(fh, 0, SEEK_SET); i = write(fh, buf, strlen(buf)); if (i < (int) strlen(buf)) { sprintf(str, loc("Cannot write to <b>%s</b>"), config_file); strcat(str, ": "); strcat(str, strerror(errno)); show_error(str); close(fh); xfree(buf); return 0; } TRUNCATE(fh); close(fh); xfree(buf); /* force re-read of config file */ check_config_file(TRUE); return 1; }
CWE-79
null
519,268
318269921690987846364587142504935129168
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void submit_config(LOGBOOK *lbs, char *server, char *buffer, char *error_str) { int i, n, port, sock, content_length, header_length, ssl; char str[256], upwd[80]; char subdir[256], param[256], remote_host_name[256]; char *content, boundary[80], request[10000], response[10000]; #ifdef HAVE_SSL SSL *ssl_con = NULL; #else void *ssl_con = NULL; #endif error_str[0] = 0; combine_url(lbs, server, "", str, sizeof(str), &ssl); split_url(str, remote_host_name, &port, subdir, param); sock = elog_connect(remote_host_name, port); if (sock == -1) { sprintf(error_str, loc("Cannot connect to host %s, port %d"), remote_host_name, port); return; } #ifdef HAVE_SSL if (ssl) if (ssl_connect(sock, &ssl_con) < 0) { strlcpy(error_str, "Error initiating SSL connection\n", 256); return; } #endif content_length = 100000; content = (char *) xmalloc(content_length); /* compose content */ sprintf(boundary, "---------------------------%04X%04X%04X", rand(), rand(), rand()); strcpy(content, boundary); strcat(content, "\r\nContent-Disposition: form-data; name=\"cmd\"\r\n\r\nSave\r\n"); if (isparam("unm")) { sprintf(content + strlen(content), "%s\r\nContent-Disposition: form-data; name=\"unm\"\r\n\r\n%s\r\n", boundary, getparam("unm")); if (isparam("upwd")) strlcpy(upwd, getparam("upwd"), sizeof(upwd)); else get_user_line(lbs, getparam("unm"), upwd, NULL, NULL, NULL, NULL, NULL); sprintf(content + strlen(content), "%s\r\nContent-Disposition: form-data; name=\"upwd\"\r\n\r\n%s\r\n", boundary, upwd); } sprintf(content + strlen(content), "%s\r\nContent-Disposition: form-data; name=\"Text\"\r\n\r\n%s\r\n%s\r\n", boundary, buffer, boundary); content_length = strlen(content); /* compose request */ strcpy(request, "POST "); if (subdir[0]) { if (subdir[0] != '/') strcat(request, "/"); strcat(request, subdir); if (request[strlen(request) - 1] != '/') strcat(request, "/"); } strcat(request, " HTTP/1.0\r\n"); sprintf(request + strlen(request), "Content-Type: multipart/form-data; boundary=%s\r\n", boundary); sprintf(request + strlen(request), "Host: %s\r\n", host_name); sprintf(request + strlen(request), "User-Agent: ELOGD\r\n"); sprintf(request + strlen(request), "Content-Length: %d\r\n", content_length); if (isparam("wpwd")) sprintf(request + strlen(request), "Cookie: wpwd=%s\r\n", getparam("wpwd")); strcat(request, "\r\n"); header_length = strlen(request); send_with_timeout(ssl_con, sock, request, header_length); send_with_timeout(ssl_con, sock, content, content_length); #ifdef HAVE_SSL if (ssl) /* receive response */ i = SSL_read(ssl_con, response, 10000); else #endif /* receive response */ i = recv(sock, response, 10000, 0); if (i < 0) { closesocket(sock); strlcpy(error_str, "Cannot receive response", 256); return; } /* discard remainder of response */ n = i; while (i > 0) { i = recv(sock, response + n, 10000, 0); if (i > 0) n += i; } response[n] = 0; #ifdef HAVE_SSL if (ssl) { SSL_shutdown(ssl_con); SSL_free(ssl_con); } #endif closesocket(sock); /* check response status */ if (strstr(response, "302 Found")) { if (strstr(response, "Location:")) { if (strstr(response, "fail")) strlcpy(error_str, "Invalid usr name or password\n", 256); } } else if (strstr(response, "Logbook Selection")) strlcpy(error_str, "No logbook specified\n", 256); else if (strstr(response, "enter password")) strlcpy(error_str, "Missing or invalid password\n", 256); else if (strstr(response, "form name=form1")) strlcpy(error_str, "Missing or invalid user name/password\n", 256); else if (strstr(response, "Error: Attribute")) { strncpy(str, strstr(response, "Error: Attribute") + 20, sizeof(str)); if (strchr(str, '<')) *strchr(str, '<') = 0; sprintf(error_str, "Missing required attribute \"%s\"\n", str); } else strlcpy(error_str, "Error transmitting message\n", 256); }
CWE-79
null
519,269
332122790354920456994123421611053779904
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int create_thumbnail(LOGBOOK *lbs, char *file_name) { char str[2 * MAX_PATH_LENGTH], cmd[2 * MAX_PATH_LENGTH], thumb_size[256], thumb_options[256]; int i; if (!image_magick_exist) return 0; if (getcfg(lbs->name, "Thumbnail size", str, sizeof(str))) { if (strcmp(str, "0") == 0) return 0; sprintf(thumb_size, " -thumbnail '%s'", str); } else thumb_size[0] = 0; getcfg(lbs->name, "Thumbnail options", thumb_options, sizeof(thumb_options)); if (!chkext(file_name, ".ps") && !chkext(file_name, ".pdf") && !chkext(file_name, ".eps") && !chkext(file_name, ".gif") && !chkext(file_name, ".jpg") && !chkext(file_name, ".jpeg") && !chkext(file_name, ".png") && !chkext(file_name, ".ico") && !chkext(file_name, ".tif") && !chkext(file_name, ".svg")) return 0; i = get_thumb_name(file_name, str, sizeof(str), 0); if (i) return i; strlcpy(str, file_name, sizeof(str)); if (chkext(file_name, ".pdf") || chkext(file_name, ".ps")) { if (strrchr(str, '.')) *strrchr(str, '.') = 0; } if (chkext(file_name, ".pdf") || chkext(file_name, ".ps")) strlcat(str, "-%d.png", sizeof(str)); else strlcat(str, ".png", sizeof(str)); if (chkext(file_name, ".pdf") || chkext(file_name, ".ps")) snprintf(cmd, sizeof(cmd), "%s %s '%s[0-7]'%s '%s'", _convert_cmd, thumb_options, file_name, thumb_size, str); else snprintf(cmd, sizeof(cmd), "%s %s '%s'%s '%s'", _convert_cmd, thumb_options, file_name, thumb_size, str); #ifdef OS_WINNT for (i = 0; i < (int) strlen(cmd); i++) if (cmd[i] == '\'') cmd[i] = '\"'; #endif snprintf(str, sizeof(str), "SHELL \"%s\"", cmd); write_logfile(lbs, str); if (get_verbose() >= VERBOSE_INFO) { eprintf(str); eprintf("\n"); } my_shell(cmd, str, sizeof(str)); i = get_thumb_name(file_name, str, sizeof(str), 0); if (i) return i; return 3; }
CWE-79
null
519,270
315836169835883540765000282993221446379
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int cind(char c) { int i; if (c == '=') return 0; for (i = 0; i < 64; i++) if (map[i] == c) return i; return -1; }
CWE-79
null
519,271
136293755510503172253601873403633151101
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void strextract(const char *str, char delim, char *extr, int size) /* extract a substinr "extr" from "str" until "delim" is found */ { int i; for (i = 0; str[i] != delim && i < size - 1; i++) extr[i] = str[i]; extr[i] = 0; }
CWE-79
null
519,272
298151122840230227390079360958801989044
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int build_subst_list(LOGBOOK *lbs, char list[][NAME_LENGTH], char value[][NAME_LENGTH], char attrib[][NAME_LENGTH], BOOL format_date) { int i; char str[NAME_LENGTH], format[256], full_name[256], user_email[256]; time_t t; struct tm *ts; /* copy attribute list */ i = 0; if (attrib != NULL) for (; i < lbs->n_attr; i++) { strcpy(list[i], attr_list[i]); if (attrib) { if ((attr_flags[i] & AF_DATE) && format_date) { t = (time_t) atoi(attrib[i]); ts = localtime(&t); assert(ts); sprintf(str, "Date format %s", attr_list[i]); if (!getcfg(lbs->name, str, format, sizeof(format))) if (!getcfg(lbs->name, "Date format", format, sizeof(format))) strcpy(format, DEFAULT_DATE_FORMAT); my_strftime(value[i], NAME_LENGTH, format, ts); } else if ((attr_flags[i] & AF_DATETIME) && format_date) { t = (time_t) atoi(attrib[i]); ts = localtime(&t); assert(ts); sprintf(str, "Time format %s", attr_list[i]); if (!getcfg(lbs->name, str, format, sizeof(format))) if (!getcfg(lbs->name, "Time format", format, sizeof(format))) strcpy(format, DEFAULT_TIME_FORMAT); my_strftime(value[i], NAME_LENGTH, format, ts); } else strcpy(value[i], attrib[i]); } else strlcpy(value[i], isparam(attr_list[i]) ? getparam(attr_list[i]) : "", NAME_LENGTH); } /* add remote host */ strcpy(list[i], "remote_host"); strlcpy(value[i++], rem_host, NAME_LENGTH); /* add local host */ strcpy(list[i], "host"); strlcpy(value[i++], host_name, NAME_LENGTH); /* add forwarded user */ strcpy(list[i], "http_user"); strlcpy(value[i++], http_user, NAME_LENGTH); /* add user names */ strcpy(list[i], "short_name"); if (isparam("unm")) { strlcpy(value[i++], getparam("unm"), NAME_LENGTH); get_user_line(lbs, getparam("unm"), NULL, full_name, user_email, NULL, NULL, NULL); } else { strlcpy(value[i++], loc("Anonymous"), NAME_LENGTH); strcpy(full_name, loc("Anonymous")); user_email[0] = 0; } strcpy(list[i], "long_name"); strlcpy(value[i++], full_name, NAME_LENGTH); /* add email */ if (user_email[0]) { strcpy(list[i], "user_email"); strcpy(value[i], "mailto:"); strlcat(value[i++], user_email, NAME_LENGTH); } /* add logbook */ if (lbs) { strcpy(list[i], "logbook"); strlcpy(value[i++], lbs->name, NAME_LENGTH); /* add logbook */ strcpy(list[i], "elogbook"); strlcpy(value[i++], lbs->name_enc, NAME_LENGTH); } /* add date */ strcpy(list[i], "date"); time(&t); if (format_date) { ts = localtime(&t); assert(ts); if (!getcfg(lbs->name, "Time format", format, sizeof(format))) strcpy(format, DEFAULT_TIME_FORMAT); my_strftime(str, sizeof(str), format, ts); } else sprintf(str, "%d", (int) t); strcpy(value[i++], str); /* add UTC date */ strcpy(list[i], "utcdate"); time(&t); if (format_date) { ts = gmtime(&t); if (!getcfg(lbs->name, "Time format", format, sizeof(format))) strcpy(format, DEFAULT_TIME_FORMAT); my_strftime(str, sizeof(str), format, ts); } else sprintf(str, "%d", (int) t); strcpy(value[i++], str); /* add ELOG version and revision */ strcpy(list[i], "version"); strcpy(value[i++], VERSION); strcpy(list[i], "revision"); sprintf(value[i++], "%s", git_revision()); return i; }
CWE-79
null
519,273
61525877348824772668965163236863602113
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void compose_base_url(LOGBOOK *lbs, char *base_url, int size, BOOL email_notify) /* return URL for elogd with optional logbook subdirectory */ { if (email_notify) if (getcfg(lbs->name, "Use Email URL", base_url, size)) return; if (!getcfg("global", "URL", base_url, size)) { if (referer[0]) { /* get URL from referer */ strlcpy(base_url, referer, size); if (strchr(base_url, '?')) *strchr(base_url, '?') = 0; if (strrchr(base_url, '/')) *(strrchr(base_url, '/') + 1) = 0; } else { if (_ssl_flag) strcpy(base_url, "https://"); else strcpy(base_url, "http://"); if (elog_tcp_port == 80) sprintf(base_url + strlen(base_url), "%s/", host_name); else sprintf(base_url + strlen(base_url), "%s:%d/", host_name, elog_tcp_port); if (lbs) { strlcat(base_url, lbs->name_enc, size); strlcat(base_url, "/", size); } } } else { if (base_url[strlen(base_url) - 1] != '/') strlcat(base_url, "/", size); if (lbs) { strlcat(base_url, lbs->name_enc, size); strlcat(base_url, "/", size); } } }
CWE-79
null
519,274
42138771675837821863367590970116285544
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int get_thumb_name(const char *file_name, char *thumb_name, int size, int index) { char str[MAX_PATH_LENGTH]; thumb_name[0] = 0; /* append .png for all files as thumbnail name, except for PDF files (convert bug!) */ memset(str, 0, sizeof(str)); if (chkext(file_name, ".pdf") || chkext(file_name, ".ps")) { strlcpy(str, file_name, sizeof(str)); if (strrchr(str, '.')) *strrchr(str, '.') = 0; snprintf(str + strlen(str), sizeof(str) - strlen(str) - 1, "-%d.png", index); if (file_exist(str)) { strlcpy(thumb_name, str, size); return 2; } if (index > 0) return 0; strlcpy(str, file_name, sizeof(str)); if (strrchr(str, '.')) *strrchr(str, '.') = 0; strlcat(str, ".png", sizeof(str)); if (file_exist(str)) { strlcpy(thumb_name, str, size); return 1; } } else { strlcpy(str, file_name, sizeof(str)); sprintf(str + strlen(str), "-%d.png", index); if (file_exist(str)) { strlcpy(thumb_name, str, size); return 2; } if (index > 0) return 0; strlcpy(str, file_name, sizeof(str)); strlcat(str, ".png", sizeof(str)); if (file_exist(str)) { strlcpy(thumb_name, str, size); return 1; } } return 0; }
CWE-79
null
519,275
73804763837224516435629428528524169646
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int is_logbook(char *logbook) { char str[256]; if (strieq(logbook, "global")) return 0; /* check for 'global group' or 'global_xxx' */ strlcpy(str, logbook, sizeof(str)); str[7] = 0; return !strieq(str, "global "); }
CWE-79
null
519,276
323108569607416834834490842164831298244
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int exist_top_group() { int i; char str[256]; for (i = 0;; i++) { if (!enumcfg("global", str, sizeof(str), NULL, 0, i)) break; str[9] = 0; if (strieq(str, "top group")) return 1; } return 0; }
CWE-79
null
519,277
142357035138410999276074970759814801034
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
BOOL get_password_file(LOGBOOK *lbs, char *file_name, int size) { char str[256]; getcfg(lbs->name, "Password file", str, sizeof(str)); if (!str[0]) return FALSE; if (str[0] == DIR_SEPARATOR || str[1] == ':') strlcpy(file_name, str, size); else { strlcpy(file_name, logbook_dir, size); strlcat(file_name, str, size); } return TRUE; }
CWE-79
null
519,278
307546712982641033134370349431300817613
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
const char *git_revision() { const char *p = _git_revision; if (strrchr(p, '-')) p = strrchr(p, '-') + 2; return p; }
CWE-79
null
519,279
18150690054596399690904398404339490249
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
char *param_in_str(char *str, char *param) { char *p; p = str; do { if (stristr(p, param) == NULL) return NULL; p = stristr(p, param); /* if parameter not followed by '=', skip it */ if (*(p + strlen(param)) != '=') { p += strlen(param); continue; } /* if parameter is value of another parameter, skip it */ if (p > str + 1 && *(p - 1) == '=') { p += strlen(param); continue; } if (*p == 0) return NULL; return p; } while (1); }
CWE-79
null
519,280
80789724996719585239879366485484292287
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
static BOOL chkext(const char *str, const char *ext) { int extl, strl; char c1, c2; if (ext == NULL || str == NULL) return FALSE; extl = strlen(ext); strl = strlen(str); if (extl >= strl) return FALSE; str = str + strl - extl; while (*str) { c1 = *str++; c2 = *ext++; if (my_toupper(c1) != my_toupper(c2)) return FALSE; } return TRUE; }
CWE-79
null
519,281
67859420756392666682144237011712765375
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void el_decode_int(char *message, char *key, char *result, int size) { char str[80]; if (result == NULL) return; *result = 0; el_decode(message, key, str, sizeof(str)); if (str[0]) sprintf(str, "%d", atoi(str)); strlcpy(result, str, size); }
CWE-79
null
519,282
263272027867111011750394188924318111462
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void build_ref(char *ref, int size, char *mode, char *expand, char *attach, char *new_entries) { char str[1000], *p; if (strchr(getparam("cmdline"), '?')) strlcat(ref, strchr(getparam("cmdline"), '?'), size); /* eliminate old search */ if (strstr(ref, "cmd=Search&")) { strlcpy(str, strstr(ref, "cmd=Search&") + 11, sizeof(str)); p = strstr(ref, "cmd=Search&"); strlcpy(p, str, size - (p - ref)); } /* eliminate id=xxx */ if (strstr(ref, "id=")) { strlcpy(str, ref, sizeof(str)); p = strstr(str, "id=") + 3; while (*p && isdigit(*p)) p++; strlcpy(strstr(ref, "id="), p, size); if (strlen(ref) > 0 && ref[strlen(ref) - 1] == '?') ref[strlen(ref) - 1] = 0; } /* eliminate old mode if new one is present */ if (mode[0]) subst_param(ref, size, "mode", mode); /* eliminate old expand if new one is present */ if (expand[0]) subst_param(ref, size, "expand", expand); /* eliminate old attach if new one is present */ if (attach[0]) subst_param(ref, size, "attach", attach); /* eliminate old new_entries if new one is present */ if (new_entries[0]) subst_param(ref, size, "new_entries", new_entries); /* eliminate old last= */ if (isparam("last")) subst_param(ref, size, "last", getparam("last")); /* replace any '&' by '&amp;' */ strlcpy(str, ref, sizeof(str)); strencode2(ref, str, size); }
CWE-79
null
519,283
89589420028803862070633682842932092602
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void eprintf(const char *format, ...) { va_list ap; char *msg; va_start(ap, format); xvasprintf(&msg, format, ap); va_end(ap); (*printf_handler)(msg); free(msg); }
CWE-79
null
519,284
165164591426634457546319277808596878146
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void btou(char *str) /* convert all blanks to underscores in a string */ { int i; for (i = 0; i < (int) strlen(str); i++) if (str[i] == ' ') str[i] = '_'; }
CWE-79
null
519,285
303177964920543008386600483666395768863
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int el_delete_message(LOGBOOK *lbs, int message_id, BOOL delete_attachments, char attachment[MAX_ATTACHMENTS][MAX_PATH_LENGTH], BOOL delete_bw_ref, BOOL delete_reply_to) /******************************************************************** Routine: el_delete_message Purpose: Delete an ELog entry including attachments Input: LOGBOOK *lbs Pointer to logbook structure int message_id Message ID BOOL delete_attachments Delete attachments if TRUE char attachment Used to return attachments (on move) BOOL delete_bw_ref If true, delete backward references BOOL delete_reply_to If true, delete replies to this message Output: <none> Function value: EL_SUCCESS Successful completion \********************************************************************/ { int i, index, size, fh, tail_size, old_offset; char str[MAX_PATH_LENGTH], file_name[MAX_PATH_LENGTH * 3], reply_to[MAX_REPLY_TO * 10], in_reply_to[256]; char *buffer, *p; char *message, attachment_all[64 * MAX_ATTACHMENTS]; char attrib[MAX_N_ATTR][NAME_LENGTH]; for (index = 0; index < *lbs->n_el_index; index++) if (lbs->el_index[index].message_id == message_id) break; if (index == *lbs->n_el_index) return -1; snprintf(file_name, sizeof(file_name), "%s%s%s", lbs->data_dir, lbs->el_index[index].subdir, lbs->el_index[index].file_name); fh = open(file_name, O_RDWR | O_BINARY, 0644); if (fh < 0) return EL_FILE_ERROR; message = xmalloc(TEXT_SIZE + 1000); lseek(fh, lbs->el_index[index].offset, SEEK_SET); i = my_read(fh, message, TEXT_SIZE + 1000 - 1); if (i <= 0) { xfree(message); close(fh); return EL_FILE_ERROR; } if (_logging_level > 1) { sprintf(str, "DELETE entry #%d", message_id); write_logfile(lbs, str); } message[i] = 0; if (strncmp(message, "$@MID@$:", 8) != 0) { close(fh); xfree(message); /* file might have been edited, rebuild index */ el_build_index(lbs, TRUE); return el_delete_message(lbs, message_id, delete_attachments, attachment, delete_bw_ref, delete_reply_to); } /* check for correct ID */ if (atoi(message + 8) != message_id) { close(fh); xfree(message); return EL_FILE_ERROR; } /* decode message size */ p = strstr(message + 8, "$@MID@$:"); if (p == NULL) size = strlen(message); else size = p - message; message[size] = 0; /* delete attachments */ el_decode(message, "Attachment: ", attachment_all, sizeof(attachment_all)); for (i = 0; i < MAX_ATTACHMENTS; i++) { if (i == 0) p = strtok(attachment_all, ","); else p = strtok(NULL, ","); if (attachment != NULL) { if (attachment[i][0] && p) { /* delete old attachment if new one exists */ el_delete_attachment(lbs, p); } /* return old attachment if no new one */ if (!attachment[i][0] && p) strcpy(attachment[i], p); } if (delete_attachments && p) el_delete_attachment(lbs, p); } /* decode references */ el_decode_intlist(message, "Reply to: ", reply_to, sizeof(reply_to)); el_decode_int(message, "In reply to: ", in_reply_to, sizeof(in_reply_to)); /* decoded attributes */ for (i = 0;; i++) { el_enum_attr(message, i, attr_list[i], attrib[i]); if (!attr_list[i][0]) break; } /* buffer tail of logfile */ lseek(fh, 0, SEEK_END); tail_size = TELL(fh) - (lbs->el_index[index].offset + size); buffer = NULL; if (tail_size > 0) { buffer = xmalloc(tail_size); lseek(fh, lbs->el_index[index].offset + size, SEEK_SET); my_read(fh, buffer, tail_size); } lseek(fh, lbs->el_index[index].offset, SEEK_SET); if (tail_size > 0) { write(fh, buffer, tail_size); xfree(buffer); } /* truncate file here */ TRUNCATE(fh); /* if file length gets zero, delete file */ tail_size = lseek(fh, 0, SEEK_END); close(fh); xfree(message); if (tail_size == 0) remove(file_name); /* remove message from index */ strcpy(str, lbs->el_index[index].file_name); old_offset = lbs->el_index[index].offset; for (i = index; i < *lbs->n_el_index - 1; i++) memcpy(&lbs->el_index[i], &lbs->el_index[i + 1], sizeof(EL_INDEX)); (*lbs->n_el_index)--; if (*lbs->n_el_index > 0) lbs->el_index = xrealloc(lbs->el_index, sizeof(EL_INDEX) * (*lbs->n_el_index)); /* correct all offsets after deleted message */ for (i = 0; i < *lbs->n_el_index; i++) if (strieq(lbs->el_index[i].file_name, str) && lbs->el_index[i].offset > old_offset) lbs->el_index[i].offset -= size; /* if other logbook has same index, update pointers */ for (i = 0; lb_list[i].name[0]; i++) if (&lb_list[i] != lbs && lb_list[i].n_el_index == lbs->n_el_index) lb_list[i].el_index = lbs->el_index; /* delete also replies to this message */ if (delete_reply_to && reply_to[0]) { p = reply_to; if (isdigit(*p)) do { if (atoi(p)) el_delete_message(lbs, atoi(p), TRUE, NULL, FALSE, TRUE); while (*p && isdigit(*p)) p++; while (*p && (*p == ',' || *p == ' ')) p++; } while (*p); } /* delete backward references */ if (in_reply_to[0] && delete_bw_ref) { p = in_reply_to; do { if (atoi(p)) remove_reference(lbs, atoi(p), message_id, TRUE); while (*p && isdigit(*p)) p++; while (*p && (*p == ',' || *p == ' ')) p++; } while (*p); } /* execute shell if requested */ if (getcfg(lbs->name, "Execute delete", str, sizeof(str))) execute_shell(lbs, message_id, attrib, NULL, str); return EL_SUCCESS; }
CWE-79
null
519,286
309916528360227522851688850967688964624
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void set_redir(LOGBOOK *lbs, char *redir) { char str[NAME_LENGTH]; str[0] = 0; /* prepare relative path */ if (redir[0]) strlcpy(str, redir, sizeof(str)); else { if (lbs) snprintf(str, sizeof(str), "../%s/", lbs->name_enc); else if (getcfg_topgroup()) sprintf(str, "."); } set_location(lbs, str); }
CWE-79
null
519,287
85904739200554926092670483079851728964
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
BOOL isparam(char *param) { int i; if (strieq(param, "text")) return _mtext[0] != 0; for (i = 0; i < MAX_PARAM && _param[i][0]; i++) if (strieq(param, _param[i])) break; if (i < MAX_PARAM && _param[i][0]) return TRUE; return FALSE; }
CWE-79
null
519,288
85561776877601758959191144283514764750
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void submit_elog(LOGBOOK *lbs) { char str[NAME_LENGTH], str2[NAME_LENGTH], file_name[256], error[1000], date[80], *mail_list, *rcpt_list, list[10000], *p, locked_by[256], encoding[80], attrib[MAX_N_ATTR][NAME_LENGTH], subst_str[MAX_PATH_LENGTH], in_reply_to[80], reply_to[MAX_REPLY_TO * 10], user[256], user_email[256], mail_param[1000], *mail_to, *rcpt_to, full_name[256], att_file[MAX_ATTACHMENTS][256], slist[MAX_N_ATTR + 10][NAME_LENGTH], svalue[MAX_N_ATTR + 10][NAME_LENGTH], ua[NAME_LENGTH], draft[256]; int i, j, k, n, missing, first, index, mindex, suppress, message_id, resubmit_orig, mail_to_size, rcpt_to_size, ltime, year, month, day, hour, min, sec, n_attr, email_notify[1000], allowed_encoding, status, bdraft, old_mail; BOOL bedit, bmultiedit; struct tm tms; bmultiedit = isparam("nsel"); bedit = isparam("edit_id") && atoi(getparam("edit_id")); bdraft = isparam("draft"); /* check for condition */ if (isparam("condition")) { set_condition(getparam("condition")); /* rescan attributes */ n_attr = scan_attributes(lbs->name); } else n_attr = lbs->n_attr; /* check for editing interval */ if (isparam("edit_id")) if (!check_edit_time(lbs, atoi(getparam("edit_id")))) return; /* check for required attributs */ missing = 0; for (i = 0; i < lbs->n_attr; i++) { strcpy(ua, attr_list[i]); stou(ua); if (attr_flags[i] & AF_REQUIRED) { if (attr_flags[i] & AF_DATE) { sprintf(str, "d%d", i); if (isparam(str) == 0) missing = 1; sprintf(str, "m%d", i); if (isparam(str) == 0) missing = 1; sprintf(str, "y%d", i); if (isparam(str) == 0) missing = 1; if (missing) break; } else if (attr_flags[i] & AF_DATETIME) { sprintf(str, "d%d", i); if (isparam(str) == 0) missing = 1; sprintf(str, "m%d", i); if (isparam(str) == 0) missing = 1; sprintf(str, "y%d", i); if (isparam(str) == 0) missing = 1; sprintf(str, "h%d", i); if (isparam(str) == 0) missing = 1; sprintf(str, "n%d", i); if (isparam(str) == 0) missing = 1; if (missing) break; } else if ((attr_flags[i] & (AF_MULTI | AF_MUSERLIST | AF_MUSEREMAIL))) { for (j = 0; j < MAX_N_LIST; j++) { sprintf(str, "%s_%d", ua, j); if (isparam(str)) break; /* check for attributes without the _<i> from elog */ if (isparam(ua)) break; } if (j == MAX_N_LIST) { missing = 1; break; } } else if (isparam(ua) == 0 || *getparam(ua) == 0) { missing = 1; break; } } } if (missing && !bdraft) { sprintf(error, "<i>"); sprintf(error + strlen(error), loc("Error: Attribute <b>%s</b> not supplied"), attr_list[i]); sprintf(error + strlen(error), ".</i><p>\n"); sprintf(error + strlen(error), loc("Please go back and enter the <b>%s</b> field"), attr_list[i]); strcat(error, ".\n"); show_error(error); return; } /* check for numeric attributes */ if (!bdraft) { for (index = 0; index < lbs->n_attr; index++) if (attr_flags[index] & AF_NUMERIC) { strcpy(ua, attr_list[index]); stou(ua); strlcpy(str, isparam(ua) ? getparam(ua) : "", sizeof(str)); for (j = 0; i < (int) strlen(str); i++) if (!isdigit(str[i])) break; sprintf(str2, "- %s -", loc("keep original values")); if (i < (int) strlen(str) && strcmp(str, "<keep>") != 0 && strcmp(str, str2) != 0) { sprintf(error, loc("Error: Attribute <b>%s</b> must be numeric"), attr_list[index]); show_error(error); return; } } } for (i = 0; i < n_attr; i++) { strcpy(ua, attr_list[i]); stou(ua); if (attr_flags[i] & (AF_MULTI | AF_MUSERLIST | AF_MUSEREMAIL)) strcat(ua, "_0"); if (isparam(ua) && *getparam(ua) && attr_options[i][0][0]) { if (strieq(attr_options[i][0], "boolean") && !bdraft) { if (atoi(getparam(ua)) != 0 && atoi(getparam(ua)) != 1 && strcmp(getparam(ua), "<keep>") != 0) { strencode2(str, getparam(ua), sizeof(str)); sprintf(error, loc("Error: Value <b>%s</b> not allowed for boolean attributes"), str); show_error(error); return; } } else { /* check if option exists */ for (j = 0; attr_options[i][j][0]; j++) if (strieq(attr_options[i][j], getparam(ua))) break; /* check if option without {n} exists */ if (!attr_options[i][j][0]) { for (j = 0; attr_options[i][j][0]; j++) { strlcpy(str, attr_options[i][j], sizeof(str)); if (strchr(str, '{')) *strchr(str, '{') = 0; if (strieq(str, getparam(ua))) break; } } if (!attr_options[i][j][0] && isparam(ua) && strcmp(getparam(ua), "<keep>") != 0) { if (attr_flags[i] & AF_EXTENDABLE) { /* check if maximal number of options exceeded */ if (attr_options[i][MAX_N_LIST - 1][0]) { strcpy(error, loc("Maximum number of attribute options exceeded")); strcat(error, "<br>"); strcat(error, loc("Please increase MAX_N_LIST in elogd.c and recompile")); show_error(error); return; } if (!add_attribute_option(lbs, attr_list[i], getparam(ua), getparam("condition"))) return; } else { char encoded[100]; strencode2(encoded, getparam(ua), sizeof(encoded)); sprintf(error, loc("Error: Attribute option <b>%s</b> not existing"), encoded); show_error(error); return; } } } } } /* check if allowed encoding */ if (getcfg(lbs->name, "Allowed encoding", str, sizeof(str))) allowed_encoding = atoi(str); else allowed_encoding = 7; strlcpy(encoding, isparam("encoding") ? getparam("encoding") : "plain", sizeof(encoding)); /* check for valid encoding */ if (!strieq(encoding, "plain") && !strieq(encoding, "ELCode") && !strieq(encoding, "HTML")) strcpy(encoding, "plain"); if (strieq(encoding, "plain") && (allowed_encoding & 1) == 0) { show_error("Plain encoding not allowed"); return; } if (strieq(encoding, "ELCode") && (allowed_encoding & 2) == 0) { show_error("ELCode encoding not allowed"); return; } if (strieq(encoding, "HTML") && (allowed_encoding & 4) == 0) { show_error("HTML encoding not allowed"); return; } /* get attachments */ for (i = 0; i < MAX_ATTACHMENTS; i++) { sprintf(str, "attachment%d", i); strcpy(att_file[i], isparam(str) ? getparam(str) : ""); } /* retrieve attributes */ for (i = 0; i < n_attr; i++) { strcpy(ua, attr_list[i]); stou(ua); if (strieq(attr_options[i][0], "boolean") && !isparam(ua)) { strcpy(attrib[i], "0"); } else if (attr_flags[i] & (AF_MULTI | AF_MUSERLIST | AF_MUSEREMAIL)) { if (isparam(ua)) { strlcpy(attrib[i], getparam(ua), NAME_LENGTH); } else { attrib[i][0] = 0; first = 1; for (j = 0; j < MAX_N_LIST; j++) { sprintf(str, "%s_%d", ua, j); if (isparam(str)) { if (first) first = 0; else strlcat(attrib[i], " | ", NAME_LENGTH); if (strlen(attrib[i]) + strlen(getparam(str)) < NAME_LENGTH - 2) strlcat(attrib[i], getparam(str), NAME_LENGTH); else break; } } } } else if (attr_flags[i] & AF_DATE) { if (isparam(ua)) // from edit/reply of fixed attributes strlcpy(attrib[i], getparam(ua), NAME_LENGTH); else { sprintf(str, "m%d", i); if (isparam(str) && strieq(getparam(str), "<keep>")) strcpy(attrib[i], "<keep>"); else { sprintf(str, "y%d", i); year = isparam(str) ? atoi(getparam(str)) : 0; if (year < 100) year += 2000; sprintf(str, "m%d", i); month = isparam(str) ? atoi(getparam(str)) : 0; sprintf(str, "d%d", i); day = isparam(str) ? atoi(getparam(str)) : 0; if (month == 0 || day == 0) strcpy(attrib[i], ""); else { memset(&tms, 0, sizeof(struct tm)); tms.tm_year = year - 1900; tms.tm_mon = month - 1; tms.tm_mday = day; tms.tm_hour = 12; ltime = (int) mktime(&tms); if (ltime == -1) { show_error(loc("Date must be between 1970 and 2037")); return; } sprintf(attrib[i], "%d", ltime); } } } } else if (attr_flags[i] & AF_DATETIME) { if (isparam(ua)) // from edit/reply of fixed attributes strlcpy(attrib[i], getparam(ua), NAME_LENGTH); else { sprintf(str, "m%d", i); if (isparam(str) && strieq(getparam(str), "<keep>")) strcpy(attrib[i], "<keep>"); else { sprintf(str, "y%d", i); year = isparam(str) ? atoi(getparam(str)) : 0; if (year < 100) year += 2000; sprintf(str, "m%d", i); month = isparam(str) ? atoi(getparam(str)) : 0; sprintf(str, "d%d", i); day = isparam(str) ? atoi(getparam(str)) : 0; sprintf(str, "h%d", i); hour = isparam(str) ? atoi(getparam(str)) : 0; sprintf(str, "n%d", i); min = isparam(str) ? atoi(getparam(str)) : 0; sprintf(str, "c%d", i); sec = isparam(str) ? atoi(getparam(str)) : 0; if (month == 0 || day == 0) strcpy(attrib[i], ""); else { memset(&tms, 0, sizeof(struct tm)); tms.tm_year = year - 1900; tms.tm_mon = month - 1; tms.tm_mday = day; tms.tm_hour = hour; tms.tm_min = min; tms.tm_sec = sec; tms.tm_isdst = -1; ltime = (int) mktime(&tms); if (ltime == -1) { show_error(loc("Date must be between 1970 and 2037")); return; } sprintf(attrib[i], "%d", ltime); } } } } else { strlcpy(attrib[i], isparam(ua) ? getparam(ua) : "", NAME_LENGTH); /* remove any CR/LF */ if (strchr(attrib[i], '\r')) *strchr(attrib[i], '\r') = 0; if (strchr(attrib[i], '\n')) *strchr(attrib[i], '\n') = 0; /* strip trailing "{...}" */ if (is_cond_attr(i) && strchr(attrib[i], '{') && strchr(attrib[i], '}')) *strchr(attrib[i], '{') = 0; } } /* compile substitution list */ n = build_subst_list(lbs, slist, svalue, attrib, TRUE); if (bedit) add_subst_list(slist, svalue, "message id", getparam("edit_id"), &n); /* substitute attributes */ if (!bedit && !isparam("reply_to")) { for (index = 0; index < n_attr; index++) { sprintf(str, "Subst %s", attr_list[index]); if (getcfg(lbs->name, str, subst_str, sizeof(subst_str))) { /* do not format date for date attributes */ i = build_subst_list(lbs, slist, svalue, attrib, (attr_flags[index] & (AF_DATE | AF_DATETIME)) == 0); strsubst_list(subst_str, sizeof(subst_str), slist, svalue, i); /* check for index substitution if not in edit mode */ if (!bedit && strchr(subst_str, '#')) { /* get index */ get_auto_index(lbs, index, subst_str, str, sizeof(str)); strcpy(subst_str, str); } strcpy(attrib[index], subst_str); } } } /* subst attributes for edits */ if (bedit) { for (index = 0; index < n_attr; index++) { sprintf(str, "Subst on edit %s", attr_list[index]); if (getcfg(lbs->name, str, str2, sizeof(str2))) { /* do not format date for date attributes */ i = build_subst_list(lbs, slist, svalue, attrib, (attr_flags[index] & (AF_DATE | AF_DATETIME)) == 0); add_subst_list(slist, svalue, "message id", getparam("edit_id"), &i); strsubst_list(str2, sizeof(str2), slist, svalue, i); if (strlen(str2) > NAME_LENGTH - 100) { if (strstr(str2 + 100, "<br>")) { strlcpy(str, strstr(str2 + 100, "<br>"), sizeof(str)); } else strlcpy(str, str2 + 100, sizeof(str)); strcpy(str2, "..."); strlcat(str2, str, sizeof(str2)); } if (strncmp(str2, "<br>", 4) == 0) strcpy(attrib[index], str2 + 4); else strcpy(attrib[index], str2); } } } /* subst attributes for replies */ if (isparam("reply_to")) { for (index = 0; index < n_attr; index++) { sprintf(str, "Subst on reply %s", attr_list[index]); if (getcfg(lbs->name, str, str2, sizeof(str2))) { /* do not format date for date attributes */ i = build_subst_list(lbs, slist, svalue, attrib, (attr_flags[index] & (AF_DATE | AF_DATETIME)) == 0); if (isparam("reply_to")) add_subst_list(slist, svalue, "Reply to", getparam("reply_to"), &i); strsubst_list(str2, sizeof(str2), slist, svalue, i); strcpy(attrib[index], str2); } } } /* check for attributes to keep */ if (bmultiedit) { sprintf(str, "- %s -", loc("keep original values")); for (i = 0; i < n_attr; i++) { if (strieq(str, attrib[i])) strlcpy(attrib[i], "<keep>", NAME_LENGTH); } } message_id = 0; reply_to[0] = 0; in_reply_to[0] = 0; date[0] = 0; resubmit_orig = 0; locked_by[0] = 0; draft[0] = 0; if (isparam("draft")) strlcpy(draft, getparam("draft"), sizeof(draft)); if (bedit && isparam("resubmit") && atoi(getparam("resubmit")) == 1) { resubmit_orig = atoi(getparam("edit_id")); /* get old links */ el_retrieve(lbs, resubmit_orig, NULL, NULL, NULL, 0, NULL, 0, in_reply_to, reply_to, NULL, NULL, NULL, NULL); /* if not message head, move all preceeding messages */ /* outcommented, users want only resubmitted message occur at end (see what's new) if (in_reply_to[0]) { do { resubmit_orig = atoi(in_reply_to); el_retrieve(lbs, resubmit_orig, NULL, NULL, NULL, 0, NULL, 0, in_reply_to, reply_to, NULL, NULL); } while (in_reply_to[0]); } */ message_id = atoi(getparam("edit_id")); strcpy(in_reply_to, "<keep>"); strcpy(reply_to, "<keep>"); date[0] = 0; } else { if (bedit) { message_id = atoi(getparam("edit_id")); strcpy(in_reply_to, "<keep>"); strcpy(reply_to, "<keep>"); strcpy(date, "<keep>"); if (bdraft) strcpy(locked_by, "<keep>"); } else strcpy(in_reply_to, isparam("reply_to") ? getparam("reply_to") : ""); } if (_logging_level > 1) { if (bmultiedit) sprintf(str, "EDIT multiple entries"); else if (bdraft) sprintf(str, "DRAFT entry #%d", message_id); else if (bedit && !resubmit_orig) sprintf(str, "EDIT entry #%d", message_id); else sprintf(str, "NEW entry #%d", message_id); write_logfile(lbs, str); } if (bmultiedit) { for (i = n = 0; i < atoi(getparam("nsel")); i++) { sprintf(str, "s%d", i); if (isparam(str)) { message_id = atoi(getparam(str)); status = submit_elog_reply(lbs, message_id, attrib, getparam("text")); if (status != EL_SUCCESS) { sprintf(str, loc("New entry cannot be written to directory \"%s\""), lbs->data_dir); strcat(str, "\n<p>"); strcat(str, loc("Please check that it exists and elogd has write access and disk is not full")); show_error(str); return; } } } redirect(lbs, isparam("redir") ? getparam("redir") : ""); return; /* no email notifications etc */ } else { message_id = el_submit(lbs, message_id, bedit, date, attr_list, attrib, n_attr, getparam("text"), in_reply_to, reply_to, encoding, att_file, TRUE, locked_by, draft); if (message_id <= 0) { sprintf(str, loc("New entry cannot be written to directory \"%s\""), lbs->data_dir); strcat(str, "\n<p>"); strcat(str, loc("Please check that it exists and elogd has write access and disk is not full")); show_error(str); return; } if (bdraft) { show_http_header(lbs, FALSE, NULL); rsprintf("OK %d\n", message_id); return; } } /* evaluate propagation of attributes */ if (getcfg(lbs->name, "Propagate attributes", str, sizeof(str))) propagate_attrib(lbs, find_thread_head(lbs, message_id), attrib); /* resubmit thread if requested */ if (resubmit_orig) message_id = el_move_message_thread(lbs, resubmit_orig); /* retrieve submission date */ if (date[0] == 0) el_retrieve(lbs, message_id, date, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); /*---- replace relative elog:/x link by elog:n/x link */ if (stristr(getparam("text"), "elog:/")) { p = getparam("text"); if (stricmp(encoding, "HTML") == 0) { sprintf(str, "%d/", message_id); } else sprintf(str, "elog:%d/", message_id); strsubst(p, TEXT_SIZE, "elog:/", str); el_submit(lbs, message_id, TRUE, date, attr_list, attrib, n_attr, p, in_reply_to, reply_to, encoding, att_file, TRUE, NULL, NULL); } /*---- replace elog: by HTML link ----*/ if (strieq(encoding, "HTML") && stristr(getparam("text"), "elog:")) { p = stristr(getparam("text"), "elog:"); while (p) { for (i = 0; i < 5 || (p[i] == '/' || isalnum(p[i])); i++) str[i] = p[i]; str[i] = 0; convert_elog_link(lbs, str + 5, str + 5, str2, 0, message_id); strsubst(p, TEXT_SIZE, str, str2); p += strlen(str2); p = stristr(p, "elog:"); } el_submit(lbs, message_id, TRUE, date, attr_list, attrib, n_attr, getparam("text"), in_reply_to, reply_to, encoding, att_file, TRUE, NULL, NULL); } /*---- email notifications ----*/ suppress = isparam("suppress") ? atoi(getparam("suppress")) : 0; /* check for mail submissions */ mail_param[0] = 0; mail_to = (char *) xmalloc(256); mail_to[0] = 0; mail_to_size = 256; rcpt_to = (char *) xmalloc(256); rcpt_to[0] = 0; rcpt_to_size = 256; mail_list = (char *) xmalloc(MAX_N_EMAIL * NAME_LENGTH); rcpt_list = (char *) xmalloc(MAX_N_EMAIL * NAME_LENGTH); if (suppress == 1 || suppress == 3) { if (suppress == 1) strcpy(mail_param, "?suppress=1"); } else { /* go throuch "Email xxx" in configuration file */ for (index = mindex = 0; index <= n_attr; index++) { strcpy(ua, attr_list[index]); stou(ua); if (index < n_attr) { strcpy(str, "Email "); if (strchr(attr_list[index], ' ')) sprintf(str + strlen(str), "\"%s\"", attr_list[index]); else strlcat(str, attr_list[index], sizeof(str)); strcat(str, " "); if (attr_flags[index] & (AF_MULTI | AF_MUSERLIST | AF_MUSEREMAIL)) { sprintf(str2, "%s_%d", ua, mindex); mindex++; if (mindex == MAX_N_LIST) mindex = 0; else index--; /* repeat this loop */ } else strlcpy(str2, ua, sizeof(str2)); if (isparam(str2)) { if (strchr(getparam(str2), ' ')) { strlcat(str, "\"", sizeof(str)); strlcat(str, getparam(str2), sizeof(str)); strlcat(str, "\"", sizeof(str)); } else strlcat(str, getparam(str2), sizeof(str)); } } else sprintf(str, "Email ALL"); if (getcfg(lbs->name, str, list, sizeof(list))) { i = build_subst_list(lbs, slist, svalue, attrib, TRUE); strsubst_list(list, sizeof(list), slist, svalue, i); n = strbreak(list, (char (*)[1500]) mail_list, 200, ",", FALSE); if (get_verbose() >= VERBOSE_INFO) eprintf("\n%s to %s\n\n", str, list); for (i = 0; i < n; i++) { /* remove possible 'mailto:' */ if ((p = strstr(&mail_list[i * NAME_LENGTH], "mailto:")) != NULL) memmove(p, p + 7, strlen(p + 7) + 1); if ((int) strlen(mail_to) + (int) strlen(&mail_list[i * NAME_LENGTH]) + 10 >= mail_to_size) { mail_to_size += 256; mail_to = xrealloc(mail_to, mail_to_size); } strcat(mail_to, &mail_list[i * NAME_LENGTH]); strcat(mail_to, ","); if ((int) strlen(rcpt_to) + (int) strlen(&mail_list[i * NAME_LENGTH]) + 10 >= rcpt_to_size) { rcpt_to_size += 256; rcpt_to = xrealloc(rcpt_to, rcpt_to_size); } strcat(rcpt_to, &mail_list[i * NAME_LENGTH]); strcat(rcpt_to, ","); } } } if (!getcfg(lbs->name, "Suppress Email to users", str, sizeof(str)) || atoi(str) == 0) { /* go through password file */ for (index = 0;; index++) { if (!enum_user_line(lbs, index, user, sizeof(user))) break; get_user_line(lbs, user, NULL, full_name, user_email, email_notify, NULL, NULL); for (i = 0; lb_list[i].name[0] && i < 1000; i++) if (strieq(lb_list[i].name, lbs->name)) break; if (email_notify[i]) { /* check if user has access to this logbook */ if (!check_login_user(lbs, user)) continue; sprintf(str, "\"%s\" <%s>,", full_name, user_email); if ((int) strlen(mail_to) + (int) strlen(str) + 1 >= mail_to_size) { mail_to_size += 256; mail_to = xrealloc(mail_to, mail_to_size); } strcat(mail_to, str); sprintf(str, "%s,", user_email); if ((int) strlen(rcpt_to) + (int) strlen(str) + 1 >= rcpt_to_size) { rcpt_to_size += 256; rcpt_to = xrealloc(rcpt_to, rcpt_to_size); } strcat(rcpt_to, str); } } } } if (strlen(mail_to) > 0) { /* convert any '|' to ',', remove duplicate email to's */ n = strbreak(rcpt_to, (void *) rcpt_list, MAX_N_EMAIL, ",|", TRUE); strbreak(mail_to, (void *) mail_list, MAX_N_EMAIL, ",|", TRUE); for (i = 0; i < n - 1; i++) { for (j = i + 1; j < n; j++) { if (rcpt_list[i * NAME_LENGTH] && rcpt_list[j * NAME_LENGTH] && strstr(&rcpt_list[i * NAME_LENGTH], &rcpt_list[j * NAME_LENGTH])) { for (k = j; k < n - 1; k++) { memcpy(&rcpt_list[k * NAME_LENGTH], &rcpt_list[(k + 1) * NAME_LENGTH], NAME_LENGTH); memcpy(&mail_list[k * NAME_LENGTH], &mail_list[(k + 1) * NAME_LENGTH], NAME_LENGTH); } memset(&rcpt_list[k * NAME_LENGTH], 0, NAME_LENGTH); memset(&mail_list[k * NAME_LENGTH], 0, NAME_LENGTH); j = j - 1; n = n - 1; break; } } } rcpt_to[0] = 0; mail_to[0] = 0; for (i = 0; i < n; i++) { if ((int) strlen(rcpt_to) + (int) strlen(&rcpt_list[i * NAME_LENGTH]) + 5 >= rcpt_to_size) { rcpt_to_size += 256; rcpt_to = xrealloc(rcpt_to, rcpt_to_size); } strcat(rcpt_to, &rcpt_list[i * NAME_LENGTH]); if ((int) strlen(mail_to) + (int) strlen(&mail_list[i * NAME_LENGTH]) + 5 >= mail_to_size) { mail_to_size += 256; mail_to = xrealloc(mail_to, mail_to_size); } strcat(mail_to, &mail_list[i * NAME_LENGTH]); if (i < MAX_N_EMAIL - 1 && rcpt_list[(i + 1) * NAME_LENGTH]) { strcat(rcpt_to, ","); strcat(mail_to, ",\r\n\t"); } } /* fix for edited draft messages. new_entry is a hidden field persisting draft cycles */ old_mail = bedit; if (isparam("new_entry")) old_mail = 0; if (resubmit_orig) old_mail = 0; if (compose_email(lbs, rcpt_to, mail_to, message_id, attrib, mail_param, old_mail, att_file, isparam("encoding") ? getparam("encoding") : "plain", atoi(in_reply_to)) == 0) { xfree(mail_to); xfree(rcpt_to); xfree(mail_list); xfree(rcpt_list); return; } } xfree(mail_to); xfree(rcpt_to); xfree(mail_list); xfree(rcpt_list); /*---- shell execution ----*/ if (!(isparam("shell_suppress") && atoi(getparam("shell_suppress")))) { if (!bedit) { if (getcfg(lbs->name, "Execute new", str, sizeof(str))) execute_shell(lbs, message_id, attrib, att_file, str); } else { if (getcfg(lbs->name, "Execute edit", str, sizeof(str))) execute_shell(lbs, message_id, attrib, att_file, str); } } /*---- custom submit page ----*/ if (getcfg(lbs->name, "Submit page", str, sizeof(str))) { /* check if file starts with an absolute directory */ if (str[0] == DIR_SEPARATOR || str[1] == ':') strcpy(file_name, str); else { strlcpy(file_name, logbook_dir, sizeof(file_name)); strlcat(file_name, str, sizeof(file_name)); } send_file_direct(file_name); return; } if (getcfg(lbs->name, "List after submit", str, sizeof(str)) && atoi(str) == 1) str[0] = 0; else sprintf(str, "%d%s", message_id, mail_param); redirect(lbs, str); }
CWE-79
null
519,289
153001505039289752727438214519089200989
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int my_read(int fh, void *buffer, unsigned int bytes) { #ifdef OS_UNIX int i, n = 0; do { i = read(fh, (char *) buffer + n, bytes - n); /* don't return if an alarm signal was cought */ if (i == -1 && errno == EINTR) continue; if (i == -1) return -1; if (i == 0) return n; n += i; } while (n < (int) bytes); return n; #else return read(fh, buffer, bytes); #endif return 0; }
CWE-79
null
519,290
181069297376838325952340926801045829449
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
time_t date_to_ltime(char *date) { struct tm tms; int i, date_zone, local_zone; time_t ltime; memset(&tms, 0, sizeof(struct tm)); if (strlen(date) > 25) { /* RFC2822 compliant date */ for (i = 0; i < 12; i++) if (strncmp(date + 8, mname[i], 3) == 0) break; tms.tm_mon = i; tms.tm_mday = atoi(date + 5); tms.tm_hour = atoi(date + 17); tms.tm_min = atoi(date + 20); tms.tm_sec = atoi(date + 23); tms.tm_year = atoi(date + 12) - 1900; tms.tm_isdst = -1; if (tms.tm_year < 90) tms.tm_year += 100; ltime = mktime(&tms); /* correct for difference between local time zone (used by mktime) and time zone of date */ date_zone = atoi(date + 26); /* correct for incorrect date_zone */ if (date_zone > 2400 || date_zone < -2400) date_zone = 0; date_zone = (abs(date_zone) % 100) * 60 + (date_zone) / 100 * 3600; local_zone = my_timezone(); if (tms.tm_isdst) local_zone -= 3600; ltime = ltime - local_zone - date_zone; } else { /* ctime() complient date */ for (i = 0; i < 12; i++) if (strncmp(date + 4, mname[i], 3) == 0) break; tms.tm_mon = i; tms.tm_mday = atoi(date + 8); tms.tm_hour = atoi(date + 11); tms.tm_min = atoi(date + 14); tms.tm_sec = atoi(date + 17); tms.tm_year = atoi(date + 20) - 1900; tms.tm_isdst = -1; if (tms.tm_year < 90) tms.tm_year += 100; ltime = mktime(&tms); } return ltime; }
CWE-79
null
519,291
274299384794119878077712334041968912479
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int el_submit_attachment(LOGBOOK *lbs, const char *afilename, const char *buffer, int buffer_size, char *full_name) { char file_name[MAX_PATH_LENGTH], ext_file_name[ MAX_PATH_LENGTH + 100], str[MAX_PATH_LENGTH], *p, subdir[MAX_PATH_LENGTH]; int fh; time_t now; struct tm tms; /* strip directory, add date and time to filename */ strlcpy(str, afilename, sizeof(str)); p = str; while (strchr(p, ':')) p = strchr(p, ':') + 1; while (strchr(p, '\\')) p = strchr(p, '\\') + 1; /* NT */ while (strchr(p, '/')) p = strchr(p, '/') + 1; /* Unix */ strlcpy(file_name, p, sizeof(file_name)); /* assemble ELog filename */ if (file_name[0]) { if (file_name[6] == '_' && file_name[13] == '_' && isdigit(file_name[0]) && isdigit(file_name[1])) strlcpy(ext_file_name, file_name, sizeof(ext_file_name)); else { time(&now); memcpy(&tms, localtime(&now), sizeof(struct tm)); sprintf(ext_file_name, "%02d%02d%02d_%02d%02d%02d_%s", tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday, tms.tm_hour, tms.tm_min, tms.tm_sec, file_name); } if (full_name) strlcpy(full_name, ext_file_name, MAX_PATH_LENGTH); strlcpy(str, lbs->data_dir, sizeof(str)); generate_subdir_name(ext_file_name, subdir, sizeof(subdir)); strlcat(str, subdir, sizeof(str)); if (strlen(str) > 0 && str[strlen(str) - 1] == DIR_SEPARATOR) str[strlen(str) - 1] = 0; #ifdef OS_WINNT mkdir(str); #else mkdir(str, 0755); #endif strlcat(str, DIR_SEPARATOR_STR, sizeof(str)); strlcat(str, ext_file_name, sizeof(str)); /* save attachment */ fh = open(str, O_CREAT | O_RDWR | O_BINARY, 0644); if (fh < 0) { strencode2(file_name, str, sizeof(file_name)); sprintf(str, "Cannot write attachment file \"%s\"", file_name); show_error(str); return -1; } else { write(fh, buffer, buffer_size); close(fh); } } return 0; }
CWE-79
null
519,292
262788614674484820095814947132783437396
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int sendmail(LOGBOOK *lbs, char *smtp_host, char *from, char *to, char *text, char *error, int error_size) { struct sockaddr_in bind_addr; struct hostent *phe; int i, n, s, strsize; char *str; char list[MAX_N_EMAIL][NAME_LENGTH], buffer[10000], decoded[256]; memset(error, 0, error_size); if (get_verbose() >= VERBOSE_INFO) eprintf("\n\nEmail from %s to %s, SMTP host %s:\n", from, to, smtp_host); sprintf(buffer, "Email from %s to ", from); strlcat(buffer, to, sizeof(buffer)); strlcat(buffer, ", SMTP host ", sizeof(buffer)); strlcat(buffer, smtp_host, sizeof(buffer)); strlcat(buffer, ":\n", sizeof(buffer)); write_logfile(lbs, buffer); /* create a new socket for connecting to remote server */ s = socket(AF_INET, SOCK_STREAM, 0); if (s == -1) return -1; strsize = MAX_CONTENT_LENGTH + 1000; str = xmalloc(strsize); /* connect to remote node port on SMTP port */ int smtp_port = 25; if (getcfg(lbs->name, "SMTP port", str, strsize)) smtp_port = atoi(str); memset(&bind_addr, 0, sizeof(bind_addr)); bind_addr.sin_family = AF_INET; bind_addr.sin_port = htons((short) smtp_port); phe = gethostbyname(smtp_host); if (phe == NULL) { if (error) strlcpy(error, loc("Cannot lookup server name"), error_size); return -1; } memcpy((char *) &(bind_addr.sin_addr), phe->h_addr, phe->h_length); if (connect(s, (void *) &bind_addr, sizeof(bind_addr)) < 0) { closesocket(s); if (error) strlcpy(error, loc("Cannot connect to server"), error_size); return -1; } recv_string(s, str, strsize, 10000); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); /* drain server messages */ do { str[0] = 0; recv_string(s, str, strsize, 300); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); } while (str[0]); if (getcfg(lbs->name, "SMTP username", str, strsize)) { snprintf(str, strsize - 1, "EHLO %s\r\n", host_name); send(s, str, strlen(str), 0); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); do { recv_string(s, str, strsize, 3000); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); if (!check_smtp_error(str, 250, error, error_size)) goto smtp_error; } while (stristr(str, "250 ") == NULL); } else { snprintf(str, strsize - 1, "HELO %s\r\n", host_name); send(s, str, strlen(str), 0); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); recv_string(s, str, strsize, 3000); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); if (!check_smtp_error(str, 250, error, error_size)) goto smtp_error; } /* optional authentication */ if (getcfg(lbs->name, "SMTP username", str, strsize)) { snprintf(str, strsize - 1, "AUTH LOGIN\r\n"); send(s, str, strlen(str), 0); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); recv_string(s, str, strsize, 3000); if (strchr(str, '\r')) *strchr(str, '\r') = 0; if (atoi(str) != 334) { strcat(str, "\n"); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); } else { base64_decode(str + 4, decoded); strcat(decoded, "\n"); if (get_verbose() >= VERBOSE_INFO) efputs(decoded); write_logfile(lbs, decoded); } if (!check_smtp_error(str, 334, error, error_size)) goto smtp_error; getcfg(lbs->name, "SMTP username", decoded, sizeof(decoded)); base64_encode((unsigned char *) decoded, (unsigned char *) str, strsize); strcat(str, "\r\n"); send(s, str, strlen(str), 0); if (get_verbose() >= VERBOSE_INFO) efputs(decoded); write_logfile(lbs, decoded); recv_string(s, str, strsize, 3000); if (strchr(str, '\r')) *strchr(str, '\r') = 0; base64_decode(str + 4, decoded); strcat(decoded, "\n"); if (get_verbose() >= VERBOSE_INFO) efputs(decoded); write_logfile(lbs, decoded); if (!check_smtp_error(str, 334, error, error_size)) goto smtp_error; getcfg(lbs->name, "SMTP password", str, strsize); strcat(str, "\r\n"); send(s, str, strlen(str), 0); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); recv_string(s, str, strsize, 3000); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); if (!check_smtp_error(str, 235, error, error_size)) goto smtp_error; } snprintf(str, strsize - 1, "MAIL FROM: %s\r\n", from); send(s, str, strlen(str), 0); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); recv_string(s, str, strsize, 3000); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); if (!check_smtp_error(str, 250, error, error_size)) goto smtp_error; /* break recipients into list */ n = strbreak(to, list, MAX_N_EMAIL, ",", FALSE); for (i = 0; i < n; i++) { if (list[i] == 0 || strchr(list[i], '@') == NULL) continue; snprintf(str, strsize - 1, "RCPT TO: <%s>\r\n", list[i]); send(s, str, strlen(str), 0); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); /* increased timeout for SMTP servers with long alias lists */ recv_string(s, str, strsize, 30000); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); if (!check_smtp_error(str, 250, error, error_size)) goto smtp_error; } snprintf(str, strsize - 1, "DATA\r\n"); send(s, str, strlen(str), 0); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); recv_string(s, str, strsize, 3000); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); if (!check_smtp_error(str, 354, error, error_size)) goto smtp_error; /* replace "." at beginning of line by ".." */ strlcpy(str, text, strsize); strsubst(str, strsize, "\n.", "\n.."); /* add ".<CR>" to signal end of message */ strlcat(str, ".\r\n", strsize); /* check if buffer exceeded */ if ((int) strlen(str) == strsize - 1) { strlcpy(error, loc("Entry size too large for email notification"), error_size); goto smtp_error; } send(s, str, strlen(str), 0); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); recv_string(s, str, strsize, 10000); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); if (!check_smtp_error(str, 250, error, error_size)) goto smtp_error; snprintf(str, strsize - 1, "QUIT\r\n"); send(s, str, strlen(str), 0); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); recv_string(s, str, strsize, 3000); if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); if (!check_smtp_error(str, 221, error, error_size)) goto smtp_error; closesocket(s); xfree(str); return 1; smtp_error: closesocket(s); xfree(str); return -1; }
CWE-79
null
519,293
224558573765065151336167895487918696397
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void show_forgot_pwd_page(LOGBOOK *lbs) { int i; char str[1000], str2[1000], login_name[256], full_name[256], user_email[256], name[256], pwd[256], redir[256], smtp_host[256], mail_from[256], mail_from_name[256], subject[256], mail_text[1000], url[1000], error[1000]; if (isparam("login_name")) { /* seach in pwd file */ strcpy(name, getparam("login_name")); for (i = 0;; i++) { if (!enum_user_line(lbs, i, login_name, sizeof(login_name))) break; get_user_line(lbs, login_name, NULL, full_name, user_email, NULL, NULL, NULL); if (strieq(name, login_name) || strieq(name, full_name) || strieq(name, user_email)) { if (user_email[0] == 0) { sprintf(str, loc("No Email address registered with user name <i>\"%s\"</i>"), name); strencode2(str2, str, sizeof(str2)); show_error(str2); return; } /* create random password */ for (i = 0; i < 16; i++) pwd[i] = 'A' + (rand() % 25); pwd[i] = 0; /* send email with new password */ if (!getcfg("global", "SMTP host", smtp_host, sizeof(smtp_host))) { show_error(loc("No SMTP host defined in [global] section of configuration file")); return; } /* try to get URL from referer */ if (!getcfg("global", "URL", url, sizeof(url))) { if (referer[0]) strcpy(url, referer); else { if (elog_tcp_port == 80) { if (_ssl_flag) sprintf(url, "https://%s/", http_host); else sprintf(url, "http://%s/", http_host); } else { if (_ssl_flag) sprintf(url, "https://%s:%d/", http_host, elog_tcp_port); else sprintf(url, "http://%s:%d/", http_host, elog_tcp_port); } } } else { if (url[strlen(url) - 1] != '/') strlcat(url, "/", sizeof(url)); if (lbs) { strlcat(url, lbs->name_enc, sizeof(url)); strlcat(url, "/", sizeof(url)); } } url_slash_encode(pwd, sizeof(pwd)); sprintf(redir, "?cmd=%s&oldpwd=%s", loc("Change password"), pwd); url_encode(redir, sizeof(redir)); strencode2(str2, redir, sizeof(str2)); sprintf(str, "?redir=%s&uname=%s&upassword=%s", str2, login_name, pwd); strlcat(url, str, sizeof(url)); retrieve_email_from(lbs, mail_from, mail_from_name, NULL); if (lbs) sprintf(subject, loc("Password recovery for ELOG %s"), lbs->name); else sprintf(subject, loc("Password recovery for ELOG %s"), http_host); mail_text[0] = 0; compose_email_header(lbs, subject, mail_from_name, user_email, NULL, mail_text, sizeof(mail_text), 1, 0, NULL, 0, 0); strlcat(mail_text, "\r\n", sizeof(mail_text)); sprintf(mail_text + strlen(mail_text), loc("This is an automatically generated account recovery email for host %s"), http_host); strlcat(mail_text, ".\r\n", sizeof(mail_text)); strlcat(mail_text, loc("Please click on following link to recover your account"), sizeof(mail_text)); strlcat(mail_text, ":\r\n\r\n", sizeof(mail_text)); strlcat(mail_text, url, sizeof(mail_text)); strlcat(mail_text, "\r\n\r\n", sizeof(mail_text)); sprintf(mail_text + strlen(mail_text), "ELOG Version %s\r\n", VERSION); if (sendmail(lbs, smtp_host, mail_from, user_email, mail_text, error, sizeof(error)) != -1) { /* save new password */ auth_change_password(lbs, login_name, NULL, pwd, str, sizeof(str)); /* show notification web page */ show_standard_header(lbs, FALSE, loc("ELOG password recovery"), "", FALSE, NULL, NULL, 0); rsprintf("<table class=\"dlgframe\" cellspacing=0 align=center>"); rsprintf("<tr><td class=\"dlgtitle\">\n"); rsprintf(loc("Email notification")); rsprintf("</td></tr>\n"); rsprintf("<tr><td align=center class=\"dlgform\">\n"); rsprintf(loc("A password recovery email for user <i>\"%s\"</i> has been sent to %s"), full_name, user_email); rsprintf("</td></tr></table>\n"); show_bottom_text(lbs); rsprintf("</body></html>\n"); return; } else { sprintf(str, loc("Error sending Email via \"%s\""), smtp_host); strlcat(str, ": ", sizeof(str)); strlcat(str, error, sizeof(str)); show_error(str); return; } } } if (strchr(name, '@')) sprintf(str, loc("Email address \"%s\" not registered"), name); else sprintf(str, loc("User name \"%s\" not registered"), name); strencode2(str2, str, sizeof(str2)); show_error(str2); return; } else { /*---- header ----*/ getcfg(lbs->name, "Authentication", str, sizeof(str)); if (stristr(str, "Kerberos") || stristr(str, "Webserver") || stristr(str, "PAM")) { show_error ("This installation of ELOG uses site authentication\nwhere password recovery is not possible"); return; } show_standard_header(lbs, TRUE, loc("ELOG password recovery"), NULL, FALSE, NULL, NULL, 0); rsprintf("<table class=\"dlgframe\" cellspacing=0 align=center>"); /*---- entry form ----*/ rsprintf("<tr><td class=\"dlgtitle\">%s</td></tr>\n", loc("Enter your user name or email address")); rsprintf("<tr><td align=center class=\"dlgform\">\n"); rsprintf("<input type=hidden name=cmd value=%s>\n", loc("Forgot")); rsprintf("<input type=text size=40 name=login_name></td></tr>\n"); rsprintf("<tr><td align=center class=\"dlgform\"><input type=submit value=\"%s\">\n", loc("Submit")); rsprintf("</td></tr></table>\n\n"); show_bottom_text(lbs); rsprintf("</form></body></html>\r\n"); } }
CWE-79
null
519,294
227167573727073374815888091894963959385
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int is_html(char *s) { char *str, *p; int i; str = xstrdup(s); for (i = 0; i < (int) strlen(s); i++) str[i] = toupper(s[i]); str[i] = 0; for (i = 0; html_tags[i][0]; i++) { p = strstr(str, html_tags[i]); if (p && strchr(p, '>') && (p == str || (p > str && *(p - 1) != '\\'))) { xfree(str); return TRUE; } } if (strstr(str, "&#") && strchr(strstr(str, "&#"), ';')) { xfree(str); return TRUE; } xfree(str); return FALSE; }
CWE-79
null
519,295
24329791675828284919407312626128811335
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void efputs(const char *buf) { (*fputs_handler)(buf); }
CWE-79
null
519,296
205391649710812831054378007606307265629
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void adjust_crlf(char *buffer, int bufsize) { char *p; UNUSED(bufsize); #ifdef OS_UNIX /* convert \r\n -> \n */ p = buffer; while ((p = strstr(p, "\r\n")) != NULL) { memmove(p, p + 1, strlen(p + 1) + 1); // strcpy() gives error under Ubuntu } #else char *tmpbuf; assert(bufsize); tmpbuf = xmalloc(bufsize); /* convert \n -> \r\n */ p = buffer; while ((p = strstr(p, "\n")) != NULL) { if (p > buffer && *(p - 1) == '\r') { p++; continue; } if ((int) strlen(buffer) + 2 >= bufsize) { xfree(tmpbuf); return; } strlcpy(tmpbuf, p, bufsize); *(p++) = '\r'; strlcpy(p, tmpbuf, bufsize - (p - buffer)); p++; } xfree(tmpbuf); #endif }
CWE-79
null
519,297
152182361012541289845458533703323374755
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void _MD5_update(MD5_CONTEXT *pctx, const void *pdata, unsigned int len) { unsigned char *pin; unsigned int i, index, partlen; pin = (unsigned char *) pdata; // compute number of bytes mod 64 index = (unsigned int) ((pctx->count[0] >> 3) & 0x3F); // update number of bits if ((pctx->count[0] += ((unsigned int) len << 3)) < ((unsigned int) len << 3)) pctx->count[1]++; pctx->count[1] += ((unsigned int) len >> 29); partlen = 64 - index; // transform as many times as possible. if (len >= partlen) { memcpy(&pctx->buffer[index], pin, partlen); _MD5_transform(pctx->state, pctx->buffer); for (i = partlen; i + 63 < len; i += 64) _MD5_transform(pctx->state, &pin[i]); index = 0; } else i = 0; /* buffer remaining input */ memcpy(&pctx->buffer[index], &pin[i], len - i); }
CWE-79
null
519,298
249702076088680952950764547662023412739
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int strbreak(char *str, char list[][NAME_LENGTH], int size, char *brk, BOOL ignore_quotes) /* break comma-separated list into char array, stripping leading and trailing blanks */ { int i, j; char *p; memset(list, 0, size * NAME_LENGTH); p = str; if (!p || !*p) return 0; while (*p == ' ') p++; for (i = 0; *p && i < size; i++) { if (*p == '"' && !ignore_quotes) { p++; j = 0; memset(list[i], 0, NAME_LENGTH); do { /* convert two '"' to one */ if (*p == '"' && *(p + 1) == '"') { list[i][j++] = '"'; p += 2; } else if (*p == '"') { break; } else list[i][j++] = *p++; } while (j < NAME_LENGTH - 1); list[i][j] = 0; /* skip second '"' */ p++; /* skip blanks and break character */ while (*p == ' ') p++; if (*p && strchr(brk, *p)) p++; while (*p == ' ') p++; } else { strlcpy(list[i], p, NAME_LENGTH); for (j = 0; j < (int) strlen(list[i]); j++) if (strchr(brk, list[i][j])) { list[i][j] = 0; break; } p += strlen(list[i]); while (*p == ' ') p++; if (*p && strchr(brk, *p)) p++; while (*p == ' ') p++; } while (list[i][strlen(list[i]) - 1] == ' ') list[i][strlen(list[i]) - 1] = 0; if (!*p) break; } if (i == size) return size; return i + 1; }
CWE-79
null
519,299
270839781090336962346614404095836814160
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void highlight_searchtext(regex_t *re_buf, char *src, char *dst, int hidden) { char *pt, *pt1; int size, status; regmatch_t pmatch[10]; dst[0] = 0; pt = src; /* original text */ pt1 = dst; /* text with inserted coloring */ do { status = regexec(re_buf, pt, 10, pmatch, 0); if (status != REG_NOMATCH) { size = pmatch[0].rm_so; /* abort if zero length match, for example from "m*" */ if (pmatch[0].rm_eo - pmatch[0].rm_so == 0) { status = REG_NOMATCH; strcpy(pt1, pt); break; } /* copy first part original text */ memcpy(pt1, pt, size); pt1 += size; pt += size; /* add coloring 1st part */ /* here: \001='<', \002='>', /003='"', and \004=' ' */ /* see also rsputs2(char* ) */ if (hidden) strcpy(pt1, "\001B\004style=\003color:black;background-color:#ffff66\003\002"); else strcpy(pt1, "<B style=\"color:black;background-color:#ffff66\">"); pt1 += strlen(pt1); /* copy origial search text */ size = pmatch[0].rm_eo - pmatch[0].rm_so; memcpy(pt1, pt, size); pt1 += size; pt += size; /* add coloring 2nd part */ if (hidden) strcpy(pt1, "\001/B\002"); else strcpy(pt1, "</B>"); pt1 += strlen(pt1); } } while (status != REG_NOMATCH); strcpy(pt1, pt); }
CWE-79
null
519,300
171215353529724730910432086482223742682
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void xml_import(LOGBOOK *lbs, const char *xml, const char *xmlfile) { char str[NAME_LENGTH], date[80], error[256], encoding[256], *list, *p, in_reply_to[80], reply_to[MAX_REPLY_TO * 10], attachment[MAX_ATTACHMENTS][MAX_PATH_LENGTH], attachment_all[64 * MAX_ATTACHMENTS]; int i, j, index, n_attr, iline, n_imported, i_line, line_len, message_id, bedit; time_t ltime; PMXML_NODE root, entry; iline = n_imported = 0; n_attr = lbs->n_attr; root = mxml_parse_buffer(xml, error, sizeof(error), NULL); if (root == NULL) { strencode2(str, error, sizeof(str)); show_error(str); return; } root = mxml_find_node(root, "ELOG_LIST"); if (root == NULL) { sprintf(str, loc("XML file does not contain %s element"), "&lt;ELOG_LIST&gt;"); show_error(str); return; } entry = mxml_subnode(root, 0); if (mxml_find_node(entry, "MID") == NULL) { sprintf(str, loc("XML file does not contain %s element"), "&lt;MID&gt;"); show_error(str); return; } if (mxml_find_node(entry, "DATE") == NULL) { sprintf(str, loc("XML file does not contain %s element"), "&lt;DATE&gt;"); show_error(str); return; } if (mxml_find_node(entry, "ENCODING") == NULL) { sprintf(str, loc("XML file does not contain %s element"), "&lt;ENCODING&gt;"); show_error(str); return; } if (isparam("preview")) { /* title row */ sprintf(str, loc("XML import preview of %s"), xmlfile); show_standard_header(lbs, TRUE, str, "./", FALSE, NULL, NULL, 0); rsprintf("<table class=\"frame\" cellpadding=\"0\" cellspacing=\"0\">\n"); rsprintf("<tr><td class=\"title1\">%s</td></tr>\n", str, str); /* menu buttons */ rsprintf("<tr><td class=\"menuframe\"><span class=\"menu1\">\n"); rsprintf("<input type=submit name=cmd value=\"%s\">\n", loc("Cancel")); rsprintf("<input type=submit name=cmd value=\"%s\">\n", loc("XML Import")); /* hidden fields */ if (isparam("head")) rsprintf("<input type=hidden name=head value=\"%s\">\n", getparam("head")); if (isparam("keep")) rsprintf("<input type=hidden name=keep value=\"%s\">\n", getparam("keep")); rsprintf("<input type=hidden name=xmlfile value=\"%s\">\n", xmlfile); rsprintf("</span></td></tr>\n\n"); rsprintf("<tr><td><table class=\"listframe\" width=\"100%%\" cellspacing=0>"); } list = (char *) xmalloc(MAX_N_ATTR * NAME_LENGTH); /* derive attributes from XML file */ if (isparam("head")) { if (isparam("preview")) { rsprintf("<tr>\n"); for (i = 0; i < mxml_get_number_of_children(entry); i++) { strlcpy(str, mxml_get_name(mxml_subnode(entry, i)), sizeof(str)); if (strieq(str, "MID")) strcpy(str, "ID"); if (strieq(str, "DATE")) strcpy(str, loc("Date")); if (strieq(str, "TEXT")) strcpy(str, loc("Text")); if (!strieq(str, "ENCODING") && !strieq(str, "IN_REPLY_TO") && !strieq(str, "REPLY_TO") && !strieq(str, "ATTACHMENT")) rsprintf("<th class=\"listtitle\">%s</th>\n", str); } rsprintf("</tr>\n"); n_attr = i; } else { for (i = j = 0; i < mxml_get_number_of_children(entry); i++) { strlcpy(str, mxml_get_name(mxml_subnode(entry, i)), NAME_LENGTH); if (stricmp(str, "MID") != 0 && stricmp(str, "DATE") != 0 && stricmp(str, "ENCODING") != 0 && stricmp(str, "TEXT") != 0 && stricmp(str, "IN_REPLY_TO") != 0 && stricmp(str, "REPLY_TO") != 0 && stricmp(str, "ATTACHMENT") != 0) strlcpy(attr_list[j++], mxml_get_name(mxml_subnode(entry, i)), NAME_LENGTH); } if (!set_attributes(lbs, attr_list, j)) return; lbs->n_attr = n_attr = j; } } else { if (isparam("preview")) { rsprintf("<tr>\n"); rsprintf("<th class=\"listtitle\">%s</th>\n", "ID"); rsprintf("<th class=\"listtitle\">%s</th>\n", loc("Date")); for (i = 0; i < n_attr; i++) rsprintf("<th class=\"listtitle\">%s</th>\n", attr_list[i]); rsprintf("<th class=\"listtitle\">%s</th>\n", loc("Text")); rsprintf("</tr>\n"); } } for (index = 0; index < mxml_get_number_of_children(root); index++) { entry = mxml_subnode(root, index); if (isparam("preview")) { rsprintf("<tr>\n"); for (i = 0; i < mxml_get_number_of_children(entry); i++) { strlcpy(str, mxml_get_name(mxml_subnode(entry, i)), NAME_LENGTH); if (strieq(str, "ENCODING") || strieq(str, "IN_REPLY_TO") || strieq(str, "REPLY_TO") || strieq(str, "ATTACHMENT")) continue; if (strieq(str, "TEXT")) break; if (iline % 2 == 0) rsputs("<td class=\"list1\">"); else rsputs("<td class=\"list2\">"); strlcpy(str, mxml_get_value(mxml_subnode(entry, i)), NAME_LENGTH); if (!str[0]) rsputs("&nbsp;"); else rsputs(str); rsputs("</td>\n"); } rsputs("<td class=\"summary\">"); if (mxml_find_node(entry, "TEXT")) { strlcpy(str, mxml_get_value(mxml_find_node(entry, "TEXT")), sizeof(str)); if (str[0]) { /* limit output to 3 lines */ for (i = i_line = line_len = 0; i < (int) sizeof(str) - 1; i++, line_len++) { if (str[i] == '\n') { i_line++; line_len = 0; } else /* limit line length to 150 characters */ if (line_len > 150 && str[i] == ' ') { str[i] = '\n'; i_line++; line_len = 0; } if (i_line == 3) break; } str[i] = 0; strip_html(str); if (str[0]) strencode(str); else rsputs("&nbsp;"); } else rsputs("&nbsp;"); } rsputs("</td>\n"); rsputs("</tr>\n"); iline++; } else { message_id = 0; if (isparam("keep")) message_id = atoi(mxml_get_value(mxml_find_node(entry, "MID"))); for (i = 0; i < n_attr; i++) { strlcpy(str, attr_list[i], sizeof(str)); while (strchr(str, ' ')) *strchr(str, ' ') = '_'; if (mxml_find_node(entry, str) == NULL) *(list + (i * NAME_LENGTH)) = 0; else strlcpy(list + i * NAME_LENGTH, mxml_get_value(mxml_find_node(entry, str)), NAME_LENGTH); } /* interprete date entries correctly */ for (i = 0; i < n_attr; i++) { if (attr_flags[i] & AF_DATE) { /* convert to seconds in Unix format */ ltime = convert_date(list + i * NAME_LENGTH); if (ltime == 0) { show_error(loc("Invalid date format")); return; } sprintf(list + i * NAME_LENGTH, "%d", (int) ltime); } if (attr_flags[i] & AF_DATETIME) { /* convert to seconds in Unix format */ ltime = convert_datetime(list + i * NAME_LENGTH); if (ltime == 0) { show_error(loc("Invalid date format")); return; } sprintf(list + i * NAME_LENGTH, "%d", (int) ltime); } } encoding[0] = 0; if (mxml_find_node(entry, "ENCODING")) strlcpy(encoding, mxml_get_value(mxml_find_node(entry, "ENCODING")), sizeof(encoding)); else strcpy(encoding, "plain"); reply_to[0] = 0; if (mxml_find_node(entry, "REPLY_TO")) strlcpy(reply_to, mxml_get_value(mxml_find_node(entry, "REPLY_TO")), sizeof(reply_to)); in_reply_to[0] = 0; if (mxml_find_node(entry, "IN_REPLY_TO")) strlcpy(in_reply_to, mxml_get_value(mxml_find_node(entry, "IN_REPLY_TO")), sizeof(in_reply_to)); date[0] = 0; if (mxml_find_node(entry, "DATE")) strlcpy(date, mxml_get_value(mxml_find_node(entry, "DATE")), sizeof(date)); attachment_all[0] = 0; if (mxml_find_node(entry, "ATTACHMENT")) strlcpy(attachment_all, mxml_get_value(mxml_find_node(entry, "ATTACHMENT")), sizeof(attachment_all)); memset(attachment, 0, sizeof(attachment)); for (i = 0; i < MAX_ATTACHMENTS; i++) { if (i == 0) p = strtok(attachment_all, ","); else p = strtok(NULL, ","); if (p != NULL) strlcpy(attachment[i], p, MAX_PATH_LENGTH); else break; } str[0] = 0; if (mxml_find_node(entry, "TEXT")) p = mxml_get_value(mxml_find_node(entry, "TEXT")); else p = str; bedit = FALSE; if (isparam("keep")) { for (i = 0; i < *lbs->n_el_index; i++) if (lbs->el_index[i].message_id == message_id) break; if (lbs->el_index[i].message_id == message_id) bedit = TRUE; } /* submit entry */ if (el_submit (lbs, message_id, bedit, date, attr_list, (char (*)[NAME_LENGTH]) list, n_attr, p, in_reply_to, reply_to, encoding, attachment, FALSE, NULL, NULL)) n_imported++; } } xfree(list); if (isparam("preview")) { rsprintf("</table></td></tr></table>\n"); show_bottom_text(lbs); rsprintf("</form></body></html>\r\n"); return; } sprintf(str, loc("%d entries successfully imported"), n_imported); show_elog_list(lbs, 0, 0, 0, TRUE, str); }
CWE-79
null
519,301
61756431797802519630661727318442788043
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void insert_breaks(char *str, int n, int size) { int i, j, i_last; i_last = 0; for (i = 0; i < (int) strlen(str); i++) { if (str[i] == '\r') i_last = i; /* if more than n chars without return, insert one */ if (i - i_last >= n && (int) strlen(str) + 3 < size) { /* find previous blank */ while (i > i_last && str[i] != ' ') i--; if (str[i] == ' ') i++; /* move trailing string one char further */ for (j = strlen(str) + 2; j > i; j--) str[j] = str[j - 2]; /* set CR */ str[i++] = '\r'; str[i++] = '\n'; i_last = i; } } }
CWE-79
null
519,302
87388980344088887582894422663068842111
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
BOOL file_exist(char *file_name) { int fh; fh = open(file_name, O_RDONLY); if (fh < 0) return FALSE; close(fh); return TRUE; }
CWE-79
null
519,303
99013341988444073016648278533458468938
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void show_plain_header(int size, char *file_name) { /* header */ rsprintf("HTTP/1.1 200 Document follows\r\n"); rsprintf("Server: ELOG HTTP %s-%s\r\n", VERSION, git_revision()); rsprintf("Accept-Ranges: bytes\r\n"); if (keep_alive) { rsprintf("Connection: Keep-Alive\r\n"); rsprintf("Keep-Alive: timeout=60, max=10\r\n"); } rsprintf("Pragma: no-cache\r\n"); rsprintf("Cache-control: private, max-age=0, no-cache, no-store\r\n"); rsprintf("Content-Type: text/plain\r\n"); rsprintf("Content-disposition: attachment; filename=\"%s\"\r\n", file_name); if (size) rsprintf("Content-Length: %d\r\n", size); rsprintf("\r\n"); }
CWE-79
null
519,304
211356313142313623712203661265362592722
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void rsputs2(LOGBOOK *lbs, int absolute_link, const char *str) { int i, j, k, l, n; char *p, *pd, link[1000], link_text[1000]; if (strlen_retbuf + (int) (2 * strlen(str) + 1000) >= return_buffer_size) { return_buffer = xrealloc(return_buffer, return_buffer_size + 100000); memset(return_buffer + return_buffer_size, 0, 100000); return_buffer_size += 100000; } j = strlen_retbuf; for (i = 0; i < (int) strlen(str); i++) { for (l = 0; key_list[l][0]; l++) { if (strncmp(str + i, key_list[l], strlen(key_list[l])) == 0) { /* check for escape character */ if (i > 0 && *(str + i - 1) == '\\') { j--; *(return_buffer + j) = 0; continue; } p = (char *) (str + i + strlen(key_list[l])); i += strlen(key_list[l]); for (k = 0; *p && strcspn(p, " \t\n\r({[)}]\"") && k < (int) sizeof(link); k++, i++) link[k] = *p++; link[k] = 0; i--; /* link may not end with a '.'/',' (like in a sentence) */ if (link[k - 1] == '.' || link[k - 1] == ',') { link[k - 1] = 0; k--; i--; } /* check if link contains coloring */ p = strchr(link, '\001'); if (p != NULL) { strlcpy(link_text, link, sizeof(link_text)); /* skip everything between '<' and '>' */ pd = p; while (*pd && *pd != '\002') *p = *pd++; memmove(p, pd + 1, strlen(pd + 1) + 1); /* skip '</B>' */ p = strchr(link, '\001'); if (p != NULL) { pd = p; while (*pd && *pd != '\002') *p = *pd++; memmove(p, pd + 1, strlen(pd + 1) + 1); } /* correct link text */ for (n = 0; n < (int) strlen(link_text); n++) { switch (link_text[n]) { /* the translation for the search highliting */ case '\001': link_text[n] = '<'; break; case '\002': link_text[n] = '>'; break; case '\003': link_text[n] = '\"'; break; case '\004': link_text[n] = ' '; break; } } } else strlcpy(link_text, link, sizeof(link_text)); if (strcmp(key_list[l], "elog:") == 0) { convert_elog_link(lbs, link, link_text, return_buffer + j, absolute_link, _current_message_id); } else if (strcmp(key_list[l], "mailto:") == 0) { sprintf(return_buffer + j, "<a href=\"mailto:%s\">%s</a>", link, link_text); } else { sprintf(return_buffer + j, "<a href=\"%s", key_list[l]); j += strlen(return_buffer + j); strlen_retbuf = j; /* link can contain special characters */ rsputs2(lbs, absolute_link, link); j = strlen_retbuf; sprintf(return_buffer + j, "\">%s", key_list[l]); j += strlen(return_buffer + j); strlen_retbuf = j; /* link_text can contain special characters */ rsputs2(lbs, absolute_link, link_text); j = strlen_retbuf; sprintf(return_buffer + j, "</a>"); } j += strlen(return_buffer + j); break; } } if (!key_list[l][0]) { if (strncmp(str + i, "<br>", 4) == 0) { strcpy(return_buffer + j, "<br>"); j += 4; i += 3; } else switch (str[i]) { case '&': strcat(return_buffer, "&amp;"); j += 5; break; case '<': strcat(return_buffer, "&lt;"); j += 4; break; case '>': strcat(return_buffer, "&gt;"); j += 4; break; /* suppress escape character '\' in front of HTML or ELCode tag */ case '\\': if (str[i + 1] != '<' && str[i + 1] != '[') return_buffer[j++] = str[i]; break; /* the translation for the search highliting */ case '\001': strcat(return_buffer, "<"); j++; break; case '\002': strcat(return_buffer, ">"); j++; break; case '\003': strcat(return_buffer, "\""); j++; break; case '\004': strcat(return_buffer, " "); j++; break; default: return_buffer[j++] = str[i]; } } } return_buffer[j] = 0; strlen_retbuf = j; }
CWE-79
null
519,305
31363218668425539679941890469681714965
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void show_admin_page(LOGBOOK *lbs, char *top_group) { int rows, cols; char *buffer, error_str[256]; char section[NAME_LENGTH], str[NAME_LENGTH], grp[NAME_LENGTH]; /*---- header ----*/ sprintf(str, "ELOG %s", loc("Admin")); show_html_header(lbs, FALSE, str, TRUE, FALSE, NULL, FALSE, 0); rsprintf("<body><form method=\"POST\" action=\"./\" enctype=\"multipart/form-data\">\n"); /*---- title ----*/ show_standard_title(lbs, "", 0); /*---- menu buttons ----*/ rsprintf("<tr><td class=\"menuframe\"><span class=\"menu1\">\n"); rsprintf("<input type=submit name=cmd value=\"%s\">\n", loc("Save")); rsprintf("<input type=submit name=cmd value=\"%s\">\n", loc("Cancel")); rsprintf("<input type=hidden name=cfgpage value=\"1\">\n"); if (lbs->top_group[0] && (!top_group || strieq(top_group, "global"))) { if (is_admin_user(NULL, getparam("unm"))) { if (lbs->top_group[0]) { sprintf(str, "global %s", lbs->top_group); if (is_group(str)) { sprintf(grp, "[global %s]", lbs->top_group); sprintf(str, loc("Change %s"), grp); rsprintf("<input type=submit name=cmd value=\"%s\">\n", str); } } } } if (is_group("global") && !strieq(top_group, "global")) { if (is_admin_user_global(getparam("unm"))) { sprintf(str, loc("Change %s"), "[global]"); rsprintf("<input type=submit name=cmd value=\"%s\">\n", str); } } if (top_group) { if (strieq(top_group, "global")) { rsprintf("<input type=hidden name=global value=\"global\">\n"); strcpy(str, "[global]"); } else { rsprintf("<input type=hidden name=global value=\"%s\">\n", top_group); sprintf(str, "[global %s]", top_group); } rsprintf("<br><center><b>%s</b></center>", str); } if (is_group("global") && !strieq(top_group, "global")) { if (is_admin_user(NULL, getparam("unm"))) { rsprintf("<input type=submit name=cmd value=\"%s\">\n", loc("Delete this logbook")); rsprintf("<input type=submit name=cmd value=\"%s\">\n", loc("Rename this logbook")); rsprintf("<input type=submit name=cmd value=\"%s\">\n", loc("Create new logbook")); } } rsprintf("</span></td></tr>\n\n"); /*---- entry form ----*/ rsprintf("<tr><td class=\"form1\">\n"); /* extract section of current logbook */ if (top_group) { if (strieq(top_group, "global")) strcpy(section, "global"); else sprintf(section, "global %s", top_group); } else strcpy(section, lbs->name); load_config_section(section, &buffer, error_str); if (error_str[0]) { rsprintf("<h2>%s</h2>\n", error_str); rsprintf("</table></td></tr></table>\n"); rsprintf("</body></html>\r\n"); return; } if (getcfg(section, "Admin textarea", str, sizeof(str)) && strchr(str, ',') != NULL) { cols = atoi(str); rows = atoi(strchr(str, ',') + 1); } else { cols = 120; rows = 30; } rsprintf("<textarea cols=%d rows=%d wrap=virtual name=Text>", cols, rows); rsputs3(buffer); xfree(buffer); rsprintf("</textarea>\n"); /* put link for config page */ rsprintf("<br><a target=\"_blank\" href=\"https://elog.psi.ch/elog/config.html\">Syntax Help</a>"); rsprintf("</td></tr>\n"); /*---- menu buttons ----*/ rsprintf("<tr><td class=\"menuframe\"><span class=\"menu1\">\n"); rsprintf("<input type=submit name=cmd value=\"%s\">\n", loc("Save")); rsprintf("<input type=submit name=cmd value=\"%s\">\n", loc("Cancel")); rsprintf("</span></td></tr>\n\n"); rsprintf("</table>\n\n"); show_bottom_text(lbs); rsprintf("</form></body></html>\r\n"); }
CWE-79
null
519,306
122252525855172720494482871854868690922
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void show_elog_list(LOGBOOK *lbs, int past_n, int last_n, int page_n, BOOL default_page, char *info) { int i, j, n, index, size, status, d1, m1, y1, h1, n1, c1, d2, m2, y2, h2, n2, c2, n_line, flags, printable, n_logbook, n_display, reverse, numeric, n_attr_disp, n_msg, search_all, message_id, n_page, i_start, i_stop, in_reply_to_id, page_mid, page_mid_head, level, refresh, disp_attr_flags[MAX_N_ATTR + 4]; char date[80], attrib[MAX_N_ATTR][NAME_LENGTH], disp_attr[MAX_N_ATTR + 4][NAME_LENGTH], *list, *text, *text1, in_reply_to[80], reply_to[MAX_REPLY_TO * 10], attachment[MAX_ATTACHMENTS][MAX_PATH_LENGTH], encoding[80], locked_by[256], str[NAME_LENGTH], ref[256], img[80], comment[NAME_LENGTH], mode[80], mid[80], menu_str[1000], menu_item[MAX_N_LIST][NAME_LENGTH], param[NAME_LENGTH], format[80], sort_attr[MAX_N_ATTR + 4][NAME_LENGTH], mode_cookie[80], charset[25], sort_item[NAME_LENGTH], refr[80], str2[80], draft[256]; char *p, *pt1, *pt2, *slist, *svalue, *gattr, line[1024], iattr[256]; BOOL show_attachments, threaded, csv, xml, raw, mode_commands, expand, filtering, date_filtering, disp_filter, show_text, text_in_attr, searched, found, disp_attr_link[MAX_N_ATTR + 4], sort_attributes, show_att_column = 0; time_t ltime, ltime_start, ltime_end, now, ltime1, ltime2, entry_ltime; struct tm tms, *ptms; MSG_LIST *msg_list; LOGBOOK *lbs_cur; regex_t re_buf[MAX_N_ATTR + 1]; regmatch_t pmatch[10]; /* redirect if empty parameters */ if (strstr(_cmdline, "=&")) { while ((pt1 = strstr(_cmdline, "=&")) != NULL) { pt2 = pt1; while (*pt1 != '&' && *pt1 != '?') pt1--; pt1++; strcpy(param, pt1); param[pt2 - pt1] = 0; memmove(pt1, pt2 + 2, strlen(pt2 + 2) + 1); /* remove param from lastcmd if present */ if ((pt1 = strstr(_cmdline, "lastcmd=")) != NULL) { sprintf(str, "%s%%3D", param); if ((pt1 = strstr(_cmdline, str)) != NULL) { pt2 = pt1 + strlen(str); while (*pt2 && *pt2 != '%') pt2++; if (*pt2 == '%') pt2 += 3; memmove(pt1, pt2, strlen(pt2) + 1); } } } if (_cmdline[strlen(_cmdline) - 1] == '=') { pt1 = _cmdline + strlen(_cmdline) - 1; while (*pt1 != '&' && *pt1 != '?') pt1--; pt1++; strcpy(param, pt1); if (param[strlen(param) - 1] == '=') param[strlen(param) - 1] = 0; *pt1 = 0; /* remove param from lastcmd if present */ if ((pt1 = strstr(_cmdline, "lastcmd=")) != NULL) { sprintf(str, "%s%%3D", param); if ((pt1 = strstr(_cmdline, str)) != NULL) { pt2 = pt1 + strlen(str); while (*pt2 && *pt2 != '%' && *pt2 != '&') pt2++; if (*pt2 == '%') pt2 += 3; memmove(pt1, pt2, strlen(pt2) + 1); } } } if (_cmdline[strlen(_cmdline) - 1] == '&') _cmdline[strlen(_cmdline) - 1] = 0; redirect(lbs, _cmdline); return; } /* redirect "go" command */ if (isparam("lastcmd")) { strlcpy(str, getparam("lastcmd"), sizeof(str)); url_decode(str); /* subsitute "last" in command line from new parameter */ if (isparam("last")) { if (strieq(getparam("last"), "_all_")) subst_param(str, sizeof(str), "last", ""); else subst_param(str, sizeof(str), "last", getparam("last")); } /* subsitute attributes in command line from new parameter */ for (i = 0; i < MAX_N_ATTR; i++) if (isparam(attr_list[i])) { if (strieq(getparam(attr_list[i]), "_all_")) subst_param(str, sizeof(str), attr_list[i], ""); else subst_param(str, sizeof(str), attr_list[i], getparam(attr_list[i])); } /* do the same for subtext */ if (isparam("subtext")) subst_param(str, sizeof(str), "subtext", getparam("subtext")); redirect(lbs, str); return; } /* remove remaining "_all_" in parameters */ if (isparam("last") && strieq(getparam("last"), "_all_")) { strlcpy(str, _cmdline, sizeof(str)); subst_param(str, sizeof(str), "last", ""); redirect(lbs, str); return; } /* remove remaining "_all_" or empty or "--+<attrib>+--" parameters */ strlcpy(str, _cmdline, sizeof(str)); found = 0; for (i = 0; i < MAX_N_ATTR; i++) { if (isparam(attr_list[i])) { if (strieq(getparam(attr_list[i]), "_all_")) { subst_param(str, sizeof(str), attr_list[i], ""); found = 1; } if (*getparam(attr_list[i]) == 0) { subst_param(str, sizeof(str), attr_list[i], ""); found = 1; } sprintf(ref, "-- %s --", attr_list[i]); if (strieq(getparam(attr_list[i]), ref)) { subst_param(str, sizeof(str), attr_list[i], ""); found = 1; } } } if (isparam("subtext")) { if (*getparam("subtext") == 0) { subst_param(str, sizeof(str), "subtext", ""); found = 1; } sprintf(ref, "-- %s --", loc("Text")); if (strieq(getparam("subtext"), ref)) { subst_param(str, sizeof(str), "subtext", ""); found = 1; } } if (found) { redirect(lbs, str); return; } slist = (char *) xmalloc((MAX_N_ATTR + 10) * NAME_LENGTH); svalue = (char *) xmalloc((MAX_N_ATTR + 10) * NAME_LENGTH); gattr = (char *) xmalloc(MAX_N_ATTR * NAME_LENGTH); list = (char *) xmalloc(10000); printable = isparam("Printable") ? atoi(getparam("Printable")) : 0; /* in printable mode, display all pages */ if (printable) page_n = -1; if (isparam("Reverse")) reverse = atoi(getparam("Reverse")); else { reverse = 0; if (getcfg(lbs->name, "Reverse sort", str, sizeof(str))) reverse = atoi(str); } /* get message ID from "list" command */ if (isparam("id")) page_mid = atoi(getparam("id")); else page_mid = 0; page_mid_head = 0; /* default mode */ strlcpy(mode, "Summary", sizeof(mode)); show_attachments = FALSE; /* check for valid page_n */ if (page_n < -1) page_n = 0; if (past_n || last_n || page_n || page_mid || default_page) { /* for page display, get mode from config file */ if (getcfg(lbs->name, "Display Mode", str, sizeof(str))) strlcpy(mode, str, sizeof(mode)); /* supersede mode from cookie */ if (isparam("elmode")) strlcpy(mode, getparam("elmode"), sizeof(mode)); /* supersede mode from direct parameter */ if (isparam("mode")) strlcpy(mode, getparam("mode"), sizeof(mode)); } else { /* for find result, get mode from find form */ if (isparam("mode")) strlcpy(mode, getparam("mode"), sizeof(mode)); else strlcpy(mode, "Full", sizeof(mode)); } /* set cookie if mode changed */ mode_cookie[0] = 0; if (strieq(mode, "Summary") || strieq(mode, "Full") || strieq(mode, "Threaded")) { if (!isparam("elmode") || !strieq(getparam("elmode"), mode)) sprintf(mode_cookie, "elmode=%s", mode); } threaded = strieq(mode, "threaded"); csv = strieq(mode, "CSV1") || strieq(mode, "CSV2") || strieq(mode, "CSV3"); xml = strieq(mode, "XML"); raw = strieq(mode, "Raw"); if (csv || xml || raw) { page_n = -1; /* display all pages */ show_attachments = FALSE; /* hide attachments */ } /* show attachments in full mode by default */ if (strieq(mode, "Full")) show_attachments = TRUE; /* supersede attachment mode if in cookie */ if (isparam("elattach")) show_attachments = atoi(getparam("elattach")); /* supersede attachment mode if in parameter */ if (isparam("attach")) show_attachments = atoi(getparam("attach")); /* set cookie if attachment mode changed in full view */ if (mode_cookie[0] == 0 && strieq(mode, "Full")) { if (!isparam("elattach") || atoi(getparam("elattach")) != show_attachments) sprintf(mode_cookie, "elattach=%d", show_attachments); } /*---- convert dates to ltime ----*/ time(&now); ptms = localtime(&now); assert(ptms); ltime_end = ltime_start = 0; d1 = m1 = y1 = h1 = n1 = c1 = d2 = m2 = y2 = h2 = n2 = c2 = 0; if (!past_n && !last_n) { ltime_start = retrieve_date("a", TRUE); if (ltime_start < 0) { xfree(slist); xfree(svalue); xfree(gattr); xfree(list); return; } if (ltime_start) { memcpy(&tms, localtime(&ltime_start), sizeof(struct tm)); y1 = tms.tm_year + 1900; m1 = tms.tm_mon + 1; d1 = tms.tm_mday; h1 = tms.tm_hour; n1 = tms.tm_min; c1 = tms.tm_sec; } ltime_end = retrieve_date("b", FALSE); if (ltime_end < 0) { xfree(slist); xfree(svalue); xfree(gattr); xfree(list); return; } if (ltime_end) { if (ltime_end <= ltime_start) { sprintf(str, "Error: Start date after end date"); show_error(str); xfree(slist); xfree(svalue); xfree(gattr); xfree(list); return; } memcpy(&tms, localtime(&ltime_end), sizeof(struct tm)); y2 = tms.tm_year + 1900; m2 = tms.tm_mon + 1; d2 = tms.tm_mday; h2 = tms.tm_hour; n2 = tms.tm_min; c2 = tms.tm_sec; } } if (ltime_start && ltime_end && ltime_start > ltime_end) { show_error(loc("Error: start date after end date")); xfree(slist); xfree(svalue); xfree(gattr); xfree(list); return; } /*---- if user present but not allowed, log it out (required when several logbooks are used with different access rights and global passwords ----*/ if (isparam("unm") && !check_login_user(lbs, getparam("unm"))) { unsetparam("unm"); sid_remove(getparam("sid")); set_sid_cookie(lbs, "", ""); } /*---- apply last login cut ----*/ if (isparam("new_entries") && atoi(getparam("new_entries")) == 1 && isparam("unm")) get_user_line(lbs, getparam("unm"), NULL, NULL, NULL, NULL, &ltime_start, NULL); /*---- assemble message list ----*/ /* check for search all */ search_all = isparam("all") ? atoi(getparam("all")) : 0; if (getcfg(lbs->name, "Search all logbooks", str, sizeof(str)) && atoi(str) == 0) search_all = 0; n_msg = 0; n_display = 0; if (search_all) { /* count logbooks */ for (n_logbook = 0;; n_logbook++) { if (!lb_list[n_logbook].name[0]) break; if (lbs->top_group[0] && !strieq(lbs->top_group, lb_list[n_logbook].top_group)) continue; if (isparam("unm") && !check_login_user(&lb_list[n_logbook], getparam("unm"))) continue; n_msg += *lb_list[n_logbook].n_el_index; } } else { n_logbook = 1; n_msg = *lbs->n_el_index; } msg_list = (MSG_LIST *) xmalloc(sizeof(MSG_LIST) * n_msg); lbs_cur = lbs; numeric = TRUE; for (i = n = 0; i < n_logbook; i++) { if (search_all) lbs_cur = &lb_list[i]; if (lbs->top_group[0] && !strieq(lbs->top_group, lbs_cur->top_group)) continue; if (isparam("unm") && !check_login_user(lbs_cur, getparam("unm"))) continue; for (j = 0; j < *lbs_cur->n_el_index; j++) { msg_list[n].lbs = lbs_cur; msg_list[n].index = j; msg_list[n].number = (int) lbs_cur->el_index[j].file_time; msg_list[n].in_reply_to = lbs_cur->el_index[j].in_reply_to; n++; } } /*---- apply start/end date cut ----*/ date_filtering = FALSE; if (past_n > 0) ltime_start = now - 3600 * 24 * past_n; // past n days else if (past_n < 0) ltime_start = now + 3600 * past_n; // past n hours if (last_n && last_n < n_msg) { date_filtering = TRUE; for (i = n_msg - last_n - 1; i >= 0; i--) msg_list[i].lbs = NULL; } if (ltime_start) { date_filtering = TRUE; for (i = 0; i < n_msg; i++) if (msg_list[i].lbs && msg_list[i].lbs->el_index[msg_list[i].index].file_time < ltime_start) msg_list[i].lbs = NULL; } if (ltime_end) { date_filtering = TRUE; for (i = 0; i < n_msg; i++) if (msg_list[i].lbs && msg_list[i].lbs->el_index[msg_list[i].index].file_time > ltime_end) msg_list[i].lbs = NULL; } if (isparam("last") || getcfg(lbs->name, "Last default", str, sizeof(str))) { date_filtering = TRUE; if (isparam("last")) n = atoi(getparam("last")); else n = atoi(str); if (n > 0) { for (i = 0; i < n_msg; i++) if (msg_list[i].lbs && msg_list[i].lbs->el_index[msg_list[i].index].file_time < now - 3600 * 24 * n) msg_list[i].lbs = NULL; } } /*---- filter message list ----*/ filtering = FALSE; show_text = TRUE; searched = found = FALSE; for (i = 0; i < lbs->n_attr; i++) { /* check if attribute filter */ if (isparam(attr_list[i])) break; if (attr_flags[i] & (AF_DATE | AF_DATETIME)) { sprintf(str, "%da", i); if (retrieve_date(str, TRUE)) break; sprintf(str, "%db", i); if (retrieve_date(str, TRUE)) break; } if (attr_flags[i] & AF_MULTI) { for (j = 0; j < MAX_N_LIST && attr_options[i][j][0]; j++) { sprintf(str, "%s_%d", attr_list[i], j); if (isparam(str)) { filtering = TRUE; break; } } } if (attr_flags[i] & (AF_MUSERLIST | AF_MUSEREMAIL)) { for (j = 0; j < MAX_N_LIST; j++) { sprintf(str, "%s_%d", attr_list[i], j); if (isparam(str)) { filtering = TRUE; break; } } } /* check if sort by attribute */ if ((isparam("sort") && strieq(getparam("sort"), attr_list[i])) || (isparam("rsort") && strieq(getparam("rsort"), attr_list[i]))) break; } /* turn on filtering if found */ if (i < lbs->n_attr) filtering = TRUE; if (isparam("subtext")) filtering = TRUE; if (getcfg(lbs->name, "Sort Attributes", list, 10000)) filtering = TRUE; text = (char *) xmalloc(TEXT_SIZE); text1 = (char *) xmalloc(TEXT_SIZE); /* prepare for regex search */ memset(re_buf, 0, sizeof(re_buf)); /* compile regex for subtext */ if (isparam("subtext")) { strlcpy(str, getparam("subtext"), sizeof(str)); flags = REG_EXTENDED; if (!isparam("casesensitive")) flags |= REG_ICASE; status = regcomp(re_buf, str, flags); if (status) { sprintf(line, loc("Error in regular expression \"%s\""), str); strlcat(line, ": ", sizeof(line)); regerror(status, re_buf, str, sizeof(str)); strlcat(line, str, sizeof(line)); strencode2(str, line, sizeof(str)); show_error(str); return; } } /* compile regex for attributes */ for (i = 0; i < lbs->n_attr; i++) { if (isparam(attr_list[i])) { strlcpy(str, getparam(attr_list[i]), sizeof(str)); /* if value starts with '$', substitute it */ if (str[0] == '$') { j = build_subst_list(lbs, (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, attrib, TRUE); add_subst_time(lbs, (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, "entry time", date, &j, 0); strsubst_list(str, sizeof(str), (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, j); setparam(attr_list[i], str); } flags = REG_EXTENDED; if (!isparam("casesensitive")) flags |= REG_ICASE; status = regcomp(re_buf + i + 1, str, flags); if (status) { sprintf(line, loc("Error in regular expression \"%s\""), str); strlcat(line, ": ", sizeof(line)); regerror(status, re_buf + i + 1, str, sizeof(str)); strlcat(line, str, sizeof(line)); strencode2(str, line, sizeof(str)); show_error(str); return; } } } sort_item[0] = 0; if (isparam("sort")) strlcpy(sort_item, getparam("sort"), sizeof(sort_item)); if (isparam("rsort")) strlcpy(sort_item, getparam("rsort"), sizeof(sort_item)); sort_attributes = getcfg(lbs->name, "Sort Attributes", str, sizeof(str)); /* do filtering */ for (index = 0; index < n_msg; index++) { if (!msg_list[index].lbs) continue; /* retrieve message */ size = TEXT_SIZE; message_id = msg_list[index].lbs->el_index[msg_list[index].index].message_id; if (filtering) { status = el_retrieve(msg_list[index].lbs, message_id, date, attr_list, attrib, lbs->n_attr, text, &size, in_reply_to, reply_to, attachment, encoding, locked_by, draft); if (status != EL_SUCCESS) break; /* apply filter for attributes */ for (i = 0; i < lbs->n_attr; i++) { /* replace icon name with their comments if present */ if (attr_flags[i] & AF_ICON) { sprintf(str, "Icon comment %s", attrib[i]); if (getcfg(lbs->name, str, comment, sizeof(comment))) strlcpy(attrib[i], comment, NAME_LENGTH); } /* check for multi attributes */ if (attr_flags[i] & AF_MULTI) { /* OR of any of the values */ searched = found = FALSE; for (j = 0; j < MAX_N_LIST && attr_options[i][j][0]; j++) { sprintf(str, "%s_%d", attr_list[i], j); if (isparam(str)) { searched = TRUE; if (strstr(attrib[i], getparam(str))) { found = TRUE; break; } } } /* search for parameter without '_' coming from quick filter */ if (isparam(attr_list[i])) { searched = TRUE; strlcpy(str, getparam(attr_list[i]), sizeof(str)); if (str[0] == '^' && str[strlen(str) - 1] == '$') { str[strlen(str) - 1] = 0; strlcpy(comment, str + 1, NAME_LENGTH); } else strlcpy(comment, str, NAME_LENGTH); strlcpy(str, comment, sizeof(str)); if (strstr(attrib[i], str)) found = TRUE; } if (searched && !found) break; } /* check for multi user list or multi user email */ else if (attr_flags[i] & (AF_MUSERLIST | AF_MUSEREMAIL)) { /* OR of any of the values */ searched = found = FALSE; for (j = 0; j < MAX_N_LIST; j++) { sprintf(str, "%s_%d", attr_list[i], j); if (isparam(str)) { searched = TRUE; if (strstr(attrib[i], getparam(str))) { found = TRUE; break; } } } /* search for parameter without '_' coming from quick filter */ if (isparam(attr_list[i])) { searched = TRUE; if (strstr(attrib[i], getparam(attr_list[i]))) found = TRUE; } if (searched && !found) break; } else if (attr_flags[i] & (AF_DATE | AF_DATETIME)) { /* check for last[i]/next[i] */ ltime = isparam(attr_list[i]) ? atoi(getparam(attr_list[i])) : 0; /* today 12h noon */ time(&now); memcpy(&tms, localtime(&now), sizeof(struct tm)); tms.tm_hour = 12; tms.tm_min = 0; tms.tm_sec = 0; now = mktime(&tms); /* negative i: last [i] days */ if (ltime < 0) if (atoi(attrib[i]) < now + ltime * 3600 * 24 - 3600 * 12 || atoi(attrib[i]) > now) break; /* positive i: next [i] days */ if (ltime > 0) if (atoi(attrib[i]) > now + ltime * 3600 * 24 + 3600 * 12 || atoi(attrib[i]) < now) break; /* check for start date / end date */ sprintf(str, "%da", i); ltime = retrieve_date(str, TRUE); if (ltime > 0 && atoi(attrib[i]) < ltime) break; sprintf(str, "%db", i); ltime = retrieve_date(str, FALSE); if (ltime > 0 && (atoi(attrib[i]) > ltime || atoi(attrib[i]) == 0)) break; } else { strlcpy(str, isparam(attr_list[i]) ? getparam(attr_list[i]) : "", sizeof(str)); /* if value starts with '$', substitute it */ if (str[0] == '$') { j = build_subst_list(lbs, (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, attrib, TRUE); sprintf(mid, "%d", message_id); add_subst_list((char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, "message id", mid, &j); add_subst_time(lbs, (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, "entry time", date, &j, 0); strsubst_list(str, sizeof(str), (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, j); setparam(attr_list[i], str); } if (isparam(attr_list[i])) { status = regexec(re_buf + 1 + i, attrib[i], 10, pmatch, 0); if (status == REG_NOMATCH) break; } } } if (i < lbs->n_attr) { msg_list[index].lbs = NULL; continue; } if (isparam("subtext")) { status = regexec(re_buf, text, 10, pmatch, 0); if (isparam("sall") && atoi(getparam("sall")) && status == REG_NOMATCH) { // search text in attributes for (i = 0; i < lbs->n_attr; i++) { status = regexec(re_buf, attrib[i], 10, pmatch, 0); if (status != REG_NOMATCH) break; } if (i == lbs->n_attr) { msg_list[index].lbs = NULL; continue; } } else if (status == REG_NOMATCH) { msg_list[index].lbs = NULL; continue; } } } // if (filtering) /* evaluate "sort attributes" */ if (sort_attributes) { getcfg(lbs->name, "Sort Attributes", list, 10000); msg_list[index].string[0] = 0; n = strbreak(list, sort_attr, MAX_N_ATTR, ",", FALSE); for (i = 0; i < n; i++) { for (j = 0; j < lbs->n_attr; j++) { if (strieq(sort_attr[i], attr_list[j])) { strlcat(msg_list[index].string, " ", sizeof(msg_list[index].string)); strlcat(msg_list[index].string, attrib[j], sizeof(msg_list[index].string)); if (attr_flags[i] & (AF_NUMERIC | AF_DATETIME | AF_DATE)) { msg_list[index].number = atoi(attrib[j]); numeric = TRUE; } else numeric = FALSE; break; } } if (strieq(sort_attr[i], loc("ID"))) { strlcat(msg_list[index].string, " ", sizeof(msg_list[index].string)); sprintf(str, "%08d", message_id); strlcat(msg_list[index].string, str, sizeof(msg_list[index].string)); } else if (strieq(sort_attr[i], loc("Logbook"))) { strlcat(msg_list[index].string, " ", sizeof(msg_list[index].string)); strlcat(msg_list[index].string, msg_list[index].lbs->name, sizeof(msg_list[index].string)); } else if (strieq(sort_attr[i], loc("Date"))) { strlcat(msg_list[index].string, " ", sizeof(msg_list[index].string)); entry_ltime = date_to_ltime(date); sprintf(str, "%08d", (int) entry_ltime); strlcat(msg_list[index].string, str, sizeof(msg_list[index].string)); } } } /* add attribute for sorting */ if (sort_item[0]) { for (i = 0; i < lbs->n_attr; i++) { if (strieq(sort_item, attr_list[i])) { if (attr_flags[i] & (AF_NUMERIC | AF_DATETIME | AF_DATE)) { numeric = TRUE; msg_list[index].number = atoi(attrib[i]); } else { numeric = FALSE; strlcpy(msg_list[index].string, attrib[i], 256); } } if (strieq(sort_item, loc("ID"))) { numeric = TRUE; msg_list[index].number = message_id; } if (strieq(sort_item, loc("Logbook"))) strlcpy(msg_list[index].string, msg_list[index].lbs->name, 256); } if (isparam("rsort")) reverse = 1; if (isparam("sort")) reverse = 0; } } /*---- in threaded mode, set date of latest entry of thread ----*/ if (threaded && !filtering && !date_filtering) { for (index = 0; index < n_msg; index++) { if (!msg_list[index].lbs) continue; message_id = msg_list[index].lbs->el_index[msg_list[index].index].message_id; in_reply_to_id = msg_list[index].lbs->el_index[msg_list[index].index].in_reply_to; if (!in_reply_to_id) continue; do { message_id = in_reply_to_id; /* search index of message */ for (i = 0; i < *msg_list[index].lbs->n_el_index; i++) if (msg_list[index].lbs->el_index[i].message_id == message_id) break; /* stop if not found */ if (i == *msg_list[index].lbs->n_el_index) break; in_reply_to_id = msg_list[index].lbs->el_index[i].in_reply_to; } while (in_reply_to_id); /* if head not found, skip message */ if (i == *msg_list[index].lbs->n_el_index) { msg_list[index].lbs = NULL; continue; } /* set new page message ID with head message */ if (page_mid && msg_list[index].lbs->el_index[msg_list[index].index].message_id == page_mid) page_mid_head = message_id; /* search message head in list */ for (j = 0; j < n_msg; j++) if (msg_list[j].lbs == msg_list[index].lbs && msg_list[j].index == i) break; if (j < index) { /* set date from current message, if later */ if (msg_list[j].number < msg_list[index].number) msg_list[j].number = msg_list[index].number; } /* now delete current message, to leave only heads in list */ msg_list[index].lbs = NULL; } } /*---- compact messasges ----*/ for (i = j = 0; i < n_msg; i++) if (msg_list[i].lbs) memcpy(&msg_list[j++], &msg_list[i], sizeof(MSG_LIST)); n_msg = j; /*---- sort messasges ----*/ if (numeric) qsort(msg_list, n_msg, sizeof(MSG_LIST), reverse ? msg_compare_reverse_numeric : msg_compare_numeric); else qsort(msg_list, n_msg, sizeof(MSG_LIST), reverse ? msg_compare_reverse : msg_compare); /*---- search page for specific message ----*/ if (getcfg(lbs->name, "Entries per page", str, sizeof(str))) n_page = atoi(str); else n_page = 20; if (isparam("npp")) { n_page = atoi(getparam("npp")); if (n_page < 1) n_page = 1; if (n_page > 100000) n_page = 100000; } if (page_mid) { default_page = 0; for (i = 0; i < n_msg; i++) if (msg_list[i].lbs->el_index[msg_list[i].index].message_id == page_mid || msg_list[i].lbs->el_index[msg_list[i].index].message_id == page_mid_head) break; if (i < n_msg) page_n = i / n_page + 1; } /*---- number of messages per page ----*/ n_attr_disp = n_line = 0; i_start = 0; i_stop = n_msg - 1; if (!csv && !xml && !raw) { if (page_n || default_page) { if (default_page && page_n != -1) page_n = reverse ? 1 : (n_msg - 1) / n_page + 1; if (page_n != -1) { i_start = (page_n - 1) * n_page; i_stop = i_start + n_page - 1; if (i_start >= n_msg && n_msg > 0) { page_n = 1; i_start = 0; } if (i_stop >= n_msg) i_stop = n_msg - 1; } } } /*---- header ----*/ if (getcfg(lbs->name, "List Page Title", str, sizeof(str))) { i = build_subst_list(lbs, (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, NULL, TRUE); strsubst_list(str, sizeof(str), (char (*)[NAME_LENGTH]) slist, (char (*)[NAME_LENGTH]) svalue, i); strip_html(str); } else sprintf(str, "ELOG %s", lbs->name); if (csv) { /* no menus and tables */ show_plain_header(0, "export.csv"); rsprintf("\"%s\"", loc("Message ID")); if (strieq(mode, "CSV1")) rsprintf(","); else rsprintf(";"); rsprintf("\"%s\"", loc("Date")); if (strieq(mode, "CSV1")) rsprintf(","); else rsprintf(";"); for (i = 0; i < lbs->n_attr; i++) { strlcpy(str, attr_list[i], sizeof(str)); if (str[0]) { rsputs("\""); pt1 = str; while ((pt2 = strchr(pt1, '"')) != NULL) { *pt2 = 0; rsputs(pt1); rsputs("\"\""); pt1 = pt2 + 1; } rsputs(pt1); rsputs("\""); } if (i < lbs->n_attr - 1) { if (strieq(mode, "CSV1")) rsprintf(","); else rsprintf(";"); } else { if (strieq(mode, "CSV3")) rsprintf(";\"Text\""); rsprintf("\r\n"); } } } else if (xml) { /* no menus and tables */ show_plain_header(0, "export.xml"); if (!getcfg("global", "charset", charset, sizeof(charset))) strcpy(charset, DEFAULT_HTTP_CHARSET); rsprintf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", charset); rsprintf("<!-- ELOGD Version %s export.xml -->\n", VERSION); rsprintf("<ELOG_LIST>\n"); } else if (raw) { /* no menus and tables */ show_plain_header(0, "export.txt"); } else { if (getcfg(lbs->name, "Refresh", refr, sizeof(refr))) refresh = atoi(refr); else refresh = 0; show_standard_header(lbs, TRUE, str, NULL, TRUE, mode_cookie, NULL, refresh); /*---- title ----*/ strlcpy(str, ", ", sizeof(str)); if (past_n == 1) strcat(str, loc("Last day")); else if (past_n > 1) sprintf(str + strlen(str), loc("Last %d days"), past_n); else if (past_n < 0) sprintf(str + strlen(str), loc("Last %d hours"), -past_n); else if (last_n) sprintf(str + strlen(str), loc("Last %d entries"), last_n); else if (page_n == -1) strlcpy(str + strlen(str), loc("all entries"), sizeof(str) - strlen(str)); else if (page_n) sprintf(str + strlen(str), loc("Page %d of %d"), page_n, (n_msg - 1) / n_page + 1); if (strlen(str) == 2) str[0] = 0; if (printable) show_standard_title(lbs, str, 1); else show_standard_title(lbs, str, 0); /*---- menu buttons ----*/ if (!printable) { rsprintf("<tr><td class=\"menuframe\"><span class=\"menu1\">\n"); /* current command line for select command */ strlcpy(str, isparam("cmdline") ? getparam("cmdline") : "", sizeof(str)); /* remove select switch */ if (strstr(str, "select=1")) { *strstr(str, "select=1") = 0; if (strlen(str) > 1 && (str[strlen(str) - 1] == '&' || str[strlen(str) - 1] == '?')) str[strlen(str) - 1] = 0; } /* store current command line as hidden parameter for page navigation */ if (str[0] && !strieq(str, "?")) { rsprintf("<input type=hidden name=lastcmd value=\""); rsputs3(str); rsprintf("\">\n", str); } if (!getcfg(lbs->name, "Guest Find menu commands", menu_str, sizeof(menu_str)) || logged_in(lbs)) getcfg(lbs->name, "Find menu commands", menu_str, sizeof(menu_str)); if (!menu_str[0]) { if (!getcfg(lbs->name, "Guest list menu commands", menu_str, sizeof(menu_str)) || logged_in(lbs)) getcfg(lbs->name, "list menu commands", menu_str, sizeof(menu_str)); } /* default menu commands */ if (menu_str[0] == 0) { strlcpy(menu_str, "New, Find, Select, Import, ", sizeof(menu_str)); if (getcfg(lbs->name, "Password file", str, sizeof(str))) strlcat(menu_str, "Config, Logout, ", sizeof(menu_str)); else strlcat(menu_str, "Config, ", sizeof(menu_str)); if (getcfg(lbs->name, "Mirror server", str, sizeof(str))) strlcat(menu_str, "Synchronize, ", sizeof(menu_str)); strlcpy(str, loc("Last x"), sizeof(str)); strlcat(menu_str, "Last x, Help, ", sizeof(menu_str)); } n = strbreak(menu_str, menu_item, MAX_N_LIST, ",", FALSE); for (i = 0; i < n; i++) { if (is_user_allowed(lbs, menu_item[i])) { if (strieq(menu_item[i], "Last x")) { if (past_n > 0) { sprintf(str, loc("Last %d days"), past_n * 2); rsprintf("&nbsp;<a href=\"past%d?mode=%s\">%s</a>&nbsp;|\n", past_n * 2, mode, str); } else { strlcpy(str, loc("Last day"), sizeof(str)); rsprintf("&nbsp;<a href=\"past1?mode=%s\">%s</a>&nbsp;|\n", mode, str); } if (last_n) { sprintf(str, loc("Last %d entries"), last_n * 2); rsprintf("&nbsp;<a href=\"last%d?mode=%s\">%s</a>&nbsp;|\n", last_n * 2, mode, str); } } else if (strieq(menu_item[i], "Select")) { strlcpy(str, getparam("cmdline"), sizeof(str)); if (isparam("select") && atoi(getparam("select")) == 1) { /* remove select switch */ if (strstr(str, "select=1")) { *strstr(str, "select=1") = 0; if (strlen(str) > 1 && (str[strlen(str) - 1] == '&' || str[strlen(str) - 1] == '?')) str[strlen(str) - 1] = 0; } } else { /* add select switch */ if (strchr(str, '?')) strcat(str, "&select=1"); else strcat(str, "?select=1"); } rsprintf("&nbsp;<a href=\""); rsputs3(str); rsprintf("\">%s</a>&nbsp;|\n", loc("Select")); } else { strlcpy(str, loc(menu_item[i]), sizeof(str)); url_encode(str, sizeof(str)); if (i < n - 1) rsprintf("&nbsp;<a href=\"?cmd=%s\">%s</a>&nbsp;|\n", str, loc(menu_item[i])); else rsprintf("&nbsp;<a href=\"?cmd=%s\">%s</a>&nbsp;\n", str, loc(menu_item[i])); } } } rsprintf("</span></td></tr>\n\n"); } /*---- list menu text ----*/ if ((getcfg(lbs->name, "find menu text", str, sizeof(str)) || getcfg(lbs->name, "list menu text", str, sizeof(str))) && !printable) { FILE *f; char file_name[256], *buf; rsprintf("<tr><td class=\"menuframe\"><span class=\"menu1\">\n"); /* check if file starts with an absolute directory */ if (str[0] == DIR_SEPARATOR || str[1] == ':') strlcpy(file_name, str, sizeof(file_name)); else { strlcpy(file_name, logbook_dir, sizeof(file_name)); strlcat(file_name, str, sizeof(file_name)); } f = fopen(file_name, "rb"); if (f != NULL) { fseek(f, 0, SEEK_END); size = TELL(fileno(f)); fseek(f, 0, SEEK_SET); buf = (char *) xmalloc(size + 1); fread(buf, 1, size, f); buf[size] = 0; fclose(f); rsputs(buf); } else rsprintf("<center><b>Error: file <i>\"%s\"</i> not found</b></center>", file_name); rsprintf("</span></td></tr>"); } /*---- display filters ----*/ disp_filter = isparam("ma") || isparam("ya") || isparam("da") || isparam("mb") || isparam("yb") || isparam("db") || isparam("subtext") || isparam("last"); for (i = 0; i < lbs->n_attr; i++) if (isparam(attr_list[i]) && (attr_flags[i] & (AF_DATE | AF_DATETIME)) == 0) disp_filter = TRUE; for (i = 0; i < lbs->n_attr; i++) { if (attr_flags[i] & (AF_DATE | AF_DATETIME)) { sprintf(str, "%da", i); ltime = retrieve_date(str, TRUE); if (ltime > 0) disp_filter = TRUE; sprintf(str, "%db", i); ltime = retrieve_date(str, FALSE); if (ltime > 0) disp_filter = TRUE; } if (attr_flags[i] & (AF_MULTI | AF_MUSERLIST | AF_MUSEREMAIL)) { for (j = 0; j < MAX_N_LIST; j++) { sprintf(str, "%s_%d", attr_list[i], j); if (isparam(str)) disp_filter = TRUE; if (isparam(attr_list[i])) disp_filter = TRUE; } } } if (isparam("new_entries") && atoi(getparam("new_entries")) == 1) { rsprintf("<tr><td class=\"listframe\">\n"); rsprintf("<table width=\"100%%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n"); rsprintf("<tr><td nowrap width=\"10%%\" class=\"attribname\">%s:</td>", loc("New entries since")); memcpy(&tms, localtime(&ltime_start), sizeof(struct tm)); my_strftime(str, sizeof(str), "%c", &tms); rsprintf("<td class=\"attribvalue\">%s</td></tr>", str); rsprintf("</table></td></tr>\n\n"); } if (disp_filter) { rsprintf("<tr><td class=\"listframe\">\n"); rsprintf("<table width=\"100%%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n"); if (isparam("last")) { rsprintf("<tr><td nowrap width=\"10%%\" class=\"attribname\">%s:</td>", loc("Restrict search to last")); strencode2(str, getparam("last"), sizeof(str)); rsprintf("<td class=\"attribvalue\">%s %s</td></tr>", str, loc("days")); } if (isparam("ma") || isparam("ya") || isparam("da") || isparam("ha") || isparam("na") || isparam("ca")) { memset(&tms, 0, sizeof(struct tm)); tms.tm_year = y1 - 1900; tms.tm_mon = m1 - 1; tms.tm_mday = d1; tms.tm_hour = h1; tms.tm_min = n1; tms.tm_sec = c1; if (tms.tm_year < 90) tms.tm_year += 100; mktime(&tms); if (!getcfg(lbs->name, "Time format", format, sizeof(format))) strcpy(format, DEFAULT_TIME_FORMAT); strftime(str, sizeof(str), format, &tms); rsprintf("<tr><td nowrap width=\"10%%\" class=\"attribname\">%s:</td>", loc("Start date")); rsprintf("<td class=\"attribvalue\">%s</td></tr>", str); } if (isparam("mb") || isparam("yb") || isparam("db") || isparam("hb") || isparam("nb") || isparam("cb")) { memset(&tms, 0, sizeof(struct tm)); tms.tm_year = y2 - 1900; tms.tm_mon = m2 - 1; tms.tm_mday = d2; tms.tm_hour = h2; tms.tm_min = n2; tms.tm_sec = c2; if (tms.tm_year < 90) tms.tm_year += 100; ltime = mktime(&tms); memcpy(&tms, localtime(&ltime), sizeof(struct tm)); if (!getcfg(lbs->name, "Time format", format, sizeof(format))) strcpy(format, DEFAULT_TIME_FORMAT); strftime(str, sizeof(str), format, &tms); rsprintf("<tr><td nowrap width=\"10%%\" class=\"attribname\">%s:</td>", loc("End date")); rsprintf("<td class=\"attribvalue\">%s</td></tr>", str); } for (i = 0; i < lbs->n_attr; i++) { if (attr_flags[i] & (AF_DATE | AF_DATETIME)) { sprintf(str, "%da", i); ltime1 = retrieve_date(str, TRUE); sprintf(str, "%db", i); ltime2 = retrieve_date(str, TRUE); if (ltime1 > 0 || ltime2 > 0) { rsprintf("<tr><td nowrap width=\"10%%\" class=\"attribname\">%s:</td>", attr_list[i]); rsprintf("<td class=\"attribvalue\">"); if (ltime1) { memcpy(&tms, localtime(&ltime1), sizeof(struct tm)); if (attr_flags[i] & AF_DATE) strcpy(format, DEFAULT_DATE_FORMAT); else strcpy(format, DEFAULT_TIME_FORMAT); my_strftime(str, sizeof(str), format, &tms); if (ltime2 > 0) rsprintf("%s %s", loc("From"), str); else rsprintf("%s %s", loc("After"), str); } if (ltime2) { memcpy(&tms, localtime(&ltime2), sizeof(struct tm)); if (attr_flags[i] & AF_DATE) strcpy(format, DEFAULT_DATE_FORMAT); else strcpy(format, DEFAULT_TIME_FORMAT); my_strftime(str, sizeof(str), format, &tms); if (ltime1 > 0) rsprintf(" %s %s", loc("to"), str); else rsprintf("%s %s", loc("Before"), str); } rsprintf("</td></tr>", comment); } } else if (attr_flags[i] & AF_MULTI) { line[0] = 0; for (j = 0; j < MAX_N_LIST && attr_options[i][j][0]; j++) { sprintf(iattr, "%s_%d", attr_list[i], j); if (isparam(iattr)) { comment[0] = 0; if (attr_flags[i] & AF_ICON) { sprintf(str, "Icon comment %s", getparam(iattr)); getcfg(lbs->name, str, comment, sizeof(comment)); } if (line[0]) strlcat(line, " | ", sizeof(line)); if (comment[0] == 0) { strlcpy(str, getparam(iattr), sizeof(str)); if (str[0] == '^' && str[strlen(str) - 1] == '$') { str[strlen(str) - 1] = 0; strlcpy(comment, str + 1, NAME_LENGTH); } else strlcpy(comment, str, NAME_LENGTH); strlcpy(str, comment, sizeof(str)); strencode2(line + strlen(line), str, sizeof(line) - strlen(line)); } else strlcat(line, comment, sizeof(line)); } } if (isparam(attr_list[i])) { comment[0] = 0; if (attr_flags[i] & AF_ICON) { sprintf(str, "Icon comment %s", getparam(attr_list[i])); getcfg(lbs->name, str, comment, sizeof(comment)); } if (line[0]) strlcat(line, " | ", sizeof(line)); if (comment[0] == 0) { strlcpy(str, getparam(attr_list[i]), sizeof(str)); if (str[0] == '^' && str[strlen(str) - 1] == '$') { str[strlen(str) - 1] = 0; strlcpy(comment, str + 1, NAME_LENGTH); } else strlcpy(comment, str, NAME_LENGTH); strlcpy(str, comment, sizeof(str)); strencode2(line + strlen(line), str, sizeof(line) - strlen(line)); } else strlcat(line, comment, sizeof(line)); } if (line[0]) { rsprintf("<tr><td nowrap width=\"10%%\" class=\"attribname\">%s:</td>", attr_list[i]); rsprintf("<td class=\"attribvalue\"><span style=\"color:black;background-color:#ffff66\">"); rsprintf("%s</span></td></tr>", line); } } else if (attr_flags[i] & (AF_MUSERLIST | AF_MUSEREMAIL)) { line[0] = 0; for (j = 0; j < MAX_N_LIST; j++) { sprintf(iattr, "%s_%d", attr_list[i], j); if (isparam(iattr)) { if (line[0]) strlcat(line, " | ", sizeof(line)); strlcat(line, getparam(iattr), sizeof(line)); } } if (isparam(attr_list[i])) { if (line[0]) strlcat(line, " | ", sizeof(line)); strencode2(line + strlen(line), getparam(attr_list[i]), sizeof(line) - strlen(line)); } if (line[0]) { rsprintf("<tr><td nowrap width=\"10%%\" class=\"attribname\">%s:</td>", attr_list[i]); rsprintf("<td class=\"attribvalue\"><span style=\"color:black;background-color:#ffff66\">"); rsprintf("%s</span></td></tr>", line); } } else if (isparam(attr_list[i])) { strlcpy(str, getparam(attr_list[i]), sizeof(str)); if (str[0] && !strieq(str, "_all_") && strncmp(str, "--", 2) != 0) { comment[0] = 0; if (attr_flags[i] & AF_ICON) { sprintf(str, "Icon comment %s", getparam(attr_list[i])); getcfg(lbs->name, str, comment, sizeof(comment)); } if (comment[0] == 0) { strlcpy(str, getparam(attr_list[i]), sizeof(str)); if (str[0] == '^' && str[strlen(str) - 1] == '$') { str[strlen(str) - 1] = 0; strlcpy(comment, str + 1, NAME_LENGTH); } else strlcpy(comment, str, NAME_LENGTH); strlcpy(str, comment, sizeof(str)); strencode2(comment, str, sizeof(comment)); } rsprintf("<tr><td nowrap width=\"10%%\" class=\"attribname\">%s:</td>", attr_list[i]); rsprintf("<td class=\"attribvalue\"><span style=\"color:black;background-color:#ffff66\">"); rsprintf("%s</span></td></tr>", comment); } } } if (isparam("subtext")) { rsprintf("<tr><td nowrap width=\"10%%\" class=\"attribname\">%s:</td>", loc("Text")); rsprintf("<td class=\"attribvalue\"><span style=\"color:black;background-color:#ffff66\">"); strencode2(str, getparam("subtext"), sizeof(str)); rsprintf("%s</span></td></tr>", str); } rsprintf("</table></td></tr>\n\n"); } /* get number of summary lines */ n_line = 3; if (getcfg(lbs->name, "Summary lines", str, sizeof(str))) n_line = atoi(str); /* suppress summary completely if text body is disabled */ if (getcfg(lbs->name, "Show text", str, sizeof(str)) && atoi(str) == 0) n_line = 0; /* suppress attachment colum if switched off */ show_att_column = strieq(mode, "Summary"); if (getcfg(lbs->name, "Enable attachments", str, sizeof(str)) && atoi(str) == 0) show_att_column = FALSE; /* get mode commands flag */ mode_commands = TRUE; if (getcfg(lbs->name, "Mode commands", str, sizeof(str)) && atoi(str) == 0) mode_commands = FALSE; /*---- evaluate conditions for quick filters */ for (i = 0; i < lbs->n_attr; i++) { attrib[i][0] = 0; if (isparam(attr_list[i])) { strlcpy(str, getparam(attr_list[i]), sizeof(str)); if (str[0] == '^' && str[strlen(str) - 1] == '$') { str[strlen(str) - 1] = 0; strlcpy(attrib[i], str + 1, NAME_LENGTH); } else strlcpy(attrib[i], str, NAME_LENGTH); } } evaluate_conditions(lbs, attrib); /*---- notification message ----*/ if (info && info[0]) { rsprintf("<tr><td class=\"notifyleft\">%s</td></tr>\n", info); } /*---- page navigation ----*/ if (!printable) { show_page_filters(lbs, n_msg, page_n, mode_commands, mode); show_page_navigation(lbs, n_msg, page_n, n_page); } /*---- select navigation ----*/ if (isparam("select") && atoi(getparam("select")) == 1) show_select_navigation(lbs); /*---- table titles ----*/ /* overall listing table */ rsprintf("<tr><td><table class=\"listframe\" width=\"100%%\" cellspacing=0>\n"); size = printable ? 2 : 3; show_text = TRUE; text_in_attr = FALSE; list[0] = 0; getcfg(lbs->name, "List display", list, 10000); /* evaluate Guest display list */ if (getcfg(lbs->name, "Password file", str, sizeof(str)) && getcfg(lbs->name, "Guest list display", str, sizeof(str)) && !isparam("unm")) { strcpy(list, str); n = strbreak(list, (char (*)[NAME_LENGTH]) gattr, MAX_N_ATTR, ",", FALSE); for (j = 0; j < n; j++) if (strieq(gattr + j * NAME_LENGTH, "text")) break; if (n > 0 && j == n) show_text = FALSE; else text_in_attr = TRUE; } memset(disp_attr_flags, 0, sizeof(disp_attr_flags)); if (list[0]) { n_attr_disp = strbreak(list, disp_attr, MAX_N_ATTR, ",", FALSE); /* if text is in guest display list, adjust number of *real* attributes */ if (text_in_attr) n_attr_disp--; if (search_all) { for (i = n_attr_disp - 1; i >= 0; i--) strcpy(disp_attr[i + 1], disp_attr[i]); strcpy(disp_attr[0], loc("Logbook")); n_attr_disp++; } } else { if (search_all) { n_attr_disp = lbs->n_attr + 3; strcpy(disp_attr[0], loc("Logbook")); strcpy(disp_attr[1], loc("ID")); strcpy(disp_attr[2], loc("Date")); memcpy(disp_attr + 3, attr_list, sizeof(attr_list)); memcpy(disp_attr_flags + 3, attr_flags, sizeof(attr_flags)); } else { n_attr_disp = lbs->n_attr + 2; strcpy(disp_attr[0], loc("ID")); strcpy(disp_attr[1], loc("Date")); memcpy(disp_attr + 2, attr_list, sizeof(attr_list)); memcpy(disp_attr_flags + 2, attr_flags, sizeof(attr_flags)); } } list[0] = 0; getcfg(lbs->name, "Link display", list, 10000); if (list[0]) { n = strbreak(list, (char (*)[NAME_LENGTH]) gattr, MAX_N_ATTR, ",", FALSE); for (i = 0; i < n_attr_disp; i++) { for (j = 0; j < n; j++) if (strieq(gattr + j * NAME_LENGTH, disp_attr[i])) break; if (j < n) disp_attr_link[i] = TRUE; else disp_attr_link[i] = FALSE; } } else for (i = 0; i < n_attr_disp; i++) disp_attr_link[i] = TRUE; if (threaded) { } else { rsprintf("<tr>\n"); /* empty title for selection box */ if (isparam("select") && atoi(getparam("select")) == 1) rsprintf("<th class=\"listtitle\">&nbsp;</th>\n"); for (i = 0; i < n_attr_disp; i++) { /* assemble current command line, replace sort statements */ strlcpy(ref, getparam("cmdline"), sizeof(ref)); strlcpy(str, disp_attr[i], sizeof(str)); url_encode(str, sizeof(str)); if (isparam("sort") && strcmp(getparam("sort"), disp_attr[i]) == 0) { subst_param(ref, sizeof(ref), "sort", ""); subst_param(ref, sizeof(ref), "rsort", str); } else { if (ref[0] == 0) { if (getcfg(lbs->name, "Reverse sort", str2, sizeof(str2)) && atoi(str2) == 1) sprintf(ref, "?rsort=%s", str); else sprintf(ref, "?sort=%s", str); } else { subst_param(ref, sizeof(ref), "rsort", ""); subst_param(ref, sizeof(ref), "sort", str); } } img[0] = 0; if (isparam("sort") && strcmp(getparam("sort"), disp_attr[i]) == 0) sprintf(img, "<img align=top src=\"up.png\" alt=\"%s\" title=\"%s\">", loc("up"), loc("up")); else if (isparam("rsort") && strcmp(getparam("rsort"), disp_attr[i]) == 0) sprintf(img, "<img align=top src=\"down.png\" alt=\"%s\" title=\"%s\">", loc("down"), loc("down")); sprintf(str, "Tooltip %s", disp_attr[i]); if (getcfg(lbs->name, str, comment, sizeof(comment))) sprintf(str, "title=\"%s\"", comment); else str[0] = 0; if (strieq(disp_attr[i], "Edit") || strieq(disp_attr[i], "Delete")) rsprintf("<th %s class=\"listtitle\">%s</th>\n", str, disp_attr[i]); else { rsprintf("<th %s class=\"listtitle\"><a href=\"", str); rsputs3(ref); rsprintf("\">%s</a>%s</th>\n", disp_attr[i], img); } } if (!strieq(mode, "Full") && n_line > 0 && show_text) rsprintf("<th class=\"listtitle2\">%s</th>\n", loc("Text")); if (show_att_column) rsprintf("<th class=\"listtitle3\"><img src=\"attachment.png\" alt=\"%s\" title=\"%s\"</th>", loc("Attachments"), loc("Attachments")); rsprintf("</tr>\n\n"); } } /* if (!csv && !xml) */ /*---- display message list ----*/ for (index = i_start; index <= i_stop; index++) { size = TEXT_SIZE; message_id = msg_list[index].lbs->el_index[msg_list[index].index].message_id; status = el_retrieve(msg_list[index].lbs, message_id, date, attr_list, attrib, lbs->n_attr, text, &size, in_reply_to, reply_to, attachment, encoding, locked_by, draft); if (status != EL_SUCCESS) break; /* skip drafts */ if (getcfg(lbs->name, "List drafts", str, sizeof(str)) && atoi(str) == 0) if (draft[0]) continue; if (csv) { rsprintf("%d", message_id); if (strieq(mode, "CSV1")) rsprintf(","); else rsprintf(";"); strlcpy(str, date, sizeof(str)); while (strchr(str, ',')) *strchr(str, ',') = ' '; rsprintf(str); if (strieq(mode, "CSV1")) rsprintf(","); else rsprintf(";"); for (i = 0; i < lbs->n_attr; i++) { strlcpy(str, attrib[i], sizeof(str)); if (str[0]) { if (attr_flags[i] & AF_DATE) { sprintf(str, "Date format %s", attr_list[i]); if (!getcfg(lbs->name, str, format, sizeof(format))) if (!getcfg(lbs->name, "Date format", format, sizeof(format))) strcpy(format, DEFAULT_DATE_FORMAT); ltime = atoi(attrib[i]); ptms = localtime(&ltime); assert(ptms); if (ltime == 0) strcpy(str, "-"); else my_strftime(str, sizeof(str), format, ptms); } else if (attr_flags[i] & AF_DATETIME) { sprintf(str, "Time format %s", attr_list[i]); if (!getcfg(lbs->name, str, format, sizeof(format))) if (!getcfg(lbs->name, "Time format", format, sizeof(format))) strcpy(format, DEFAULT_TIME_FORMAT); ltime = atoi(attrib[i]); ptms = localtime(&ltime); assert(ptms); if (ltime == 0) strcpy(str, "-"); else my_strftime(str, sizeof(str), format, ptms); } rsputs("\""); pt1 = str; while ((pt2 = strchr(pt1, '"')) != NULL) { *pt2 = 0; rsputs(pt1); rsputs("\"\""); pt1 = pt2 + 1; } rsputs(pt1); rsputs("\""); } if (i < lbs->n_attr - 1) { if (strieq(mode, "CSV1")) rsprintf(","); else rsprintf(";"); } else { if (strlen(text) > 0 && strieq(mode, "CSV3")) { rsprintf(";"); strlcpy(str, text, sizeof(str)); rsputs("\""); pt1 = str; while ((pt2 = strchr(pt1, '"')) != NULL) { *pt2 = 0; rsputs(pt1); rsputs("\"\""); pt1 = pt2 + 1; } rsputs(pt1); rsputs("\""); } rsprintf("\r\n"); } } } else if (xml) { rsputs("\t<ENTRY>\n"); rsprintf("\t\t<MID>%d</MID>\n", message_id); rsprintf("\t\t<DATE>%s</DATE>\n", date); if (in_reply_to[0]) rsprintf("\t\t<IN_REPLY_TO>%s</IN_REPLY_TO>\n", in_reply_to); if (reply_to[0]) rsprintf("\t\t<REPLY_TO>%s</REPLY_TO>\n", reply_to); if (attachment[0][0]) { rsprintf("\t\t<ATTACHMENT>"); rsprintf(attachment[0]); for (i = 1; i < MAX_ATTACHMENTS; i++) if (attachment[i][0]) rsprintf(",%s", attachment[i]); rsprintf("</ATTACHMENT>\n", attachment); } rsprintf("\t\t<ENCODING>%s</ENCODING>\n", encoding); for (i = 0; i < lbs->n_attr; i++) { strcpy(iattr, attr_list[i]); for (j = 0; j < (int) strlen(iattr); j++) /* replace special characters with "_", exclude any UTF-8 */ if (!isalnum(iattr[j]) && ((unsigned char) iattr[j] < 128)) iattr[j] = '_'; rsprintf("\t\t<%s>", iattr); strlcpy(str, attrib[i], sizeof(str)); if (attr_flags[i] & AF_DATE) { sprintf(str, "Date format %s", attr_list[i]); if (!getcfg(lbs->name, str, format, sizeof(format))) if (!getcfg(lbs->name, "Date format", format, sizeof(format))) strcpy(format, DEFAULT_DATE_FORMAT); ltime = atoi(attrib[i]); ptms = localtime(&ltime); assert(ptms); if (ltime == 0) strcpy(str, "-"); else my_strftime(str, sizeof(str), format, ptms); sprintf(str + strlen(str), " [%ld]", (long)ltime); } else if (attr_flags[i] & AF_DATETIME) { sprintf(str, "Time format %s", attr_list[i]); if (!getcfg(lbs->name, str, format, sizeof(format))) if (!getcfg(lbs->name, "Time format", format, sizeof(format))) strcpy(format, DEFAULT_TIME_FORMAT); ltime = atoi(attrib[i]); ptms = localtime(&ltime); assert(ptms); if (ltime == 0) strcpy(str, "-"); else my_strftime(str, sizeof(str), format, ptms); sprintf(str + strlen(str), " [%ld]", (long)ltime); } xmlencode(str); rsprintf("</%s>\n", iattr); } rsputs("\t\t<TEXT>"); xmlencode(text); rsputs("</TEXT>\n"); rsputs("\t</ENTRY>\n"); } else if (raw) { rsprintf("$@MID@$: %d\r\n", message_id); rsprintf("Date: %s\r\n", date); if (reply_to[0]) rsprintf("Reply to: %s\r\n", reply_to); if (in_reply_to[0]) rsprintf("In reply to: %s\r\n", in_reply_to); for (i = 0; i < lbs->n_attr; i++) rsprintf("%s: %s\r\n", attr_list[i], attrib[i]); rsprintf("Attachment: "); if (attachment[0][0]) { rsprintf("%s", attachment[0]); for (i = 1; i < MAX_ATTACHMENTS; i++) if (attachment[i][0]) rsprintf(",%s", attachment[i]); } rsprintf("\r\n"); rsprintf("Encoding: %s\r\n", encoding); if (locked_by[0]) rsprintf("Locked by: %s\r\n", locked_by); rsprintf("========================================\r\n"); rsputs(text); rsputs("\r\n"); } else { /*---- add highlighting for searched subtext ----*/ if (isparam("subtext")) { highlight_searchtext(re_buf, text, text1, strieq(encoding, "plain") || strieq(encoding, "ELCode") || !strieq(mode, "Full")); strlcpy(text, text1, TEXT_SIZE); } /*---- display line ----*/ expand = 1; if (threaded) { if (getcfg(lbs->name, "Expand default", str, sizeof(str))) expand = atoi(str); if (isparam("expand")) expand = atoi(getparam("expand")); } level = 0; if (!filtering && !date_filtering) { if (expand == 0 && (!getcfg(lbs->name, "Collapse to last", str, sizeof(str)) || atoi(str) == 1)) { /* search last entry in this thread */ if (reply_to[0]) { search_last_reply(msg_list[index].lbs, &message_id); size = TEXT_SIZE; status = el_retrieve(msg_list[index].lbs, message_id, date, attr_list, attrib, lbs->n_attr, text, &size, in_reply_to, reply_to, attachment, encoding, locked_by, draft); if (status == SUCCESS) level = 1; } } } else if (in_reply_to[0]) level = 1; display_line(msg_list[index].lbs, message_id, index, mode, expand, level, printable, n_line, show_attachments, show_att_column, date, in_reply_to, reply_to, n_attr_disp, disp_attr, disp_attr_link, attrib, lbs->n_attr, text, show_text, attachment, encoding, isparam("select") ? atoi(getparam("select")) : 0, &n_display, locked_by, 0, re_buf, page_mid, FALSE, draft); if (threaded && !filtering && !date_filtering) { if (reply_to[0] && expand > 0) { p = reply_to; do { display_reply(msg_list[index].lbs, atoi(p), printable, expand, n_line, n_attr_disp, disp_attr, show_text, 1, 0, re_buf, page_mid, FALSE); while (*p && isdigit(*p)) p++; while (*p && (*p == ',' || *p == ' ')) p++; } while (*p); } } } /* if (!csv && !xml) */ } /* for() */ if (!csv && !xml && !raw) { rsprintf("</table>\n"); if (n_display) rsprintf("<input type=hidden name=nsel value=%d>\n", n_display); rsprintf("</td></tr>\n"); if (n_msg == 0) rsprintf("<tr><td class=\"errormsg\">%s</td></tr>", loc("No entries found")); /*---- page navigation ----*/ if (!printable) show_page_navigation(lbs, n_msg, page_n, n_page); rsprintf("</table>\n"); show_bottom_text(lbs); rsprintf("</form></body></html>\r\n"); } if (xml) { rsputs("</ELOG_LIST>\n"); } regfree(re_buf); for (i = 0; i < lbs->n_attr; i++) regfree(re_buf + 1 + i); xfree(slist); xfree(svalue); xfree(gattr); xfree(list); xfree(msg_list); xfree(text); xfree(text1); }
CWE-79
null
519,307
227520370694498015565086349055778184753
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int is_ascii(char *file_name) { int i, fh, length; unsigned char *buf; fh = open(file_name, O_RDONLY | O_BINARY); if (fh < 0) return FALSE; lseek(fh, 0, SEEK_END); length = TELL(fh); lseek(fh, 0, SEEK_SET); if (length > 1000) length = 1000; buf = xmalloc(length); read(fh, buf, length); close(fh); for (i = 0; i < length; i++) { if (buf[i] < 32 && buf[i] != '\r' && buf[i] != '\n' && buf[i] != '\t') { xfree(buf); return FALSE; } } xfree(buf); return TRUE; }
CWE-79
null
519,308
207567663253758506955956513948339025676
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void el_enum_attr(char *message, int n, char *attr_name, char *attr_value) { char *p, str[NAME_LENGTH], tmp[NAME_LENGTH]; int i; p = message; for (i = 0; i <= n; i++) { strlcpy(str, p, sizeof(str)); if (strchr(str, '\n')) *strchr(str, '\n') = 0; if (strchr(str, '\r')) *strchr(str, '\r') = 0; if (strcmp(str, "========================================") == 0) break; p = strchr(p, '\n'); if (!p) { str[0] = 0; /* not a valid line */ break; } while (*p == '\n' || *p == '\r') p++; if (strchr(str, ':')) { strcpy(tmp, str); *strchr(tmp, ':') = 0; if (strieq(tmp, "$@MID@$") || strieq(tmp, "Date") || strieq(tmp, "Attachment") || strieq(tmp, "Reply To") || strieq(tmp, "In Reply To") || strieq(tmp, "Encoding") || strieq(tmp, "Locked by")) i--; } } attr_name[0] = 0; attr_value[0] = 0; if (strchr(str, ':')) { strlcpy(attr_name, str, NAME_LENGTH); *strchr(attr_name, ':') = 0; strlcpy(attr_value, strchr(str, ':') + 2, NAME_LENGTH); } }
CWE-79
null
519,309
207494004660721862251738336377665690587
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int get_verbose(void) { return _verbose_level; }
CWE-79
null
519,310
322946857638513256693618893695251450019
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void replace_inline_img(LOGBOOK *lbs, char *str) { char *p, *pn, *pa, old[256], link[256], base_url[256], domain[256]; int index; p = str; do { p = strstr(p, "<img "); if (p) { pn = strstr(p, "name="); if (pn) { pn += 9; index = atoi(pn); while (*pn && *pn != '>') pn++; if (*pn == '>') pn++; retrieve_domain(domain, sizeof(domain)); sprintf(p, "<img border=\"0\" src=\"cid:att%d@%s\">", index, domain); memmove(p + strlen(p), pn, strlen(pn) + 1); /* now change href to absolute link */ pa = p - 1; while (pa > str && *pa != '<') // search '<a href=...>' pa--; pn = strstr(pa, "href="); if (pn && pn - pa < 10) { strlcpy(old, pn + 6, sizeof(old)); if (strchr(old, '\"')) *strchr(old, '\"') = 0; compose_base_url(lbs, base_url, sizeof(base_url), FALSE); strlcpy(link, base_url, sizeof(link)); strlcat(link, old, sizeof(link)); if (strchr(link, '?')) *strchr(link, '?') = 0; strsubst(pn + 6, TEXT_SIZE, old, link); if (strlen(link) > strlen(old)) p += strlen(link) - strlen(old); } p++; } else p++; } } while (p != NULL); }
CWE-79
null
519,311
45274983154614987388977614195428972426
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void serialdate2date(double days, int *day, int *month, int *year) /* convert days since 1.1.1900 to date */ { int i, j, l, n; l = (int) days + 68569 + 2415019; n = (int) ((4 * l) / 146097); l = l - (int) ((146097 * n + 3) / 4); i = (int) ((4000 * (l + 1)) / 1461001); l = l - (int) ((1461 * i) / 4) + 31; j = (int) ((80 * l) / 2447); *day = l - (int) ((2447 * j) / 80); l = (int) (j / 11); *month = j + 2 - (12 * l); *year = 100 * (n - 49) + i + l; }
CWE-79
null
519,312
290537596725472398192675924439742519313
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void base64_bufenc(unsigned char *s, int len, char *d) { unsigned int t, pad; int i; pad = 3 - len % 3; if (pad == 3) pad = 0; for (i = 0; i < len;) { t = s[i++] << 16; if (i < len) t |= s[i++] << 8; if (i < len) t |= s[i++] << 0; *(d + 3) = map[t & 63]; t >>= 6; *(d + 2) = map[t & 63]; t >>= 6; *(d + 1) = map[t & 63]; t >>= 6; *(d + 0) = map[t & 63]; d += 4; } *d = 0; while (pad--) *(--d) = '='; }
CWE-79
null
519,313
242913305599546790136539201275469664734
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void rsputs(const char *str) { if (strlen_retbuf + (int) strlen(str) + 1 >= return_buffer_size) { return_buffer = xrealloc(return_buffer, return_buffer_size + (int) strlen(str) + 100000); memset(return_buffer + return_buffer_size, 0, (int) strlen(str) + 100000); return_buffer_size += (int) strlen(str) + 100000; } strcpy(return_buffer + strlen_retbuf, str); strlen_retbuf += strlen(str); }
CWE-79
null
519,314
9251890073903779663884548790492708957
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void receive_config(LOGBOOK *lbs, char *server, char *error_str) { char str[256], pwd[256], *buffer, *p; int status, version, ssl; error_str[0] = 0; do { combine_url(lbs, server, "", str, sizeof(str), &ssl); if (lbs == NULL) strcat(str, "?cmd=GetConfig"); // request complete config file else strcat(str, "?cmd=Download"); // request config section of logbook if (retrieve_url(lbs, str, ssl, &buffer, TRUE) < 0) { *strchr(str, '?') = 0; sprintf(error_str, "Cannot contact elogd server at http://%s", str); return; } /* check version */ p = strstr(buffer, "ELOG HTTP "); if (!p) { if (get_verbose() >= VERBOSE_INFO) puts(buffer); sprintf(error_str, "Remote server is not an ELOG server"); xfree(buffer); return; } version = atoi(p + 10) * 100 + atoi(p + 12) * 10 + atoi(p + 14); if (version < 254) { if (get_verbose() >= VERBOSE_INFO) puts(buffer); strlcpy(str, p + 10, 10); if (strchr(str, '\r')) *strchr(str, '\r') = 0; sprintf(error_str, "Incorrect remote ELOG server version %s, must be 2.5.4 or later", str); xfree(buffer); return; } /* evaluate status */ p = strchr(buffer, ' '); if (p == NULL) { if (get_verbose() >= VERBOSE_INFO) puts(buffer); xfree(buffer); *strchr(str, '?') = 0; sprintf(error_str, "Received invalid response from elogd server at http%s://%s", ssl ? "s" : "", str); xfree(buffer); return; } p++; status = atoi(p); if (status == 401) { if (get_verbose() >= VERBOSE_INFO) puts(buffer); xfree(buffer); eprintf("Please enter password to access remote elogd server: "); fgets(pwd, sizeof(pwd), stdin); while (pwd[strlen(pwd) - 1] == '\n' || pwd[strlen(pwd) - 1] == '\r') pwd[strlen(pwd) - 1] = 0; } else if (status != 200) { if (get_verbose() >= VERBOSE_INFO) puts(buffer); xfree(buffer); *strchr(str, '?') = 0; sprintf(error_str, "Received invalid response from elogd server at http%s://%s", ssl ? "s" : "", str); return; } } while (status != 200); p = strstr(buffer, "\r\n\r\n"); if (p == NULL) { if (get_verbose() >= VERBOSE_INFO) puts(buffer); xfree(buffer); sprintf(error_str, loc("Cannot receive \"%s\""), str); return; } p += 4; if (strstr(p, "[global]") == NULL) { strlcpy(error_str, p, 256); xfree(buffer); return; } if (lbs == NULL) { if (!save_config(p, str)) rsprintf("%s", str); } else { if (!save_admin_config(lbs->name, p, str)) rsprintf("%s", str); } xfree(buffer); }
CWE-79
null
519,315
329123131024739148557107134971228364555
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void csv_import(LOGBOOK *lbs, const char *csv, const char *csvfile) { const char *p; char *line, *list; char str[256], date[80], sep[80]; int i, j, n, n_attr, iline, n_imported, textcol, datecol, attr_offset; BOOL first, in_quotes, filltext; time_t ltime; list = (char *) xmalloc((MAX_N_ATTR + 2) * NAME_LENGTH); line = (char *) xmalloc(10000); first = TRUE; in_quotes = FALSE; iline = n_imported = 0; filltext = FALSE; textcol = -1; datecol = -1; attr_offset = 0; strcpy(sep, ","); if (isparam("sep")) strcpy(sep, getparam("sep")); if (sep[0] == 0) strcpy(sep, ","); if (strieq(sep, "auto")) { /* count commas */ for (i = 0, p = csv; p; i++) { p = strchr(p, ','); if (p) p++; } n = i; /* count semicolon */ for (i = 0, p = csv; p; i++) { p = strchr(p, ';'); if (p) p++; } strcpy(sep, i > n ? ";" : ","); } n_attr = lbs->n_attr; if (isparam("preview")) { /* title row */ sprintf(str, loc("CSV import preview of %s"), csvfile); show_standard_header(lbs, TRUE, str, "./", FALSE, NULL, NULL, 0); rsprintf("<table class=\"frame\" cellpadding=\"0\" cellspacing=\"0\">\n"); rsprintf("<tr><td class=\"title1\">%s</td></tr>\n", str, str); /* menu buttons */ rsprintf("<tr><td class=\"menuframe\"><span class=\"menu1\">\n"); rsprintf("<input type=submit name=cmd value=\"%s\">\n", loc("Cancel")); rsprintf("<input type=submit name=cmd value=\"%s\">\n", loc("CSV Import")); /* hidden fields */ rsprintf("<input type=hidden name=sep value=\"%s\">\n", sep); if (isparam("head")) rsprintf("<input type=hidden name=head value=\"%s\">\n", getparam("head")); if (isparam("notignore")) rsprintf("<input type=hidden name=notignore value=\"%s\">\n", getparam("notignore")); if (isparam("filltext")) rsprintf("<input type=hidden name=filltext value=\"%s\">\n", getparam("filltext")); rsprintf("<input type=hidden name=csvfile value=\"%s\">\n", csvfile); rsprintf("</span></td></tr>\n\n"); rsprintf("<tr><td><table class=\"listframe\" width=\"100%%\" cellspacing=0>"); } p = csv; datecol = -1; attr_offset = 0; do { for (i = 0; i < 10000 && *p; i++) { if (!in_quotes && (*p == '\r' || *p == '\n')) break; line[i] = *p++; if (line[i] == '"') in_quotes = !in_quotes; } line[i] = 0; while (*p == '\r' || *p == '\n') p++; if (!*p) break; memset(list, 0, MAX_N_ATTR * NAME_LENGTH); n = strbreak(line, (char (*)[NAME_LENGTH]) list, MAX_N_ATTR, sep, FALSE); if (n == MAX_N_ATTR) { strlcpy(str, loc("Too many attributes in CSV file"), sizeof(str)); show_error(str); } /* check if text column is present */ if (first && isparam("filltext") && atoi(getparam("filltext"))) { for (i = 0; i < n; i++) if (strieq(list + i * NAME_LENGTH, loc("text"))) { filltext = TRUE; textcol = i; break; } } /* interprete date entries correctly */ if (!(first && isparam("head"))) { for (i = attr_offset; i < n; i++) { if (attr_flags[i - attr_offset] & AF_DATE) { /* convert to seconds in Unix format */ ltime = convert_date(list + i * NAME_LENGTH); if (ltime == 0) { show_error(loc("Invalid date format")); return; } sprintf(list + i * NAME_LENGTH, "%d", (int) ltime); } if (attr_flags[i - attr_offset] & AF_DATETIME) { /* convert to seconds in Unix format */ ltime = convert_datetime(list + i * NAME_LENGTH); if (ltime == 0) { show_error(loc("Invalid date format")); return; } sprintf(list + i * NAME_LENGTH, "%d", (int) ltime); } } } if (first) { /* check for date column */ for (i = attr_offset = 0; i < n; i++) if (strieq(list + i * NAME_LENGTH, "Date")) datecol = i; /* skip message ID */ for (i = attr_offset = 0; i < n; i++) if (strieq(list + i * NAME_LENGTH, "Message ID") || strieq(list + i * NAME_LENGTH, "Date")) attr_offset++; } /* derive attributes from first line */ if (first && isparam("head")) { if (isparam("preview")) { rsprintf("<tr>\n"); for (i = attr_offset; i < n; i++) if (i != textcol) rsprintf("<th class=\"listtitle\">%s</th>\n", list + i * NAME_LENGTH); if (filltext) rsprintf("<th class=\"listtitle\">%s</th>\n", loc("text")); rsprintf("</tr>\n"); if (filltext) n_attr = n - 1 - attr_offset; else n_attr = n - attr_offset; } else { for (i = j = attr_offset; i < n; i++) if (i != textcol) strlcpy(attr_list[j++ - attr_offset], list + i * NAME_LENGTH, NAME_LENGTH); if (filltext) { if (!set_attributes(lbs, attr_list, n - 1 - attr_offset)) return; lbs->n_attr = n - 1 - attr_offset; } else { if (!set_attributes(lbs, attr_list, n - attr_offset)) return; lbs->n_attr = n - attr_offset; } n_attr = lbs->n_attr; } } else { /* ignore first line */ if (first && !isparam("notignore")) { first = FALSE; continue; } if (isparam("preview")) { rsprintf("<tr>\n"); for (i = j = attr_offset; i < n_attr + attr_offset; i++) { if (iline % 2 == 0) rsputs("<td class=\"list1\">"); else rsputs("<td class=\"list2\">"); /* skip text column */ if (i == textcol) j++; if (i >= n || !list[j * NAME_LENGTH]) rsputs("&nbsp;"); else rsputs(list + j * NAME_LENGTH); rsputs("</td>\n"); j++; } if (filltext) { rsputs("<td class=\"summary\">"); if (list[textcol * NAME_LENGTH]) rsputs(list + textcol * NAME_LENGTH); else rsputs("&nbsp;"); rsputs("</td>\n"); } rsputs("</tr>\n"); iline++; } else { /* get date and check it */ if (datecol != -1) { strlcpy(date, list + datecol * NAME_LENGTH, sizeof(date)); ltime = date_to_ltime(date); if (ltime <= 0) { /* try other date formats */ ltime = convert_datetime(date); if (ltime <= 0) ltime = convert_date(date); if (ltime <= 0) { strcpy(str, loc("Invalid date format")); strlcat(str, ": \"", sizeof(str)); strlcat(str, date, sizeof(str)); strlcat(str, "\"", sizeof(str)); show_error(str); return; } /* convert back ltime to date */ get_rfc2822_date(date, sizeof(date), ltime); } } else date[0] = 0; if (!filltext) { /* submit entry */ if (el_submit (lbs, 0, FALSE, date, attr_list, (char (*)[NAME_LENGTH]) (list + attr_offset * NAME_LENGTH), n_attr, "", "", "", "plain", NULL, TRUE, NULL, NULL)) n_imported++; } else { strlcpy(line, list + textcol * NAME_LENGTH, 10000); insert_breaks(line, 78, 10000); for (i = textcol; i < n_attr + attr_offset; i++) strlcpy(list + i * NAME_LENGTH, list + (i + 1) * NAME_LENGTH, NAME_LENGTH); /* submit entry */ if (el_submit (lbs, 0, FALSE, date, attr_list, (char (*)[NAME_LENGTH]) (list + attr_offset * NAME_LENGTH), n_attr, line, "", "", "plain", NULL, TRUE, NULL, NULL)) n_imported++; } } } first = FALSE; } while (*p); xfree(line); xfree(list); if (isparam("preview")) { rsprintf("</table></td></tr></table>\n"); show_bottom_text(lbs); rsprintf("</form></body></html>\r\n"); return; } sprintf(str, loc("%d entries successfully imported"), n_imported); show_elog_list(lbs, 0, 0, 0, TRUE, str); }
CWE-79
null
519,316
91826370148432333267318049392301443979
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
BOOL subst_param(char *str, int size, char *param, char *value) { int len; char *p1, *p2, *s, param_enc[256], str2[256]; strlcpy(param_enc, param, sizeof(param_enc)); url_slash_encode(param_enc, sizeof(param_enc)); if (!value[0]) { /* remove parameter */ s = param_in_str(str, param_enc); if (s == NULL) return FALSE; /* remove parameter */ p1 = s - 1; for (p2 = p1 + strlen(param_enc) + 1; *p2 && *p2 != '&'; p2++); strlcpy(str2, p2, sizeof(str2)); strlcpy(p1, str2, size - (p1 - str)); if (!strchr(str, '?') && strchr(str, '&')) *strchr(str, '&') = '?'; return TRUE; } if ((p1 = param_in_str(str, param_enc)) == NULL) { if (strchr(str, '?')) strlcat(str, "&", size); else strlcat(str, "?", size); strlcat(str, param_enc, size); strlcat(str, "=", size); strlcat(str, value, size); return FALSE; } p1 += strlen(param_enc) + 1; for (p2 = p1; *p2 && *p2 != '&'; p2++); len = p2 - p1; if (len > (int) strlen(value)) { /* new value is shorter than old one */ strlcpy(str2, value, size - (p1 - str)); strlcpy(str2 + strlen(value), p2, size - (p1 + strlen(value) - str)); strlcpy(p1, str2, size - (p1 - str)); } else { /* new value is longer than old one */ s = (char *) xmalloc(size); strlcpy(s, p2, size); strlcpy(str2, value, size - (p1 - str)); strlcat(str2, s, size - (p1 + strlen(value) - str)); strlcpy(p1, str2, size - (p1 - str)); xfree(s); } return TRUE; }
CWE-79
null
519,317
336882837411036239930271638207084115317
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int recv_string(int sock, char *buffer, int buffer_size, int millisec) { int i, n; fd_set readfds; struct timeval timeout; n = 0; memset(buffer, 0, buffer_size); do { if (millisec > 0) { FD_ZERO(&readfds); FD_SET(sock, &readfds); timeout.tv_sec = millisec / 1000; timeout.tv_usec = (millisec % 1000) * 1000; select(FD_SETSIZE, (void *) &readfds, NULL, NULL, (void *) &timeout); if (!FD_ISSET(sock, &readfds)) break; } i = recv(sock, buffer + n, 1, 0); if (i <= 0) break; n++; if (n >= buffer_size) break; } while (buffer[n - 1] && buffer[n - 1] != 10); return n - 1; }
CWE-79
null
519,318
137880732332099422572450073319704895459
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int max_attachment_size(LOGBOOK *lbs, int message_id) { char att_file[MAX_ATTACHMENTS][MAX_PATH_LENGTH]; int index, max_size, fh; char str[256], subdir[256], file_name[256]; el_retrieve(lbs, message_id, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL, att_file, NULL, NULL, NULL); max_size = 0; for (index = 0; index < MAX_ATTACHMENTS; index++) { if (att_file[index][0] == 0) continue; strlcpy(file_name, lbs->data_dir, sizeof(file_name)); generate_subdir_name(att_file[index], subdir, sizeof(subdir)); strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, att_file[index], sizeof(file_name)); if (is_image(file_name)) { get_thumb_name(file_name, str, sizeof(str), 0); if (str[0]) strlcpy(file_name, str, sizeof(file_name)); } fh = open(file_name, O_RDONLY | O_BINARY); if (fh > 0) { off_t size = lseek(fh, 0L, SEEK_END); max_size = size > max_size ? size : max_size; } } return max_size; }
CWE-79
null
519,319
250644709110895914537794672010150402461
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void send_file_direct(char *file_name) { int fh, i, length, delta; char str[MAX_PATH_LENGTH], dir[MAX_PATH_LENGTH], charset[80]; getcwd(dir, sizeof(dir)); fh = open(file_name, O_RDONLY | O_BINARY); if (fh > 0) { lseek(fh, 0, SEEK_END); length = TELL(fh); lseek(fh, 0, SEEK_SET); rsprintf("HTTP/1.1 200 Document follows\r\n"); rsprintf("Server: ELOG HTTP %s-%s\r\n", VERSION, git_revision()); rsprintf("Accept-Ranges: bytes\r\n"); /* set expiration time to one day if no thumbnail */ if (isparam("thumb")) { rsprintf("Pragma: no-cache\r\n"); rsprintf("Cache-control: private, max-age=0, no-cache, no-store\r\n"); } else { rsprintf("Cache-control: public, max-age=86400\r\n"); } if (keep_alive) { rsprintf("Connection: Keep-Alive\r\n"); rsprintf("Keep-Alive: timeout=60, max=10\r\n"); } /* return proper header for file type */ for (i = 0; i < (int) strlen(file_name); i++) str[i] = toupper(file_name[i]); str[i] = 0; for (i = 0; filetype[i].ext[0]; i++) if (chkext(str, filetype[i].ext)) break; if (!getcfg("global", "charset", charset, sizeof(charset))) strcpy(charset, DEFAULT_HTTP_CHARSET); if (filetype[i].ext[0]) { if (strncmp(filetype[i].type, "text", 4) == 0) rsprintf("Content-Type: %s;charset=%s\r\n", filetype[i].type, charset); else if (strcmp(filetype[i].ext, ".SVG") == 0) { rsprintf("Content-Type: %s\r\n", filetype[i].type); if (strrchr(file_name, '/')) strlcpy(str, strrchr(file_name, '/')+1, sizeof(str)); else strlcpy(str, file_name, sizeof(str)); if (str[6] == '_' && str[13] == '_') rsprintf("Content-Disposition: attachment; filename=\"%s\"\r\n", str+14); else rsprintf("Content-Disposition: attachment; filename=\"%s\"\r\n", str); } else rsprintf("Content-Type: %s\r\n", filetype[i].type); } else if (is_ascii(file_name)) rsprintf("Content-Type: text/plain;charset=%s\r\n", charset); else rsprintf("Content-Type: application/octet-stream;charset=%s\r\n", charset); rsprintf("Content-Length: %d\r\n\r\n", length); /* increase return buffer size if file too big */ if (length > return_buffer_size - (int) strlen(return_buffer)) { delta = length - (return_buffer_size - strlen(return_buffer)) + 1000; return_buffer = xrealloc(return_buffer, return_buffer_size + delta); memset(return_buffer + return_buffer_size, 0, delta); return_buffer_size += delta; } return_length = strlen(return_buffer) + length; read(fh, return_buffer + strlen(return_buffer), length); close(fh); } else { char encodedname[256]; show_html_header(NULL, FALSE, "404 Not Found", TRUE, FALSE, NULL, FALSE, 0); rsprintf("<body><h1>Not Found</h1>\r\n"); rsprintf("The requested file <b>"); strencode2(encodedname, file_name, sizeof(encodedname)); if (strchr(file_name, DIR_SEPARATOR)) rsprintf("%s", encodedname); else rsprintf("%s%c%s", dir, DIR_SEPARATOR, encodedname); rsprintf("</b> was not found on this server<p>\r\n"); rsprintf("<hr><address>ELOG version %s</address></body></html>\r\n\r\n", VERSION); return_length = strlen_retbuf; keep_alive = FALSE; } }
CWE-79
null
519,320
184268512206261144818013410223816296123
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void add_logbook_to_group(LOGBOOK *lbs, char *new_name) { int i, j, n, flag; char str[1000], grpname[256], grpmembers[1000]; char grplist[MAX_N_LIST][NAME_LENGTH]; /* enumerate groups */ for (i = 0;; i++) { if (!enumcfg("global", grpname, sizeof(grpname), grpmembers, sizeof(grpmembers), i)) break; flag = 0; strlcpy(str, grpname, sizeof(str)); str[9] = 0; if (strieq(str, "top group")) flag = 2; str[5] = 0; if (strieq(str, "group")) flag = 1; if (flag) { n = strbreak(grpmembers, grplist, MAX_N_LIST, ",", FALSE); for (j = 0; j < n; j++) { if (strieq(lbs->name, grplist[j])) { /* rename or remove logbook */ change_config_line(lbs, grpname, "", new_name); break; } } } } }
CWE-79
null
519,321
264950733620858751845049790915386407999
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int setparam(char *param, char *value) { int i; char str[10000]; if (strieq(param, "text")) { if (strlen(value) >= TEXT_SIZE) { sprintf(str, "Error: Entry text too big (%lu bytes). Please increase TEXT_SIZE and recompile elogd\n", (unsigned long) strlen(value)); show_error(str); return 0; } strlcpy(_mtext, value, TEXT_SIZE); return 1; } if (strieq(param, "cmdline")) { if (strlen(value) >= CMD_SIZE) { sprintf(str, "Error: Command line too big (%lu bytes). Please increase CMD_SIZE and recompile elogd\n", (unsigned long) strlen(value)); show_error(str); return 0; } strlcpy(_cmdline, value, CMD_SIZE); return 1; } /* paremeters can be superseeded */ for (i = 0; i < MAX_PARAM; i++) if (_param[i][0] == 0 || strieq(param, _param[i])) break; if (i < MAX_PARAM) { if (strlen(param) >= NAME_LENGTH) { sprintf(str, "Error: Parameter name too big (%lu bytes).\n", (unsigned long) strlen(param)); show_error(str); return 0; } strlcpy(_param[i], param, NAME_LENGTH); if (strlen(value) >= NAME_LENGTH) { sprintf(str, "Error: Parameter value for parameter <b>%s</b> too big (%lu bytes). Please increase NAME_LENGTH and recompile elogd\n", param, (unsigned long) strlen(value)); show_error(str); return 0; } strlcpy(_value[i], value, NAME_LENGTH); } else { sprintf(str, "Error: Too many parameters (> %d). Cannot perform operation.\n", MAX_PARAM); show_error(str); return 0; } return 1; }
CWE-79
null
519,322
237305427417184032516880352363107638425
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int ascii_compare2(const void *s1, const void *s2) { return stricmp((char *) s1, (char *) s2); }
CWE-79
null
519,323
928494220083352862217873571887176504
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
char *getparam(char *param) { int i; if (strieq(param, "text")) return _mtext; if (strieq(param, "cmdline")) return _cmdline; for (i = 0; i < MAX_PARAM && _param[i][0]; i++) if (strieq(param, _param[i])) break; if (i < MAX_PARAM && _param[i][0]) return _value[i]; return NULL; }
CWE-79
null
519,324
235200062306609831331707763228916450335
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
void show_change_pwd_page(LOGBOOK *lbs) { char str[256], config[256], old_pwd[256], new_pwd[256], new_pwd2[256], user[256], auth[32], error_str[256]; int wrong_pwd; /* otherwise calls with null lbs which make this procedure crash */ if (lbs == NULL) lbs = get_first_lbs_with_global_passwd(); if (lbs == NULL) return; getcfg(lbs->name, "Authentication", auth, sizeof(auth)); old_pwd[0] = new_pwd[0] = new_pwd2[0] = 0; if (isparam("oldpwd")) strlcpy(old_pwd, getparam("oldpwd"), sizeof(old_pwd)); if (isparam("newpwd")) strlcpy(new_pwd, getparam("newpwd"), sizeof(new_pwd)); if (isparam("newpwd2")) strlcpy(new_pwd2, getparam("newpwd2"), sizeof(new_pwd2)); if (isparam("unm")) strlcpy(user, getparam("unm"), sizeof(user)); else user[0] = 0; if (isparam("config")) { strlcpy(str, getparam("config"), sizeof(str)); strencode2(user, str, sizeof(user)); } wrong_pwd = FALSE; error_str[0] = 0; if (isparam("fail")) { wrong_pwd = atoi(getparam("fail")); if (!wrong_pwd) { wrong_pwd = 3; strlcpy(error_str, getparam("fail"), sizeof(error_str)); } } if (old_pwd[0] || new_pwd[0]) { if (user[0]) { if (stristr(auth, "Kerberos") || stristr(auth, "Webserver") || stristr(auth, "PAM")) { if (strcmp(new_pwd, new_pwd2) != 0) wrong_pwd = 2; } else { /* administrator does not have to supply old password if changing other user's password */ if (isparam("unm") && is_admin_user(lbs, getparam("unm")) && stricmp(getparam("unm"), user) != 0) wrong_pwd = 0; else { if (!auth_verify_password(lbs, user, old_pwd, str, sizeof(str))) wrong_pwd = 1; } if (strcmp(new_pwd, new_pwd2) != 0) wrong_pwd = 2; } } if (new_pwd[0]) { /* replace password */ error_str[0] = 0; if (!wrong_pwd) wrong_pwd = (auth_change_password(lbs, user, old_pwd, new_pwd, error_str, sizeof(error_str)) == 0); if (!wrong_pwd && isparam("unm") && strcmp(user, getparam("unm")) == 0) { redirect(lbs, ""); return; } if (!wrong_pwd) { /* redirect back to configuration page */ if (isparam("config")) { strlcpy(config, getparam("config"), sizeof(config)); sprintf(str, "?cmd=%s&cfg_user=%s", loc("Config"), config); } else sprintf(str, "?cmd=%s", loc("Config")); redirect(lbs, str); return; } /* go though one redirection to avoid passwords to be shown in URL */ if (wrong_pwd) { if (error_str[0]) sprintf(str, "?cmd=%s&config=%s&fail=%s", loc("Change password"), getparam("unm"), error_str); else sprintf(str, "?cmd=%s&config=%s&fail=%d", loc("Change password"), getparam("unm"), wrong_pwd); redirect(lbs, str); return; } } } show_standard_header(lbs, TRUE, loc("ELOG change password"), NULL, FALSE, NULL, NULL, 0); rsprintf("<table class=\"dlgframe\" cellspacing=0 align=center>"); if (wrong_pwd == 1) { if (error_str[0]) { strencode2(str, error_str, sizeof(str)); rsprintf("<tr><td colspan=2 class=\"dlgerror\">%s!</td></tr>\n", str); } else rsprintf("<tr><td colspan=2 class=\"dlgerror\">%s!</td></tr>\n", loc("Wrong password")); } if (wrong_pwd == 2) rsprintf("<tr><td colspan=2 class=\"dlgerror\">%s!</td></tr>\n", loc("New passwords do not match, please retype")); if (wrong_pwd == 3) { strencode2(str, error_str, sizeof(str)); rsprintf("<tr><td colspan=2 class=\"dlgerror\">%s!</td></tr>\n", str); } rsprintf("<tr><td colspan=2 class=\"dlgtitle\">\n"); rsprintf("<input type=hidden name=config value=\"%s\">", user); rsprintf("%s \"%s\"</td></tr>\n", loc("Change password for user"), user); /* do not ask for old pwasword if admin changes other user's password */ if (isparam("unm")) { if (!is_admin_user(lbs, getparam("unm")) || stricmp(getparam("unm"), user) == 0) { if (isparam("oldpwd") && !(wrong_pwd == 1)) // hidden password for password recovery rsprintf("<input type=hidden name=oldpwd value=\"%s\"", getparam("oldpwd")); else { rsprintf("<tr><td align=right class=\"dlgform\">%s:\n", loc("Old password")); rsprintf("<td align=left class=\"dlgform\"><input type=password name=oldpwd>\n"); rsprintf("</td></tr>\n"); } } } rsprintf("<tr><td align=right class=\"dlgform\">%s:</td>\n", loc("New password")); rsprintf("<td align=left class=\"dlgform\"><input type=password name=newpwd></td></tr>\n"); rsprintf("<tr><td align=right class=\"dlgform\">%s:</td>\n", loc("Retype new password")); rsprintf("<td align=left class=\"dlgform\"><input type=password name=newpwd2></td></tr>\n"); rsprintf("<tr><td align=center colspan=2 class=\"dlgform\"><input type=submit value=\"%s\"></td></tr>", loc("Submit")); rsprintf("</table>\n"); show_bottom_text(lbs); rsprintf("</form></body></html>\r\n"); }
CWE-79
null
519,325
241786240603889515737041299911414952465
null
null
other
elog
993bed4923c88593cc6b1186e0d1b9564994a25a
0
int el_move_message_thread(LOGBOOK *lbs, int message_id) { int i, n, size, new_id; char date[80], attrib[MAX_N_ATTR][NAME_LENGTH], *text, in_reply_to[80], reply_to[MAX_REPLY_TO * 10], encoding[80], locked_by[256], draft[256]; char list[MAX_N_ATTR][NAME_LENGTH], str[256]; char att_file[MAX_ATTACHMENTS][256]; /* retrieve message */ text = xmalloc(TEXT_SIZE); size = TEXT_SIZE; el_retrieve(lbs, message_id, date, attr_list, attrib, lbs->n_attr, text, &size, in_reply_to, reply_to, att_file, encoding, locked_by, draft); /* submit as new message */ date[0] = 0; new_id = el_submit(lbs, 0, FALSE, date, attr_list, attrib, lbs->n_attr, text, in_reply_to, reply_to, encoding, att_file, FALSE, locked_by, draft); xfree(text); /* correct links */ el_correct_links(lbs, message_id, new_id); /* delete original message */ el_delete_message(lbs, message_id, FALSE, NULL, FALSE, FALSE); /* move all replies recursively */ if (getcfg(lbs->name, "Resubmit replies", str, sizeof(str)) && atoi(str) == 1) { if (reply_to[0]) { n = strbreak(reply_to, list, MAX_N_ATTR, ",", FALSE); for (i = 0; i < n; i++) el_move_message_thread(lbs, atoi(list[i])); } } return new_id; }
CWE-79
null
519,326
7405508265614156158059298688280352978
null
null
other