mirror of
https://gitea.psi.ch/ELOG/elog.git
synced 2026-09-16 21:26:27 +00:00
Don't create PID file when creating/changing passwords
SVN revision: 437
This commit is contained in:
parent
ca97cd36ff
commit
0ed4ab425f
132
src/elogd.c
132
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.45 2003/03/10 11:56:07 midas
|
||||||
|
Don't create PID file when creating/changing passwords
|
||||||
|
|
||||||
Revision 1.44 2003/03/10 08:08:11 midas
|
Revision 1.44 2003/03/10 08:08:11 midas
|
||||||
Fallback to elog/elog added
|
Fallback to elog/elog added
|
||||||
|
|
||||||
@ -2085,7 +2088,11 @@ struct tm tms;
|
|||||||
fh = open(file_name, O_RDWR | O_BINARY, 0644);
|
fh = open(file_name, O_RDWR | O_BINARY, 0644);
|
||||||
|
|
||||||
if (fh < 0)
|
if (fh < 0)
|
||||||
|
{
|
||||||
|
sprintf(str, "Cannot open file \"%s\":", file_name);
|
||||||
|
perror(str);
|
||||||
return EL_FILE_ERROR;
|
return EL_FILE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
/* read file into buffer */
|
/* read file into buffer */
|
||||||
length = lseek(fh, 0, SEEK_END);
|
length = lseek(fh, 0, SEEK_END);
|
||||||
@ -12595,82 +12602,85 @@ usage:
|
|||||||
#ifdef OS_UNIX
|
#ifdef OS_UNIX
|
||||||
/* create PID file if given as command line parameter or if running under root */
|
/* create PID file if given as command line parameter or if running under root */
|
||||||
|
|
||||||
if (geteuid() == 0 || pidfile[0])
|
if (!read_pwd[0] && !write_pwd[0] && !admin_pwd[0])
|
||||||
{
|
{
|
||||||
int fd;
|
if (geteuid() == 0 || pidfile[0])
|
||||||
char buf[20];
|
|
||||||
struct stat finfo;
|
|
||||||
|
|
||||||
if (pidfile[0] == 0)
|
|
||||||
strcpy(pidfile, PIDFILE);
|
|
||||||
|
|
||||||
/* check if file exists */
|
|
||||||
if (stat(pidfile, &finfo) >= 0)
|
|
||||||
{
|
{
|
||||||
printf("File \"%s\" exists, using \"%s.%d\" instead.\n", pidfile, pidfile, tcp_port);
|
int fd;
|
||||||
sprintf(pidfile + strlen(pidfile), ".%d", tcp_port);
|
char buf[20];
|
||||||
|
struct stat finfo;
|
||||||
|
|
||||||
/* check again for the new name */
|
if (pidfile[0] == 0)
|
||||||
|
strcpy(pidfile, PIDFILE);
|
||||||
|
|
||||||
|
/* check if file exists */
|
||||||
if (stat(pidfile, &finfo) >= 0)
|
if (stat(pidfile, &finfo) >= 0)
|
||||||
{
|
{
|
||||||
/* never overwrite a file */
|
printf("File \"%s\" exists, using \"%s.%d\" instead.\n", pidfile, pidfile, tcp_port);
|
||||||
printf("Refuse to overwrite existing file \"%s\".\n", pidfile);
|
sprintf(pidfile + strlen(pidfile), ".%d", tcp_port);
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fd = open(pidfile, O_CREAT | O_RDWR, 0644);
|
/* check again for the new name */
|
||||||
if (fd < 0)
|
if (stat(pidfile, &finfo) >= 0)
|
||||||
{
|
|
||||||
sprintf(str, "Error creating pid file \"%s\"", pidfile);
|
|
||||||
perror(str);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
sprintf(buf, "%d\n", (int)getpid());
|
|
||||||
if (write(fd, buf, strlen(buf)) == -1)
|
|
||||||
{
|
|
||||||
sprintf(str, "Error writing to pid file \"%s\"", pidfile);
|
|
||||||
perror(str);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* save gid/uid to regain later for deleting the PID file */
|
|
||||||
orig_gid = getegid();
|
|
||||||
orig_uid = geteuid();
|
|
||||||
|
|
||||||
/* give up root privilege */
|
|
||||||
|
|
||||||
if (geteuid() == 0)
|
|
||||||
{
|
|
||||||
if (!getcfg("global", "Grp", str) || setgroup(str) < 0)
|
|
||||||
{
|
|
||||||
printf("Falling back to default group \"elog\"\n");
|
|
||||||
if (setgroup("elog") < 0)
|
|
||||||
{
|
|
||||||
printf("Falling back to default group \"%s\"\n", DEFAULT_GROUP);
|
|
||||||
if (setgroup(DEFAULT_GROUP) < 0)
|
|
||||||
{
|
{
|
||||||
printf("Refuse to run as setgid root.\n");
|
/* never overwrite a file */
|
||||||
printf("Please consider to define a Grp statement in configuration file\n");
|
printf("Refuse to overwrite existing file \"%s\".\n", pidfile);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fd = open(pidfile, O_CREAT | O_RDWR, 0644);
|
||||||
|
if (fd < 0)
|
||||||
|
{
|
||||||
|
sprintf(str, "Error creating pid file \"%s\"", pidfile);
|
||||||
|
perror(str);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(buf, "%d\n", (int)getpid());
|
||||||
|
if (write(fd, buf, strlen(buf)) == -1)
|
||||||
|
{
|
||||||
|
sprintf(str, "Error writing to pid file \"%s\"", pidfile);
|
||||||
|
perror(str);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!getcfg("global", "Usr", str) || setuser(str) < 0)
|
/* save gid/uid to regain later for deleting the PID file */
|
||||||
|
orig_gid = getegid();
|
||||||
|
orig_uid = geteuid();
|
||||||
|
|
||||||
|
/* give up root privilege */
|
||||||
|
|
||||||
|
if (geteuid() == 0)
|
||||||
{
|
{
|
||||||
printf("Falling back to default user \"elog\"\n");
|
if (!getcfg("global", "Grp", str) || setgroup(str) < 0)
|
||||||
if (setuser("elog") < 0)
|
|
||||||
{
|
{
|
||||||
printf("Falling back to default user \"%s\"\n", DEFAULT_USER);
|
printf("Falling back to default group \"elog\"\n");
|
||||||
if (setuser(DEFAULT_USER) < 0)
|
if (setgroup("elog") < 0)
|
||||||
{
|
{
|
||||||
printf("Refuse to run as setuid root.\n");
|
printf("Falling back to default group \"%s\"\n", DEFAULT_GROUP);
|
||||||
printf("Please consider to define a Usr statement in configuration file\n");
|
if (setgroup(DEFAULT_GROUP) < 0)
|
||||||
exit(EXIT_FAILURE);
|
{
|
||||||
|
printf("Refuse to run as setgid root.\n");
|
||||||
|
printf("Please consider to define a Grp statement in configuration file\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!getcfg("global", "Usr", str) || setuser(str) < 0)
|
||||||
|
{
|
||||||
|
printf("Falling back to default user \"elog\"\n");
|
||||||
|
if (setuser("elog") < 0)
|
||||||
|
{
|
||||||
|
printf("Falling back to default user \"%s\"\n", DEFAULT_USER);
|
||||||
|
if (setuser(DEFAULT_USER) < 0)
|
||||||
|
{
|
||||||
|
printf("Refuse to run as setuid root.\n");
|
||||||
|
printf("Please consider to define a Usr statement in configuration file\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user