* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: convert-fcrontab.c,v 1.15 2002-11-01 18:17:39 thib Exp $ */
+ /* $Id: convert-fcrontab.c,v 1.16 2002-11-17 13:13:52 thib Exp $ */
#include "global.h"
#include "log.h"
#include "subs.h"
-char rcs_info[] = "$Id: convert-fcrontab.c,v 1.15 2002-11-01 18:17:39 thib Exp $";
+char rcs_info[] = "$Id: convert-fcrontab.c,v 1.16 2002-11-17 13:13:52 thib Exp $";
void info(void);
void usage(void);
pid_t daemon_pid = 0;
char debug_opt = 0;
char dosyslog = 1;
-time_t t_save = 0;
-struct stat file_stat;
void
info(void)
}
-/* this function is called in save.c */
-int
-save_one_file(cf_t *file, char *path)
-/* save a given file to disk */
-{
- int fd;
-
- fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC);
- if ( fd == -1 ) {
- error_e("Could not open %s", path);
- return ERR;
- }
-
- if ( fchown(fd, file_stat.st_uid, file_stat.st_gid) != 0 ) {
- error_e("Could not fchown %s", path);
- return ERR;
- }
-
- if ( fchmod(fd, file_stat.st_mode) != 0 ) {
- error_e("Could not fchmod %s", path);
- return ERR;
- }
-
- if ( write_file_to_disk(fd, file, t_save) == ERR ) {
- close(fd);
- remove(path);
- return ERR;
- }
-
- close(fd);
-
- return OK;
-
-}
-
void
convert_file(char *file_name)
/* this functions is a mix of read_file() from version 1.0.3 and save_file(),
env_t *env = NULL;
FILE *f = NULL;
char buf[LINE_LEN];
+ time_t t_save = 0;
+ struct stat file_stat;
explain("Converting %s's fcrontab ...", file_name);
if ( rename(buf, file_name) != 0 )
error_e("Could not rename %s to %s", buf, file_name);
- save_file_safe(file, file_name, "convert-fcrontab");
+ save_file_safe(file, file_name, "convert-fcrontab", file_stat.st_uid,
+ file_stat.st_gid, t_save);
delete_file(file);
}
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: save.c,v 1.4 2002-11-01 18:17:44 thib Exp $ */
+ /* $Id: save.c,v 1.5 2002-11-17 13:13:55 thib Exp $ */
#include "global.h"
#include "save.h"
int save_strn(int fd, short int type, char *str, short int size, char *write_buf,
int *buf_used);
int save_lint(int fd, short int type, long int value, char *write_buf, int *buf_used);
-extern int save_one_file(cf_t *file, char *filename);
+int save_one_file(cf_t *file, char *filename, uid_t own_uid, gid_t own_gid,
+ time_t save_date);
int
int
-save_file_safe(cf_t *file, char *final_path, char *prog_name)
+save_one_file(cf_t *file, char *filename, uid_t own_uid, gid_t own_gid, time_t save_date)
+/* save a given file to disk */
+{
+ int fd;
+
+ /* open file */
+ fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC, S_IRUSR|S_IWUSR);
+ if ( fd == -1 ) {
+ error_e("Could not open %s", filename);
+ return ERR;
+ }
+
+ if (fchown(fd, own_uid, own_gid) != 0) {
+ error_e("Could not fchown %s to uid:%d gid:%d", filename, own_uid, own_gid);
+ close(fd);
+ remove(filename);
+ return ERR;
+ }
+
+ /* save file : */
+ if ( write_file_to_disk(fd, file, save_date) == ERR ) {
+ close(fd);
+ remove(filename);
+ return ERR;
+ }
+
+ close(fd);
+
+ return OK;
+}
+
+
+int
+save_file_safe(cf_t *file, char *final_path, char *prog_name, uid_t own_uid,
+ gid_t own_gid, time_t save_date)
/* save a file to a temp path, and then rename it (safely) to avoid loss of data
* if a system crash, hardware failure, etc happens. */
{
sizeof(temp_path)-sizeof(tmp_str) : final_path_len;
strcpy(&temp_path[temp_path_index], ".tmp");
- /* save_one_file() is defined in conf.c for fcron, fileconf.c for fcrondyn */
- if ( save_one_file(file, temp_path) == OK ) {
+ if ( save_one_file(file, temp_path, own_uid, own_gid, save_date) == OK ) {
if ( rename(temp_path, final_path) != 0 ) {
error_e("Cannot rename %s to %s", temp_path, final_path);
error("%s will try to save the name to its definitive filename "
"directly.", prog_name);
error("If there is an error, root may consider to replace %s (which is "
"a valid copy) by %s manually.", final_path, temp_path);
- if ( save_one_file(file, final_path) == ERR )
+ if ( save_one_file(file, final_path, own_uid, own_gid, save_date) == ERR )
return ERR;
}
}
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: save.h,v 1.8 2002-11-01 18:17:59 thib Exp $ */
+ /* $Id: save.h,v 1.9 2002-11-17 13:14:02 thib Exp $ */
#ifndef __SAVE_H__
#define __SAVE_H__
/* functions defined by save.c */
extern int write_file_to_disk(int fd, struct cf_t *file, time_t time_date);
-extern int save_file_safe(cf_t *file, char *final_path, char *fcron_suffix);
+extern int save_file_safe(cf_t *file, char *final_path, char *prog_name, uid_t own_uid,
+ gid_t own_gid, time_t save_date);
/* here is the format fcron(tab) uses to save the fcrontabs :