|
@@ -485,50 +485,15 @@ int write_userfile(int idx)
|
|
|
if (userlist == NULL || !conf.bot->hub)
|
|
if (userlist == NULL || !conf.bot->hub)
|
|
|
return 1; /* No point in saving userfile */
|
|
return 1; /* No point in saving userfile */
|
|
|
|
|
|
|
|
- FILE *f = NULL;
|
|
|
|
|
- char *new_userfile = NULL;
|
|
|
|
|
- size_t siz = strlen(userfile) + 4 + 1;
|
|
|
|
|
-
|
|
|
|
|
- new_userfile = (char *) my_calloc(1, siz);
|
|
|
|
|
- simple_snprintf(new_userfile, siz, "%s~new", userfile);
|
|
|
|
|
-
|
|
|
|
|
- f = fopen(new_userfile, "w");
|
|
|
|
|
- if (f == NULL) {
|
|
|
|
|
- putlog(LOG_MISC, "*", "ERROR writing user file.");
|
|
|
|
|
- free(new_userfile);
|
|
|
|
|
- return 2;
|
|
|
|
|
- }
|
|
|
|
|
- fchmod(fileno(f), S_IRUSR | S_IWUSR);
|
|
|
|
|
-
|
|
|
|
|
- char backup[DIRMAX] = "";
|
|
|
|
|
-
|
|
|
|
|
if (idx >= 0)
|
|
if (idx >= 0)
|
|
|
dprintf(idx, "Saving userfile...\n");
|
|
dprintf(idx, "Saving userfile...\n");
|
|
|
|
|
|
|
|
if (sort_users)
|
|
if (sort_users)
|
|
|
sort_userlist();
|
|
sort_userlist();
|
|
|
|
|
|
|
|
-
|
|
|
|
|
putlog(LOG_DEBUG, "@", "Writing user entries.");
|
|
putlog(LOG_DEBUG, "@", "Writing user entries.");
|
|
|
|
|
|
|
|
- if (real_writeuserfile(idx, userlist, f)) {
|
|
|
|
|
- putlog(LOG_MISC, "*", "ERROR writing user file. (%s)", strerror(ferror(f)));
|
|
|
|
|
- unlink(new_userfile);
|
|
|
|
|
- fclose(f);
|
|
|
|
|
- free(new_userfile);
|
|
|
|
|
- return 3;
|
|
|
|
|
- }
|
|
|
|
|
- fclose(f);
|
|
|
|
|
- putlog(LOG_DEBUG, "@", "Done writing userfile.");
|
|
|
|
|
- simple_snprintf(backup, sizeof backup, "%s/%s~", conf.datadir, userfile);
|
|
|
|
|
- copyfile(userfile, backup);
|
|
|
|
|
- movefile(new_userfile, userfile);
|
|
|
|
|
- free(new_userfile);
|
|
|
|
|
- return 0;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-/* Used by writeuserfile() and write_tmp_userfile() in share.c */
|
|
|
|
|
-int real_writeuserfile(int idx, const struct userrec *bu, FILE *f, bool compat) {
|
|
|
|
|
|
|
+ Tempfile *new_userfile = new Tempfile("userfile");
|
|
|
/* FIXME: REMOVE AFTER 1.2.14 */
|
|
/* FIXME: REMOVE AFTER 1.2.14 */
|
|
|
bool old = 0;
|
|
bool old = 0;
|
|
|
|
|
|
|
@@ -538,8 +503,22 @@ int real_writeuserfile(int idx, const struct userrec *bu, FILE *f, bool compat)
|
|
|
|
|
|
|
|
const char salt1[] = SALT1;
|
|
const char salt1[] = SALT1;
|
|
|
EncryptedStream stream(salt1);
|
|
EncryptedStream stream(salt1);
|
|
|
- stream_writeuserfile(stream, bu, idx, old);
|
|
|
|
|
- return stream.writeFile(fileno(f), compat ? ENC_DEFAULT : (ENC_KEEP_NEWLINES|ENC_AES_256_ECB|ENC_BASE64_BROKEN));
|
|
|
|
|
|
|
+ stream_writeuserfile(stream, userlist, idx, old);
|
|
|
|
|
+ if (stream.writeFile(new_userfile->fd)) {
|
|
|
|
|
+ putlog(LOG_MISC, "*", "ERROR writing user file. (%s)", strerror(errno));
|
|
|
|
|
+ delete new_userfile;
|
|
|
|
|
+ return 3;
|
|
|
|
|
+ }
|
|
|
|
|
+ new_userfile->my_close();
|
|
|
|
|
+ putlog(LOG_DEBUG, "@", "Done writing userfile.");
|
|
|
|
|
+
|
|
|
|
|
+ char backup[DIRMAX] = "";
|
|
|
|
|
+
|
|
|
|
|
+ simple_snprintf(backup, sizeof backup, "%s/%s~", conf.datadir, userfile);
|
|
|
|
|
+ copyfile(userfile, backup);
|
|
|
|
|
+ movefile(new_userfile->file, userfile);
|
|
|
|
|
+ delete new_userfile;
|
|
|
|
|
+ return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int change_handle(struct userrec *u, char *newh)
|
|
int change_handle(struct userrec *u, char *newh)
|