Blame SOURCES/cronie-1.4.11-refresh-users.patch

304494
diff -up cronie-1.4.11/src/cron.c.refresh-users cronie-1.4.11/src/cron.c
304494
--- cronie-1.4.11/src/cron.c.refresh-users	2013-07-18 14:27:08.000000000 +0200
304494
+++ cronie-1.4.11/src/cron.c	2015-04-21 14:43:11.205438697 +0200
304494
@@ -525,7 +525,6 @@ static void find_jobs(int vtime, cron_db
304494
 	int minute, hour, dom, month, dow;
304494
 	user *u;
304494
 	entry *e;
304494
-	const char *uname;
304494
 
304494
 	/* The support for the job-specific timezones is not perfect. There will
304494
 	 * be jobs missed or run twice during the DST change in the job timezone.
304494
@@ -562,16 +561,11 @@ static void find_jobs(int vtime, cron_db
304494
 		 */
304494
 		for (u = db->head; u != NULL; u = u->next) {
304494
 		for (e = u->crontab; e != NULL; e = e->next) {
304494
-			Debug(DSCH | DEXT, ("user [%s:%ld:%ld:...] cmd=\"%s\"\n",
304494
-					e->pwd->pw_name, (long) e->pwd->pw_uid,
304494
-					(long) e->pwd->pw_gid, e->cmd));
304494
-				uname = e->pwd->pw_name;
304494
-			/* check if user exists in time of job is being run f.e. ldap */
304494
-			if (getpwnam(uname) != NULL) {
304494
 				time_t virtualSecond = (vtime - e->delay) * SECONDS_PER_MINUTE;
304494
 				time_t virtualGMTSecond = virtualSecond - vGMToff;
304494
 				job_tz = env_get("CRON_TZ", e->envp);
304494
 				maketime(job_tz, orig_tz);
304494
+
304494
 				/* here we test whether time is NOW */
304494
 				if (bit_test(e->minute, minute) &&
304494
 					bit_test(e->hour, hour) &&
304494
@@ -591,10 +585,9 @@ static void find_jobs(int vtime, cron_db
304494
 							!(e->flags & (MIN_STAR | HR_STAR))) ||
304494
 						(doWild && (e->flags & (MIN_STAR | HR_STAR))))
304494
 						job_add(e, u);	/*will add job, if it isn't in queue already for NOW. */
304494
-				}
304494
-			}
304494
-		}
304494
-	}
304494
+			        }
304494
+		        }
304494
+	        }
304494
 	if (orig_tz != NULL)
304494
 		setenv("TZ", orig_tz, 1);
304494
 	else
304494
diff -up cronie-1.4.11/src/database.c.refresh-users cronie-1.4.11/src/database.c
304494
--- cronie-1.4.11/src/database.c.refresh-users	2013-07-18 14:27:08.000000000 +0200
304494
+++ cronie-1.4.11/src/database.c	2015-04-21 15:20:03.768846359 +0200
304494
@@ -152,10 +152,41 @@ check_orphans(cron_db *db) {
304494
 	}
304494
 }
304494
 
304494
+static int
304494
+find_orphan(const char *uname, const char *fname, const char *tabname) {
304494
+	orphan *o;
304494
+
304494
+	for (o = orphans; o != NULL; o = o->next) {
304494
+		if (uname && o->uname) {
304494
+			if (strcmp(uname, o->uname) != 0)
304494
+				continue;
304494
+		} else if (uname != o->uname)
304494
+			continue;
304494
+
304494
+		if (fname && o->fname) {
304494
+			if (strcmp(fname, o->fname) != 0)
304494
+				continue;
304494
+		} else if (fname != o->fname)
304494
+			continue;
304494
+
304494
+		if (tabname && o->tabname) {
304494
+			if (strcmp(tabname, o->tabname) != 0)
304494
+				continue;
304494
+		} else if (tabname != o->tabname)
304494
+			continue;
304494
+		return 1;
304494
+	}
304494
+
304494
+	return 0;
304494
+}
304494
+
304494
 static void
304494
 add_orphan(const char *uname, const char *fname, const char *tabname) {
304494
 	orphan *o;
304494
 
304494
+	if (find_orphan(uname, fname, tabname))
304494
+		return;
304494
+
304494
 	o = calloc(1, sizeof(*o));
304494
 	if (o == NULL)
304494
 		return;
304494
diff -up cronie-1.4.11/src/entry.c.refresh-users cronie-1.4.11/src/entry.c
304494
--- cronie-1.4.11/src/entry.c.refresh-users	2013-07-18 14:27:08.000000000 +0200
304494
+++ cronie-1.4.11/src/entry.c	2015-04-21 14:40:13.473310662 +0200
304494
@@ -99,6 +99,7 @@ entry *load_entry(FILE * file, void (*er
304494
 	char envstr[MAX_ENVSTR];
304494
 	char **tenvp;
304494
 	char *p;
304494
+	struct passwd temppw;
304494
 
304494
 	Debug(DPARS, ("load_entry()...about to eat comments\n"));
304494
 
304494
@@ -286,11 +287,15 @@ entry *load_entry(FILE * file, void (*er
304494
 
304494
 		pw = getpwnam(username);
304494
 		if (pw == NULL) {
304494
-			ecode = e_username;
304494
-			goto eof;
304494
-		}
304494
-		Debug(DPARS, ("load_entry()...uid %ld, gid %ld\n",
304494
+			Debug(DPARS, ("load_entry()...unknown user entry\n"));
304494
+			memset(&temppw, 0, sizeof (temppw));
304494
+			temppw.pw_name = username;
304494
+			temppw.pw_passwd = "";
304494
+			pw = &temppw;
304494
+		} else {
304494
+			Debug(DPARS, ("load_entry()...uid %ld, gid %ld\n",
304494
 				(long) pw->pw_uid, (long) pw->pw_gid));
304494
+		}
304494
 	}
304494
 
304494
 	if ((e->pwd = pw_dup(pw)) == NULL) {
304494
@@ -331,17 +336,11 @@ entry *load_entry(FILE * file, void (*er
304494
 		else
304494
 			log_it("CRON", getpid(), "ERROR", "can't set SHELL", 0);
304494
 	}
304494
-	if (!env_get("HOME", e->envp)) {
304494
-		if (glue_strings(envstr, sizeof envstr, "HOME", pw->pw_dir, '=')) {
304494
-			if ((tenvp = env_set(e->envp, envstr)) == NULL) {
304494
-				ecode = e_memory;
304494
-				goto eof;
304494
-			}
304494
-			e->envp = tenvp;
304494
-		}
304494
-		else
304494
-			log_it("CRON", getpid(), "ERROR", "can't set HOME", 0);
304494
+	if ((tenvp = env_update_home(e->envp, pw->pw_dir)) == NULL) {
304494
+		ecode = e_memory;
304494
+		goto eof;
304494
 	}
304494
+	e->envp = tenvp;
304494
 #ifndef LOGIN_CAP
304494
 	/* If login.conf is in used we will get the default PATH later. */
304494
 	if (ChangePath && !env_get("PATH", e->envp)) {
304494
diff -up cronie-1.4.11/src/env.c.refresh-users cronie-1.4.11/src/env.c
304494
--- cronie-1.4.11/src/env.c.refresh-users	2013-07-18 14:27:08.000000000 +0200
304494
+++ cronie-1.4.11/src/env.c	2015-04-21 14:40:13.473310662 +0200
304494
@@ -25,6 +25,7 @@
304494
 #include <errno.h>
304494
 #include <stdlib.h>
304494
 #include <string.h>
304494
+#include <sys/types.h>
304494
 #include <unistd.h>
304494
 
304494
 #include "globals.h"
304494
@@ -291,3 +292,19 @@ char *env_get(const char *name, char **e
304494
 	}
304494
 	return (NULL);
304494
 }
304494
+
304494
+char **env_update_home(char **envp, const char *dir) {
304494
+	char envstr[MAX_ENVSTR];
304494
+
304494
+	if (dir == NULL || *dir == '\0' || env_get("HOME", envp)) {
304494
+		return envp;
304494
+	}
304494
+
304494
+	if (glue_strings(envstr, sizeof envstr, "HOME", dir, '=')) {
304494
+		envp = env_set(envp, envstr);
304494
+	}			
304494
+	else
304494
+		log_it("CRON", getpid(), "ERROR", "can't set HOME", 0);
304494
+
304494
+	return envp;
304494
+}
304494
diff -up cronie-1.4.11/src/funcs.h.refresh-users cronie-1.4.11/src/funcs.h
304494
--- cronie-1.4.11/src/funcs.h.refresh-users	2013-07-18 14:27:08.000000000 +0200
304494
+++ cronie-1.4.11/src/funcs.h	2015-04-21 14:40:13.473310662 +0200
304494
@@ -82,7 +82,8 @@ char		*env_get(const char *, char **),
304494
 		*first_word(const char *, const char *),
304494
 		**env_init(void),
304494
 		**env_copy(char **),
304494
-		**env_set(char **, const char *);
304494
+		**env_set(char **, const char *),
304494
+		**env_update_home(char **, const char *);
304494
 
304494
 user		*load_user(int, struct passwd *, const char *, const char *, const char *),
304494
 		*find_user(cron_db *, const char *, const char *);
304494
diff -up cronie-1.4.11/src/job.c.refresh-users cronie-1.4.11/src/job.c
304494
--- cronie-1.4.11/src/job.c.refresh-users	2013-07-18 14:27:08.000000000 +0200
304494
+++ cronie-1.4.11/src/job.c	2015-04-21 14:40:13.474310685 +0200
304494
@@ -22,6 +22,11 @@
304494
 #include "config.h"
304494
 
304494
 #include <stdlib.h>
304494
+#include <pwd.h>
304494
+#include <errno.h>
304494
+#include <sys/types.h>
304494
+#include <unistd.h>
304494
+#include <string.h>
304494
 
304494
 #include "funcs.h"
304494
 #include "globals.h"
304494
@@ -36,12 +41,42 @@ static job *jhead = NULL, *jtail = NULL;
304494
 
304494
 void job_add(entry * e, user * u) {
304494
 	job *j;
304494
+	struct passwd *newpwd;
304494
+	struct passwd *temppwd;
304494
+	const char *uname;
304494
 
304494
 	/* if already on queue, keep going */
304494
 	for (j = jhead; j != NULL; j = j->next)
304494
 		if (j->e == e && j->u == u)
304494
 			return;
304494
 
304494
+	uname = e->pwd->pw_name;
304494
+	/* check if user exists in time of job is being run f.e. ldap */
304494
+	if ((temppwd = getpwnam(uname)) != NULL) {
304494
+		char **tenvp;
304494
+
304494
+		Debug(DSCH | DEXT, ("user [%s:%ld:%ld:...] cmd=\"%s\"\n",
304494
+				e->pwd->pw_name, (long) temppwd->pw_uid,
304494
+				(long) temppwd->pw_gid, e->cmd));
304494
+		if ((newpwd = pw_dup(temppwd)) == NULL) {
304494
+			log_it(uname, getpid(), "ERROR", "memory allocation failed", errno);
304494
+			return;
304494
+		}
304494
+		free(e->pwd);
304494
+		e->pwd = newpwd;
304494
+
304494
+		if ((tenvp = env_update_home(e->envp, e->pwd->pw_dir)) == NULL) {
304494
+			log_it(uname, getpid(), "ERROR", "memory allocation failed", errno);
304494
+			return;
304494
+		}
304494
+		e->envp = tenvp;
304494
+	} else {
304494
+		log_it(uname, getpid(), "ERROR", "getpwnam() failed",errno);
304494
+		Debug(DSCH | DEXT, ("%s:%d pid=%d time=%ld getpwnam(%s) failed errno=%d error=%s\n",
304494
+			__FILE__,__LINE__,getpid(),time(NULL),uname,errno,strerror(errno)));
304494
+		return;
304494
+	}
304494
+
304494
 	/* build a job queue element */
304494
 	if ((j = (job *) malloc(sizeof (job))) == NULL)
304494
 		return;