From 737dd7a227270737250118e74764f2d970d389e7 Mon Sep 17 00:00:00 2001 From: Stefan Ritt Date: Tue, 1 Mar 2005 23:48:18 +0000 Subject: [PATCH] Implemented MXML for password file SVN revision: 1225 --- src/elogd.c | 496 +++++++++++------------- src/mxml.c | 1050 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/mxml.h | 71 ++++ 3 files changed, 1336 insertions(+), 281 deletions(-) create mode 100755 src/mxml.c create mode 100755 src/mxml.h diff --git a/src/elogd.c b/src/elogd.c index 215c6ad9..0d97e776 100755 --- a/src/elogd.c +++ b/src/elogd.c @@ -6,6 +6,9 @@ Contents: Web server program for Electronic Logbook ELOG $Log$ + Revision 1.572 2005/03/01 23:48:17 ritt + Implemented MXML for password file + Revision 1.571 2005/02/22 09:34:04 ritt Fixed bug with logbook names containing blanks and 'List' link @@ -932,6 +935,7 @@ char pidfile[256]; /* Pidfile name /* local includes */ #include "regex.h" +#include "mxml.h" BOOL running_as_daemon; /* Running as a daemon/service? */ int elog_tcp_port = (int) DEFAULT_PORT; /* Server's TCP port */ @@ -1195,7 +1199,7 @@ int run_service(void); #endif void show_error(char *error); -BOOL enum_user_line(LOGBOOK * lbs, int n, char *user); +BOOL enum_user_line(LOGBOOK * lbs, int n, char *user, int size); int get_user_line(char *logbook_name, char *user, char *password, char *full_name, char *email, char *email_notify); int strbreak(char *str, char list[][NAME_LENGTH], int size, char *brk); @@ -1361,8 +1365,6 @@ char *xstrdup(const char *string) return s; } -/*------------------------------------------------------------------*/ - /*----------------------- Message handling -------------------------*/ /* Have vasprintf? (seems that only libc6 based Linux has this) */ @@ -3568,7 +3570,7 @@ void retrieve_email_from(LOGBOOK * lbs, char *ret, char attrib[MAX_N_ATTR][NAME_ /* if nothing available, figure out email from an administrator */ if (strchr(str, '@') == NULL) { for (i = 0;; i++) { - if (!enum_user_line(lbs, i, login_name)) + if (!enum_user_line(lbs, i, login_name, sizeof(login_name))) break; get_user_line(lbs->name, login_name, NULL, NULL, str, NULL); if (is_admin_user(lbs->name, login_name) && strchr(str, '@')) @@ -7254,9 +7256,8 @@ void add_subst_time(LOGBOOK * lbs, BOOL change_pwd(LOGBOOK * lbs, char *user, char *pwd) { - char str[256], file_name[256], line[256], *p, *pl; - char *buf; - int i, fh, size; + char str[256], file_name[256]; + PMXML_NODE xml_tree, node; getcfg(lbs->name, "Password file", str, sizeof(str)); @@ -7267,75 +7268,23 @@ BOOL change_pwd(LOGBOOK * lbs, char *user, char *pwd) strlcat(file_name, str, sizeof(file_name)); } - fh = open(file_name, O_RDWR | O_BINARY, 644); - if (fh > 0) { - lseek(fh, 0, SEEK_END); - size = TELL(fh); - lseek(fh, 0, SEEK_SET); + xml_tree = mxml_parse_file(file_name, str, sizeof(str)); + if (!xml_tree) + return FALSE; - buf = xmalloc(size + 1); - read(fh, buf, size); - buf[size] = 0; - pl = buf; - - while (pl < buf + size) { - for (i = 0; pl[i] && pl[i] != '\r' && pl[i] != '\n'; i++) - line[i] = pl[i]; - line[i] = 0; - - if (line[0] == ';' || line[0] == '#' || line[0] == 0) { - pl += strlen(line); - while (*pl && (*pl == '\r' || *pl == '\n')) - pl++; - continue; - } - - strcpy(str, line); - if (strchr(str, ':')) - *strchr(str, ':') = 0; - if (strcmp(str, user) == 0) - break; - - pl += strlen(line); - while (*pl && (*pl == '\r' || *pl == '\n')) - pl++; - } - - /* return if not found */ - if (pl >= buf + size) { - xfree(buf); - close(fh); - return FALSE; - } - - p = strchr(line, ':'); - if (p) - p = strchr(p + 1, ':'); - if (p == NULL) - return FALSE; - - /* replace password */ - lseek(fh, 0, SEEK_SET); - write(fh, buf, pl - buf); - - sprintf(str, "%s:%s%s\n", user, pwd, p); - write(fh, str, strlen(str)); - - pl += strlen(line); - while (*pl && (*pl == '\r' || *pl == '\n')) - pl++; - - write(fh, pl, strlen(pl)); - - TRUNCATE(fh); - - xfree(buf); - close(fh); - - return TRUE; + sprintf(str, "/list/user[name=%s]/password", user); + node = mxml_find_node(xml_tree, str); + if (node == NULL) { + mxml_free_tree(xml_tree); + return FALSE; } - return FALSE; + mxml_replace_node_value(node, pwd); + + mxml_write_tree(file_name, xml_tree); + mxml_free_tree(xml_tree); + + return TRUE; } /*------------------------------------------------------------------*/ @@ -8347,7 +8296,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL rsprintf("