This source file includes following definitions.
- log_error
- free_user
- load_user
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 #include "config.h"
26
27 #include <errno.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <unistd.h>
31
32 #include "funcs.h"
33 #include "globals.h"
34
35 static const char *FileName;
36
37 static void
38 log_error (const char *msg)
39 {
40 log_it ("CRON", getpid (), msg, FileName, 0);
41 }
42
43 void
44 free_user (user * u) {
45 entry *e, *ne;
46
47 if (!u) {
48 return;
49 }
50
51 free(u->name);
52 free(u->tabname);
53 for (e = u->crontab; e != NULL; e = ne) {
54 ne = e->next;
55 free_entry(e);
56 }
57 #ifdef WITH_SELINUX
58 free_security_context(&(u->scontext));
59 #endif
60 free(u);
61 }
62
63 user *
64 load_user (int crontab_fd, struct passwd *pw, const char *uname,
65 const char *fname, const char *tabname) {
66 char envstr[MAX_ENVSTR];
67 FILE *file;
68 user *u;
69 entry *e;
70 int status = TRUE, save_errno = 0;
71 char **envp = NULL, **tenvp;
72
73 if (!(file = fdopen(crontab_fd, "r"))) {
74 save_errno = errno;
75 log_it(uname, getpid (), "FAILED", "fdopen on crontab_fd in load_user",
76 save_errno);
77 close(crontab_fd);
78 return (NULL);
79 }
80
81 Debug(DPARS, ("load_user()\n"));
82
83
84 if ((u = (user *) malloc (sizeof (user))) == NULL) {
85 save_errno = errno;
86 goto done;
87 }
88 memset(u, 0, sizeof(*u));
89
90 if (((u->name = strdup(fname)) == NULL)
91 || ((u->tabname = strdup(tabname)) == NULL)) {
92 save_errno = errno;
93 goto done;
94 }
95
96 u->system = pw == NULL;
97
98
99
100 if ((envp = env_init()) == NULL) {
101 save_errno = errno;
102 goto done;
103 }
104
105 if (env_set_from_environ(&envp) == FALSE) {
106 save_errno = errno;
107 goto done;
108 }
109
110 #ifdef WITH_SELINUX
111 if (get_security_context(pw == NULL ? NULL : uname,
112 crontab_fd, &u->scontext, tabname) != 0) {
113 goto done;
114 }
115 #endif
116
117
118 while ((status = load_env (envstr, file)) >= OK) {
119 switch (status) {
120 case FALSE:
121 FileName = tabname;
122 e = load_entry(file, log_error, pw, envp);
123 if (e) {
124 e->next = u->crontab;
125 u->crontab = e;
126 }
127 break;
128 case TRUE:
129 if ((tenvp = env_set (envp, envstr)) == NULL) {
130 save_errno = errno;
131 goto done;
132 }
133 envp = tenvp;
134 break;
135 }
136 }
137
138 done:
139 if (status == TRUE) {
140 log_it(uname, getpid(), "FAILED", "loading cron table",
141 save_errno);
142 free_user(u);
143 u = NULL;
144 }
145 if (envp)
146 env_free(envp);
147 fclose(file);
148 Debug(DPARS, ("...load_user() done\n"));
149 errno = save_errno;
150 return (u);
151 }