]> code.citadel.org Git - citadel.git/blobdiff - citadel/config.c
Networker: when a remote host fails to connect successfully add floodprotection.
[citadel.git] / citadel / config.c
index cc48c8d11c7f3a586e5650d178e0a01e04a2595c..5328e30369149a50d2c04939d0c6469b1557a17f 100644 (file)
@@ -42,9 +42,7 @@ void brand_new_installation_set_defaults(void) {
        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);
@@ -130,7 +128,8 @@ void get_config(void) {
                {
                        fprintf(stderr, 
                                "Warning: The config file %s has unexpected size. \n",
-                               file_citadel_config);
+                               file_citadel_config
+                       );
                }
                fclose(cfp);
        }
@@ -206,15 +205,16 @@ void get_config(void) {
 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));
 }