mirror of
https://gitea.psi.ch/ELOG/elog.git
synced 2026-09-27 02:57:22 +00:00
Fixed password file mirror problems
SVN revision: 1012
This commit is contained in:
parent
d97fd2862f
commit
9579009f98
155
src/elogd.c
155
src/elogd.c
@ -6,6 +6,9 @@
|
|||||||
Contents: Web server program for Electronic Logbook ELOG
|
Contents: Web server program for Electronic Logbook ELOG
|
||||||
|
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.428 2004/08/04 10:30:36 midas
|
||||||
|
Fixed password file mirror problems
|
||||||
|
|
||||||
Revision 1.427 2004/08/04 09:24:17 midas
|
Revision 1.427 2004/08/04 09:24:17 midas
|
||||||
Removed user[0] in is_admin_user()
|
Removed user[0] in is_admin_user()
|
||||||
|
|
||||||
@ -8611,6 +8614,7 @@ void remove_crlf(char *buffer)
|
|||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
|
/* convert \r\n -> \n */
|
||||||
p = buffer;
|
p = buffer;
|
||||||
while ((p = strstr(p, "\r\n")) != NULL) {
|
while ((p = strstr(p, "\r\n")) != NULL) {
|
||||||
strcpy(p, p + 1);
|
strcpy(p, p + 1);
|
||||||
@ -8619,6 +8623,51 @@ void remove_crlf(char *buffer)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void adjust_crlf(char *buffer, int bufsize)
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
#ifdef OS_UNIX
|
||||||
|
|
||||||
|
/* convert \r\n -> \n */
|
||||||
|
p = buffer;
|
||||||
|
while ((p = strstr(p, "\r\n")) != NULL) {
|
||||||
|
strcpy(p, p + 1);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
|
char *tmpbuf;
|
||||||
|
|
||||||
|
assert(bufsize);
|
||||||
|
tmpbuf = malloc(bufsize);
|
||||||
|
assert(tmpbuf);
|
||||||
|
|
||||||
|
/* 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) {
|
||||||
|
free (tmpbuf);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
strlcpy(tmpbuf, p, bufsize);
|
||||||
|
*(p++) = '\r';
|
||||||
|
strlcpy(p, tmpbuf, bufsize - ((int) p - (int) buffer));
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(tmpbuf);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
int save_admin_config(char *section, char *buffer, char *error)
|
int save_admin_config(char *section, char *buffer, char *error)
|
||||||
{
|
{
|
||||||
int fh, i, length;
|
int fh, i, length;
|
||||||
@ -8664,12 +8713,8 @@ int save_admin_config(char *section, char *buffer, char *error)
|
|||||||
strlcat(p1, buf2, length + strlen(buffer) + 1);
|
strlcat(p1, buf2, length + strlen(buffer) + 1);
|
||||||
free(buf2);
|
free(buf2);
|
||||||
}
|
}
|
||||||
#ifdef OS_UNIX
|
|
||||||
|
|
||||||
/* under unix, convert CRLF to CR */
|
adjust_crlf(buf, length + strlen(buffer) + 10);
|
||||||
remove_crlf(buf);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
lseek(fh, 0, SEEK_SET);
|
lseek(fh, 0, SEEK_SET);
|
||||||
i = write(fh, buf, strlen(buf));
|
i = write(fh, buf, strlen(buf));
|
||||||
@ -8697,7 +8742,7 @@ int save_admin_config(char *section, char *buffer, char *error)
|
|||||||
|
|
||||||
int change_config_line(LOGBOOK * lbs, char *option, char *old_value, char *new_value)
|
int change_config_line(LOGBOOK * lbs, char *option, char *old_value, char *new_value)
|
||||||
{
|
{
|
||||||
int fh, i, j, n, length;
|
int fh, i, j, n, length, bufsize;
|
||||||
char str[NAME_LENGTH], *buf, *buf2, *p1, *p2, *p3;
|
char str[NAME_LENGTH], *buf, *buf2, *p1, *p2, *p3;
|
||||||
char list[MAX_N_LIST][NAME_LENGTH], line[NAME_LENGTH];
|
char list[MAX_N_LIST][NAME_LENGTH], line[NAME_LENGTH];
|
||||||
|
|
||||||
@ -8713,7 +8758,8 @@ int change_config_line(LOGBOOK * lbs, char *option, char *old_value, char *new_v
|
|||||||
/* read previous contents */
|
/* read previous contents */
|
||||||
length = lseek(fh, 0, SEEK_END);
|
length = lseek(fh, 0, SEEK_END);
|
||||||
lseek(fh, 0, SEEK_SET);
|
lseek(fh, 0, SEEK_SET);
|
||||||
buf = malloc(length + strlen(new_value) + 10);
|
bufsize = 2*(length + strlen(new_value) + 10);
|
||||||
|
buf = malloc(bufsize);
|
||||||
assert(buf);
|
assert(buf);
|
||||||
read(fh, buf, length);
|
read(fh, buf, length);
|
||||||
buf[length] = 0;
|
buf[length] = 0;
|
||||||
@ -8783,12 +8829,8 @@ int change_config_line(LOGBOOK * lbs, char *option, char *old_value, char *new_v
|
|||||||
strlcat(p2, buf2, length + strlen(new_value) + 10);
|
strlcat(p2, buf2, length + strlen(new_value) + 10);
|
||||||
free(buf2);
|
free(buf2);
|
||||||
}
|
}
|
||||||
#ifdef OS_UNIX
|
|
||||||
|
|
||||||
/* under unix, convert CRLF to CR */
|
adjust_crlf(buf, bufsize);
|
||||||
remove_crlf(buf);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
lseek(fh, 0, SEEK_SET);
|
lseek(fh, 0, SEEK_SET);
|
||||||
i = write(fh, buf, strlen(buf));
|
i = write(fh, buf, strlen(buf));
|
||||||
@ -8877,7 +8919,7 @@ int delete_logbook(LOGBOOK * lbs, char *error)
|
|||||||
|
|
||||||
int rename_logbook(LOGBOOK * lbs, char *new_name)
|
int rename_logbook(LOGBOOK * lbs, char *new_name)
|
||||||
{
|
{
|
||||||
int fh, i, length;
|
int fh, i, length, bufsize;
|
||||||
char *buf, *buf2, *p1, *p2;
|
char *buf, *buf2, *p1, *p2;
|
||||||
char str[256], lb_dir[256], old_dir[256], new_dir[256];
|
char str[256], lb_dir[256], old_dir[256], new_dir[256];
|
||||||
|
|
||||||
@ -8907,7 +8949,8 @@ int rename_logbook(LOGBOOK * lbs, char *new_name)
|
|||||||
/* read previous contents */
|
/* read previous contents */
|
||||||
length = lseek(fh, 0, SEEK_END);
|
length = lseek(fh, 0, SEEK_END);
|
||||||
lseek(fh, 0, SEEK_SET);
|
lseek(fh, 0, SEEK_SET);
|
||||||
buf = malloc(length + strlen(new_name) + 10);
|
bufsize = 2*(length + strlen(new_name) + 10);
|
||||||
|
buf = malloc(bufsize);
|
||||||
assert(buf);
|
assert(buf);
|
||||||
read(fh, buf, length);
|
read(fh, buf, length);
|
||||||
buf[length] = 0;
|
buf[length] = 0;
|
||||||
@ -8934,12 +8977,7 @@ int rename_logbook(LOGBOOK * lbs, char *new_name)
|
|||||||
strlcat(p1, buf2, length + strlen(new_name) + 1);
|
strlcat(p1, buf2, length + strlen(new_name) + 1);
|
||||||
free(buf2);
|
free(buf2);
|
||||||
|
|
||||||
#ifdef OS_UNIX
|
adjust_crlf(buf, bufsize);
|
||||||
|
|
||||||
/* under unix, convert CRLF to CR */
|
|
||||||
remove_crlf(buf);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
lseek(fh, 0, SEEK_SET);
|
lseek(fh, 0, SEEK_SET);
|
||||||
i = write(fh, buf, strlen(buf));
|
i = write(fh, buf, strlen(buf));
|
||||||
@ -8969,7 +9007,7 @@ int rename_logbook(LOGBOOK * lbs, char *new_name)
|
|||||||
|
|
||||||
int create_logbook(LOGBOOK * oldlbs, char *logbook, char *templ)
|
int create_logbook(LOGBOOK * oldlbs, char *logbook, char *templ)
|
||||||
{
|
{
|
||||||
int fh, i, length, templ_length;
|
int fh, i, length, bufsize, templ_length;
|
||||||
char *buf, *p1, *p2, str[256];
|
char *buf, *p1, *p2, str[256];
|
||||||
|
|
||||||
fh = open(config_file, O_RDWR | O_BINARY, 644);
|
fh = open(config_file, O_RDWR | O_BINARY, 644);
|
||||||
@ -8987,7 +9025,8 @@ int create_logbook(LOGBOOK * oldlbs, char *logbook, char *templ)
|
|||||||
/* read previous contents */
|
/* read previous contents */
|
||||||
length = lseek(fh, 0, SEEK_END);
|
length = lseek(fh, 0, SEEK_END);
|
||||||
lseek(fh, 0, SEEK_SET);
|
lseek(fh, 0, SEEK_SET);
|
||||||
buf = malloc(2 * length + 1);
|
bufsize = 2*(2 * length + 1);
|
||||||
|
buf = malloc(bufsize);
|
||||||
assert(buf);
|
assert(buf);
|
||||||
read(fh, buf, length);
|
read(fh, buf, length);
|
||||||
buf[length] = 0;
|
buf[length] = 0;
|
||||||
@ -9031,12 +9070,8 @@ int create_logbook(LOGBOOK * oldlbs, char *logbook, char *templ)
|
|||||||
strncpy(p2, p1, templ_length);
|
strncpy(p2, p1, templ_length);
|
||||||
p2[templ_length] = 0;
|
p2[templ_length] = 0;
|
||||||
}
|
}
|
||||||
#ifdef OS_UNIX
|
|
||||||
|
|
||||||
/* under unix, convert CRLF to CR */
|
adjust_crlf(buf, bufsize);
|
||||||
remove_crlf(buf);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
lseek(fh, 0, SEEK_SET);
|
lseek(fh, 0, SEEK_SET);
|
||||||
i = write(fh, buf, strlen(buf));
|
i = write(fh, buf, strlen(buf));
|
||||||
@ -9067,6 +9102,7 @@ int create_logbook(LOGBOOK * oldlbs, char *logbook, char *templ)
|
|||||||
int save_config(char *buffer, char *error)
|
int save_config(char *buffer, char *error)
|
||||||
{
|
{
|
||||||
int fh, i;
|
int fh, i;
|
||||||
|
char *buf;
|
||||||
|
|
||||||
error[0] = 0;
|
error[0] = 0;
|
||||||
|
|
||||||
@ -9077,15 +9113,13 @@ int save_config(char *buffer, char *error)
|
|||||||
strcat(error, strerror(errno));
|
strcat(error, strerror(errno));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#ifdef OS_UNIX
|
|
||||||
|
|
||||||
/* under unix, convert CRLF to CR */
|
buf = malloc(strlen(buffer)*2);
|
||||||
remove_crlf(buffer);
|
strlcpy(buf, buffer, strlen(buffer)*2);
|
||||||
|
adjust_crlf(buf, strlen(buffer)*2);
|
||||||
|
|
||||||
#endif
|
i = write(fh, buf, strlen(buf));
|
||||||
|
if (i < (int) strlen(buf)) {
|
||||||
i = write(fh, buffer, strlen(buffer));
|
|
||||||
if (i < (int) strlen(buffer)) {
|
|
||||||
sprintf(error, loc("Cannot write to <b>%s</b>"), config_file);
|
sprintf(error, loc("Cannot write to <b>%s</b>"), config_file);
|
||||||
strcat(error, ": ");
|
strcat(error, ": ");
|
||||||
strcat(error, strerror(errno));
|
strcat(error, strerror(errno));
|
||||||
@ -11523,7 +11557,7 @@ int adjust_config(char *url)
|
|||||||
/* read previous contents */
|
/* read previous contents */
|
||||||
length = lseek(fh, 0, SEEK_END);
|
length = lseek(fh, 0, SEEK_END);
|
||||||
lseek(fh, 0, SEEK_SET);
|
lseek(fh, 0, SEEK_SET);
|
||||||
buf = malloc(length + 1000);
|
buf = malloc(2*length + 1000);
|
||||||
assert(buf);
|
assert(buf);
|
||||||
read(fh, buf, length);
|
read(fh, buf, length);
|
||||||
buf[length] = 0;
|
buf[length] = 0;
|
||||||
@ -11577,12 +11611,8 @@ int adjust_config(char *url)
|
|||||||
|
|
||||||
eputs("Option \"URL = xxx\" has been outcommented from config file.");
|
eputs("Option \"URL = xxx\" has been outcommented from config file.");
|
||||||
}
|
}
|
||||||
#ifdef OS_UNIX
|
|
||||||
|
|
||||||
/* under unix, convert CRLF to CR */
|
adjust_crlf(buf, 2*length + 1000);
|
||||||
remove_crlf(buf);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
lseek(fh, 0, SEEK_SET);
|
lseek(fh, 0, SEEK_SET);
|
||||||
i = write(fh, buf, strlen(buf));
|
i = write(fh, buf, strlen(buf));
|
||||||
@ -11608,7 +11638,7 @@ int adjust_config(char *url)
|
|||||||
|
|
||||||
void receive_pwdfile(LOGBOOK * lbs, char *server, char *error_str)
|
void receive_pwdfile(LOGBOOK * lbs, char *server, char *error_str)
|
||||||
{
|
{
|
||||||
char str[256], pwd[256], url[256], *buffer, *p;
|
char str[256], pwd[256], url[256], *buffer, *buf, *p;
|
||||||
int i, status, version, fh;
|
int i, status, version, fh;
|
||||||
|
|
||||||
error_str[0] = pwd[0] = 0;
|
error_str[0] = pwd[0] = 0;
|
||||||
@ -11684,7 +11714,7 @@ void receive_pwdfile(LOGBOOK * lbs, char *server, char *error_str)
|
|||||||
if (strstr(buffer, "?wusr=") || strstr(buffer, "?wpwd="))
|
if (strstr(buffer, "?wusr=") || strstr(buffer, "?wpwd="))
|
||||||
eprintf("\nInvalid username or password.");
|
eprintf("\nInvalid username or password.");
|
||||||
|
|
||||||
if (strstr(p, loc("Please login")) == NULL && strstr(p, "GetPwdFile"))
|
if (strstr(p, loc("Please login")) == NULL && strstr(p, "GetPwdFile") && isparam("unm"))
|
||||||
eprintf("\nUser \"%s\" has no admin rights on remote server.",
|
eprintf("\nUser \"%s\" has no admin rights on remote server.",
|
||||||
getparam("unm"));
|
getparam("unm"));
|
||||||
|
|
||||||
@ -11709,24 +11739,27 @@ void receive_pwdfile(LOGBOOK * lbs, char *server, char *error_str)
|
|||||||
|
|
||||||
|
|
||||||
getcfg(lbs->name, "Password file", str, sizeof(str));
|
getcfg(lbs->name, "Password file", str, sizeof(str));
|
||||||
fh = open(str, O_CREAT | O_RDWR, 0644);
|
fh = open(str, O_CREAT | O_RDWR | O_BINARY, 0644);
|
||||||
if (fh < 0) {
|
if (fh < 0) {
|
||||||
sprintf(error_str, loc("Cannot open file <b>%s</b>"), str);
|
sprintf(error_str, loc("Cannot open file <b>%s</b>"), str);
|
||||||
strcat(error_str, ": ");
|
strcat(error_str, ": ");
|
||||||
strcat(error_str, strerror(errno));
|
strcat(error_str, strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#ifdef OS_UNIX
|
|
||||||
/* under unix, convert CRLF to CR */
|
|
||||||
remove_crlf(buffer);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
i = write(fh, p, strlen(p));
|
buf = malloc(2*strlen(p));
|
||||||
if (i < (int) strlen(p)) {
|
assert(buf);
|
||||||
|
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);
|
sprintf(error_str, loc("Cannot write to <b>%s</b>"), str);
|
||||||
strcat(error_str, ": ");
|
strcat(error_str, ": ");
|
||||||
strcat(error_str, strerror(errno));
|
strcat(error_str, strerror(errno));
|
||||||
close(fh);
|
close(fh);
|
||||||
|
free(buf);
|
||||||
|
free(buffer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -11734,6 +11767,7 @@ void receive_pwdfile(LOGBOOK * lbs, char *server, char *error_str)
|
|||||||
|
|
||||||
close(fh);
|
close(fh);
|
||||||
|
|
||||||
|
free(buf);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21063,15 +21097,32 @@ int main(int argc, char *argv[])
|
|||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
eprintf("\nRetrieve remote password files? [y]/n: ");
|
eprintf("\nRetrieve remote password files? [y]/n: ");
|
||||||
fgets(str, sizeof(str), stdin);
|
fgets(str, sizeof(str), stdin);
|
||||||
if (str[0] != 'n' && str[0] != 'N') {
|
if (str[0] != 'n' && str[0] != 'N')
|
||||||
for (i = n = 0; lb_list[i].name[0]; i++)
|
for (i = n = 0; lb_list[i].name[0]; i++) {
|
||||||
|
|
||||||
|
if (lb_list[i].top_group[0])
|
||||||
|
setcfg_topgroup(lb_list[i].top_group);
|
||||||
|
else
|
||||||
|
setcfg_topgroup("");
|
||||||
|
|
||||||
if (getcfg(lb_list[i].name, "Password file", file_name, sizeof(file_name))) {
|
if (getcfg(lb_list[i].name, "Password file", file_name, sizeof(file_name))) {
|
||||||
|
|
||||||
/* check if this file has not already been retrieved */
|
/* check if this file has not already been retrieved */
|
||||||
for (j = 0; j < i; j++)
|
for (j = 0; j < i; j++) {
|
||||||
|
if (lb_list[j].top_group[0])
|
||||||
|
setcfg_topgroup(lb_list[j].top_group);
|
||||||
|
else
|
||||||
|
setcfg_topgroup("");
|
||||||
|
|
||||||
if (getcfg(lb_list[j].name, "Password file", str, sizeof(str)) &&
|
if (getcfg(lb_list[j].name, "Password file", str, sizeof(str)) &&
|
||||||
stricmp(file_name, str) == 0)
|
stricmp(file_name, str) == 0)
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lb_list[i].top_group[0])
|
||||||
|
setcfg_topgroup(lb_list[i].top_group);
|
||||||
|
else
|
||||||
|
setcfg_topgroup("");
|
||||||
|
|
||||||
if (j == i) {
|
if (j == i) {
|
||||||
receive_pwdfile(&lb_list[i], clone_url, error_str);
|
receive_pwdfile(&lb_list[i], clone_url, error_str);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user