Skip to content
Permalink
Browse files

Move userfile sizeof

Patch by: michaelortmann
  • Loading branch information...
michaelortmann authored and vanosg committed Sep 8, 2019
1 parent d659635 commit 2caaa82b7c87b72a40e4840767b870eaa47744af
Showing with 14 additions and 18 deletions.
  1. +0 −11 src/main.c
  2. +14 −7 src/userrec.c
@@ -88,7 +88,6 @@
#endif

extern char origbotname[], botnetnick[];
extern char userfile[121]; /* 121 = sizeof userfile from users.c */
extern int dcc_total, conmask, cache_hit, cache_miss, max_logs, quick_logs,
quiet_save;
extern struct dcc_t *dcc;
@@ -610,16 +609,6 @@ static void do_arg()
}
}

void backup_userfile(void)
{
char s[sizeof userfile + 4];

if (quiet_save < 2)
putlog(LOG_MISC, "*", USERF_BACKUP);
egg_snprintf(s, sizeof s, "%s~bak", userfile);
copyfile(userfile, s);
}

/* Timer info */
static time_t lastmin;
static time_t then;
@@ -33,7 +33,7 @@
extern struct dcc_t *dcc;
extern struct chanset_t *chanset;
extern int default_flags, default_uflags, quiet_save, dcc_total, share_greet;
extern char userfile[], ver[], botnetnick[];
extern char ver[], botnetnick[];
extern time_t now;

int noshare = 1; /* don't send out to sharebots */
@@ -45,6 +45,7 @@ int cache_hit = 0, cache_miss = 0; /* temporary cache accounting */
int strict_host = 1;
int userfile_perm = 0600; /* Userfile permissions
* (default rw-------) */
char userfile[121];

void *_user_malloc(int size, const char *file, int line)
{
@@ -532,7 +533,7 @@ void sort_userlist()
void write_userfile(int idx)
{
FILE *f;
char *new_userfile;
char new_userfile[(sizeof userfile) + 4]; /* 4 = strlen("~new") */
char s1[81];
time_t tt;
struct userrec *u;
@@ -541,14 +542,12 @@ void write_userfile(int idx)
if (userlist == NULL)
return; /* No point in saving userfile */

new_userfile = nmalloc(strlen(userfile) + 5);
sprintf(new_userfile, "%s~new", userfile);
egg_snprintf(new_userfile, sizeof new_userfile, "%s~new", userfile);

f = fopen(new_userfile, "w");
chmod(new_userfile, userfile_perm);
if (f == NULL) {
putlog(LOG_MISC, "*", USERF_ERRWRITE);
nfree(new_userfile);
return;
}
if (!quiet_save)
@@ -566,13 +565,21 @@ void write_userfile(int idx)
if (!ok || !write_ignores(f, -1) || fflush(f)) {
putlog(LOG_MISC, "*", "%s (%s)", USERF_ERRWRITE, strerror(ferror(f)));
fclose(f);
nfree(new_userfile);
return;
}
fclose(f);
call_hook(HOOK_USERFILE);
movefile(new_userfile, userfile);
nfree(new_userfile);
}

void backup_userfile(void)
{
char s[(sizeof userfile) + 4]; /* 4 = strlen("~bak") */

if (quiet_save < 2)
putlog(LOG_MISC, "*", USERF_BACKUP);
egg_snprintf(s, sizeof s, "%s~bak", userfile);
copyfile(userfile, s);
}

int change_handle(struct userrec *u, char *newh)

0 comments on commit 2caaa82

Please sign in to comment.
You can’t perform that action at this time.