uname(&my_utsname);
/* set some sample/default values in place of blanks... */
- char c_nodename[256];
- safestrncpy(c_nodename, my_utsname.nodename, sizeof c_nodename);
- strtok(config.c_nodename, ".");
+ extract_token(config.c_nodename, my_utsname.nodename, 0, '.', sizeof config.c_nodename);
if (IsEmptyStr(config.c_fqdn) ) {
if ((he = gethostbyname(my_utsname.nodename)) != NULL) {
safestrncpy(config.c_fqdn, he->h_name, sizeof config.c_fqdn);
{
fprintf(stderr,
"Warning: The config file %s has unexpected size. \n",
- file_citadel_config);
+ file_citadel_config
+ );
}
fclose(cfp);
}
void put_config(void)
{
FILE *cfp;
- int rv;
-
- if ((cfp = fopen(file_citadel_config, "rb+")) == NULL)
- perror(file_citadel_config);
- else {
- rv = fwrite((char *) &config, sizeof(struct config), 1, cfp);
- if (rv == -1)
- syslog(LOG_EMERG, "Failed to write: %s [%s]\n",
- file_citadel_config, strerror(errno));
- fclose(cfp);
+ int blocks_written = 0;
+
+ if ((cfp = fopen(file_citadel_config, "w")) != NULL) {
+ blocks_written = fwrite((char *) &config, sizeof(struct config), 1, cfp);
+ if (blocks_written == 1) {
+ fclose(cfp);
+ chown(file_citadel_config, CTDLUID, (-1));
+ chmod(file_citadel_config, 0600);
+ return;
+ }
}
+ syslog(LOG_EMERG, "%s: %s", file_citadel_config, strerror(errno));
}