4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
30 #include <sys/types.h>
32 #include <sys/param.h>
45 #define CANTCD "can't change directory to the at directory"
46 #define NOREADDIR "can't read the at directory"
48 extern int audit_cron_is_anc_name(char *);
54 while (isdigit(**ptr
)) {
55 n
= n
*10 + (**ptr
- '0');
61 static int dom
[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
64 days_btwn(int m1
, int d1
, int y1
, int m2
, int d2
, int y2
)
67 * calculate the number of "full" days in between
68 * m1/d1/y1 and m2/d2/y2.
69 * NOTE: there should not be more than a year separation in the
70 * dates. also, m should be in 0 to 11, and d should be in 1 to 31.
76 if ((m1
== m2
) && (d1
== d2
) && (y1
== y2
))
78 if ((m1
== m2
) && (d1
< d2
)) {
80 * In case of d2==29 ,d1==28 and m1==m2==Feb and year is not
81 * a leap year, this function should return the days till the
82 * the next Feb 29.See Bug 4257355.
84 if (d2
> days_in_mon(m2
, y2
)) {
86 for (p
= 1; ! isleap(y2
+YEAR
+p
); p
++)
88 return (p
*365 + d2
-d1
-1);
92 /* the remaining dates are on different months */
93 days
= (days_in_mon(m1
, y1
)-d1
) + (d2
-1);
98 days
+= days_in_mon(m
, y1
);
105 days_in_mon(int m
, int y
)
108 * returns the number of days in month m of year y
109 * NOTE: m should be in the range 0 to 11
111 return (dom
[m
] + (((m
== 1) && isleap(y
+ YEAR
)) ? 1 : 0));
119 if ((p
= malloc(size
)) == NULL
) {
127 xcalloc(size_t nElements
, size_t size
)
131 if ((p
= calloc(nElements
, size
)) == NULL
) {
139 xstrdup(const char *str
)
145 p
= xmalloc(len
+ 1);
146 (void) memcpy(p
, str
, len
);
153 cron_sendmsg(char action
, char *login
, char *fname
, char etype
)
155 static int msgfd
= -2;
156 struct message
*pmsg
, msgbuf
;
159 (void) memset(&msgbuf
, 0, sizeof (msgbuf
));
162 if ((msgfd
= open(FIFO
, O_WRONLY
|O_NDELAY
)) < 0) {
163 if (errno
== ENXIO
|| errno
== ENOENT
)
164 (void) fprintf(stderr
, gettext("cron may not"
165 " be running - call your system"
166 " administrator\n"));
168 (void) fprintf(stderr
, gettext(
169 "error in message queue open\n"));
174 pmsg
->action
= action
;
175 (void) strlcpy(pmsg
->fname
, fname
, FLEN
);
176 (void) strlcpy(pmsg
->logname
, login
, LLEN
);
177 if ((i
= write(msgfd
, pmsg
, sizeof (struct message
))) < 0)
178 (void) fprintf(stderr
, gettext("error in message send\n"));
179 else if (i
!= sizeof (struct message
))
180 (void) fprintf(stderr
, gettext(
181 "error in message send: Premature EOF\n"));
188 static char msg_buf
[32];
190 msg
= strerror(errnum
);
193 (void) snprintf(msg_buf
, sizeof (msg_buf
),
194 gettext("Error %d"), errnum
);
201 filewanted(struct dirent
*direntry
)
206 p
= direntry
->d_name
;
208 if (p
== direntry
->d_name
)
209 return (0); /* didn't start with a number */
211 return (0); /* followed by a period */
213 if (c
< 'a' || c
> 'z')
214 return (0); /* followed by a queue name */
215 if (audit_cron_is_anc_name(direntry
->d_name
))
221 isvalid_shell(const char *shell
)
226 while ((t
= getusershell()) != NULL
) {
227 if (strcmp(t
, shell
) == 0) {
237 isvalid_dir(const char *dir
)
239 char *cwd
= getcwd(NULL
, 0);
241 if (dir
[0] != '/' || chdir(dir
) == -1) {