Tags: patch > When run as root, the pidfile should be in /var/run/ and only > there. There should be no need for a symlink into /tmp/. > > When run as another user, the pidfile can be in /tmp/ instead.
The following patch should fix this problem. Please consider for
inclusion.
Regards - Juergen
--- tleds.c.orig 2005-04-02 23:38:59.599658112 +0200
+++ tleds.c 2005-04-02 22:56:29.782289272 +0200
@@ -124,6 +124,7 @@
char *find_device_line(char *buffer, char *netDeviceName);
inline int find_max_VT();
pid_t get_old_pid();
+pid_t get_own_pid(char *fileName);
int get_sleeptime(int isDefinedByUser, char *interfaceName);
void handle_my_argvs(char **interfaceName, int *sleeptime,
int argc, char **argv);
@@ -625,12 +626,24 @@
int kill_old_process()
{
pid_t pid, pid2;
+ char *ownPidFileName;
- if (!(pid = get_old_pid())) {
+ /*
+ * We use get_own_pid() here as we don't want to
+ * kill foreign processes (or become vulnerable by
+ * forged pidfiles) when running as root.
+ */
+
+ if (geteuid())
+ ownPidFileName = pidFileName;
+ else
+ ownPidFileName = rootPidFileName; /* root */
+
+ if (!(pid = get_own_pid(ownPidFileName))) {
if (!opt_q) {
fprintf(stderr,
"Couldn't find what to kill.\n");
- perror(pidFileName);
+ perror(ownPidFileName);
}
return 1;
}
@@ -638,7 +651,7 @@
if (!opt_q)
printf("One moment...(3 secs)...\n");
sleep(3);
- if ((pid2 = get_old_pid())) {
+ if ((pid2 = get_own_pid(ownPidFileName))) {
if (!opt_q)
fprintf(stderr,
"PID: %d - Hmm...not sure if I succeeded in kill.\n",
@@ -717,12 +730,19 @@
perror(tmpPidFileName);
exit(1);
}
- if (!geteuid()) { /* EUID root */
- if (symlink(tmpPidFileName, pidFileName)) {
- perror(pidFileName);
- exit(1);
- }
- }
+}
+
+pid_t get_own_pid(char *fileName)
+{
+ FILE *pidFile;
+ long returnValue;
+
+ pidFile = fopen(fileName, "r");
+ if (!(pidFile))
+ return (pid_t) 0L;
+ fscanf(pidFile, "%ld", &returnValue);
+ fclose(pidFile);
+ return (pid_t) returnValue;
}
pid_t get_old_pid()
--
GPG A997BA7A | 87FC DA31 5F00 C885 0DC3 E28F BD0D 4B33 A997 BA7A
signature.asc
Description: Digital signature

