Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

load_cfg.c 16.2 KB
Newer Older
1 2 3 4 5 6
/* Synchronet configuration load routines (exported) */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
7
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *																			*
 * This program is free software; you can redistribute it and/or			*
 * modify it under the terms of the GNU General Public License				*
 * as published by the Free Software Foundation; either version 2			*
 * of the License, or (at your option) any later version.					*
 * See the GNU General Public License for more details: gpl.txt or			*
 * http://www.fsf.org/copyleft/gpl.html										*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

22 23 24 25 26
#include "load_cfg.h"
#include "scfglib.h"
#include "str_util.h"
#include "nopen.h"
#include "datewrap.h"
27
#include "text.h"	/* TOTAL_TEXT */
28 29 30
#ifdef USE_CRYPTLIB
#include "cryptlib.h"
#endif
31

32
static void prep_cfg(scfg_t* cfg);
33 34
static void free_attr_cfg(scfg_t* cfg);

35
int 	lprintf(int level, const char *fmt, ...);	/* log output */
36

37 38 39
/* readtext.c */
char *	readtext(long *line, FILE *stream, long dflt);

40 41 42
/****************************************************************************/
/* Initializes system and node configuration information and data variables */
/****************************************************************************/
43
BOOL load_cfg(scfg_t* cfg, char* text[], BOOL prep, BOOL req_node, char* error, size_t maxerrlen)
44 45
{
	int		i;
rswindell's avatar
rswindell committed
46
#ifdef SBBS
47
	long	line=0L;
48
	FILE 	*instream;
49
	char	str[256];
rswindell's avatar
rswindell committed
50
#endif
51

52
	if(cfg->size!=sizeof(scfg_t)) {
53
		safe_snprintf(error, maxerrlen,"cfg->size (%"PRIu32") != sizeof(scfg_t) (%" XP_PRIsize_t "d)"
54
			,cfg->size,sizeof(scfg_t));
55
		return(FALSE);
56
	}
57

58 59
	free_cfg(cfg);	/* free allocated config parameters */

60
	cfg->prepped=FALSE;	/* reset prepped flag */
61
	cfg->tls_certificate = -1;
62

63 64 65 66
	if(cfg->node_num<1)
		cfg->node_num=1;

	backslash(cfg->ctrl_dir);
67
	if(read_main_cfg(cfg, error, maxerrlen)==FALSE)
68
		return(FALSE);
69 70 71

	if(prep)
		for(i=0;i<cfg->sys_nodes;i++) 
72
			prep_dir(cfg->ctrl_dir, cfg->node_path[i], sizeof(cfg->node_path[i]));
73

74
	SAFECOPY(cfg->node_dir,cfg->node_path[cfg->node_num-1]);
75
	prep_dir(cfg->ctrl_dir, cfg->node_dir, sizeof(cfg->node_dir));
76
	if(read_node_cfg(cfg, error, maxerrlen)==FALSE && req_node)
77
		return(FALSE);
78
	if(read_msgs_cfg(cfg, error, maxerrlen)==FALSE)
79
		return(FALSE);
80
	if(read_file_cfg(cfg, error, maxerrlen)==FALSE)
81
		return(FALSE);
82
	if(read_xtrn_cfg(cfg, error, maxerrlen)==FALSE)
83
		return(FALSE);
84
	if(read_chat_cfg(cfg, error, maxerrlen)==FALSE)
85
		return(FALSE);
86
	if(read_attr_cfg(cfg, error, maxerrlen)==FALSE)
87 88
		return(FALSE);

89
#ifdef SBBS
90
	if(text!=NULL) {
91 92 93 94

		/* Free existing text if allocated */
		free_text(text);

95
		SAFEPRINTF(str,"%stext.dat",cfg->ctrl_dir);
96
		if((instream=fnopen(NULL,str,O_RDONLY))==NULL) {
97
			safe_snprintf(error, maxerrlen,"%d opening %s",errno,str);
98 99
			return(FALSE); 
		}
deuce's avatar
deuce committed
100
		for(i=0;i<TOTAL_TEXT;i++)
101
			if((text[i]=readtext(&line,instream,i))==NULL) {
102 103 104 105 106 107
				i--;
				break;
			}
		fclose(instream);

		if(i<TOTAL_TEXT) {
108
			safe_snprintf(error, maxerrlen,"line %d: Less than TOTAL_TEXT (%u) strings defined in %s."
109 110
				,i
				,TOTAL_TEXT,str);
111 112
			return(FALSE); 
		}
113
		cfg->text = text;
114
	}
115
#endif
116

117 118 119 120
    /* Override com-port settings */
    cfg->com_base=0xf;	/* All nodes use FOSSIL */
    cfg->com_port=1;	/* All nodes use "COM1" */

121 122 123
	if(prep)
		prep_cfg(cfg);

124
	/* Auto-toggle daylight savings time in US time-zones */
125
	sys_timezone(cfg);
126

127 128 129
	return(TRUE);
}

130 131 132 133 134 135 136 137
/****************************************************************************/
/* Prepare configuration for run-time (resolve relative paths, etc)			*/
/****************************************************************************/
void prep_cfg(scfg_t* cfg)
{
	int i;

	/* Fix-up paths */
138
	prep_dir(cfg->ctrl_dir, cfg->data_dir, sizeof(cfg->data_dir));
139
	prep_dir(cfg->ctrl_dir, cfg->logs_dir, sizeof(cfg->logs_dir));
140
	prep_dir(cfg->ctrl_dir, cfg->exec_dir, sizeof(cfg->exec_dir));
141
	prep_dir(cfg->ctrl_dir, cfg->mods_dir, sizeof(cfg->mods_dir));
142
	prep_dir(cfg->ctrl_dir, cfg->text_dir, sizeof(cfg->text_dir));
143

144 145 146
	prep_dir(cfg->ctrl_dir, cfg->netmail_dir, sizeof(cfg->netmail_dir));
	prep_dir(cfg->ctrl_dir, cfg->echomail_dir, sizeof(cfg->echomail_dir));
	prep_dir(cfg->ctrl_dir, cfg->fidofile_dir, sizeof(cfg->fidofile_dir));
147 148 149 150 151 152

	prep_path(cfg->netmail_sem);
	prep_path(cfg->echomail_sem);
	prep_path(cfg->inetmail_sem);

	for(i=0;i<cfg->total_subs;i++) {
153

154
		if(!cfg->sub[i]->data_dir[0])	/* no data storage path specified */
155
			SAFEPRINTF(cfg->sub[i]->data_dir,"%ssubs",cfg->data_dir);
156
		prep_dir(cfg->ctrl_dir, cfg->sub[i]->data_dir, sizeof(cfg->sub[i]->data_dir));
157 158 159

		/* default QWKnet tagline */
		if(!cfg->sub[i]->tagline[0])
160
			SAFECOPY(cfg->sub[i]->tagline,cfg->qnet_tagline);
161 162 163

		/* default origin line */
		if(!cfg->sub[i]->origline[0])
164
			SAFECOPY(cfg->sub[i]->origline,cfg->origline);
165 166

		/* A sub-board's internal code is the combination of the grp's code_prefix & the sub's code_suffix */
167
		SAFEPRINTF2(cfg->sub[i]->code,"%s%s"
168 169 170 171
			,cfg->grp[cfg->sub[i]->grp]->code_prefix
			,cfg->sub[i]->code_suffix);

		strlwr(cfg->sub[i]->code); 		/* data filenames are all lowercase */
172 173

		prep_path(cfg->sub[i]->post_sem);
174 175
	}

176
	for(i=0;i<cfg->total_libs;i++) {
177
		if(cfg->lib[i]->parent_path[0])
178
			prep_dir(cfg->ctrl_dir, cfg->lib[i]->parent_path, sizeof(cfg->lib[i]->parent_path));
179 180 181 182 183 184 185 186 187 188 189 190 191 192
		if((cfg->lib[i]->misc&LIB_DIRS) == 0 || cfg->lib[i]->parent_path[0] == 0)
			continue;
		char path[MAX_PATH+1];
		SAFECOPY(path, cfg->lib[i]->parent_path);
		backslash(path);
		strcat(path, ALLFILES);
		glob_t g;
		if(glob(path, GLOB_MARK, NULL, &g))
			continue;
   		for(uint gi=0;gi<g.gl_pathc;gi++) {
			char* p = g.gl_pathv[gi];
			char* tp = lastchar(p);
			if(*tp != '/')
				continue;
193
			*tp = 0; // Remove trailing slash
194 195 196 197 198
			char* dirname = getfname(p);
			int j;
			for(j = 0; j < cfg->total_dirs; j++) {
				if(cfg->dir[j]->lib != i)
					continue;
199 200
				if(stricmp(cfg->dir[j]->code, dirname) == 0)
					break;
201 202 203 204 205
				if(stricmp(cfg->dir[j]->code_suffix, dirname) == 0)
					break;
			}
			if(j < cfg->total_dirs)	// duplicate
				continue;
206 207 208 209 210 211
			dir_t dir;
			memset(&dir, 0, sizeof(dir));
			dir.lib = i;
			dir.misc = DIR_FILES;
			SAFECOPY(dir.path, p);
			backslash(dir.path);
212
			SAFECOPY(dir.lname, dirname);
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
			SAFECOPY(dir.sname, dir.lname);
			char code_suffix[LEN_EXTCODE+1];
			SAFECOPY(code_suffix, dir.lname);
			prep_code(code_suffix, cfg->lib[i]->code_prefix);
			SAFECOPY(dir.code_suffix, code_suffix);
			SAFEPRINTF2(dir.code,"%s%s"
				,cfg->lib[i]->code_prefix
				,dir.code_suffix);

			dir_t** new_dirs;
			if((new_dirs=(dir_t **)realloc(cfg->dir, sizeof(dir_t *)*(cfg->total_dirs+2)))==NULL)
				continue;
			cfg->dir  = new_dirs;
			if((cfg->dir[cfg->total_dirs] = malloc(sizeof(dir_t))) == NULL)
				continue;
			*cfg->dir[cfg->total_dirs++] = dir;
		}
	}

232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
	for(i=0;i<cfg->total_dirs;i++) {

		if(!cfg->dir[i]->data_dir[0])	/* no data storage path specified */
			SAFEPRINTF(cfg->dir[i]->data_dir,"%sdirs",cfg->data_dir);
		prep_dir(cfg->ctrl_dir, cfg->dir[i]->data_dir, sizeof(cfg->dir[i]->data_dir));

		/* A directory's internal code is the combination of the lib's code_prefix & the dir's code_suffix */
		SAFEPRINTF2(cfg->dir[i]->code,"%s%s"
			,cfg->lib[cfg->dir[i]->lib]->code_prefix
			,cfg->dir[i]->code_suffix);

		strlwr(cfg->dir[i]->code); 		/* data filenames are all lowercase */

		if(!cfg->dir[i]->path[0])
			SAFECOPY(cfg->dir[i]->path, cfg->dir[i]->code);
		if(cfg->lib[cfg->dir[i]->lib]->parent_path[0])
			prep_dir(cfg->lib[cfg->dir[i]->lib]->parent_path, cfg->dir[i]->path, sizeof(cfg->dir[i]->path));
		else
			prep_dir(cfg->dir[i]->data_dir, cfg->dir[i]->path, sizeof(cfg->dir[i]->path));

		prep_path(cfg->dir[i]->upload_sem);
	}
254 255

	/* make data filenames are all lowercase */
256
	for(i=0;i<cfg->total_shells;i++)
257
		strlwr(cfg->shell[i]->code);
258 259

	for(i=0;i<cfg->total_gurus;i++)
260
		strlwr(cfg->guru[i]->code); 
261 262

	for(i=0;i<cfg->total_txtsecs;i++)
263
		strlwr(cfg->txtsec[i]->code);
264 265

	for(i=0;i<cfg->total_xtrnsecs;i++)
266 267
		strlwr(cfg->xtrnsec[i]->code);

268 269 270
	for(i=0;i<cfg->total_xtrns;i++) 
	{
		strlwr(cfg->xtrn[i]->code);
271
		prep_dir(cfg->ctrl_dir, cfg->xtrn[i]->path, sizeof(cfg->xtrn[i]->path));
272 273
	}
	for(i=0;i<cfg->total_events;i++) {
274
		strlwr(cfg->event[i]->code); 	/* data filenames are all lowercase */
275
		prep_dir(cfg->ctrl_dir, cfg->event[i]->dir, sizeof(cfg->event[i]->dir));
276
	}
277 278
	for(i=0;i<cfg->total_xedits;i++) 
		strlwr(cfg->xedit[i]->code);
279

280 281
	if (!cfg->prepped)
		cfg->tls_certificate = -1;
282 283 284
	cfg->prepped=TRUE;	/* data prepared for run-time, DO NOT SAVE TO DISK! */
}

Rob Swindell's avatar
Rob Swindell committed
285
void free_cfg(scfg_t* cfg)
286
{
287 288 289 290
#ifdef USE_CRYPTLIB
	if (cfg->tls_certificate != -1 && cfg->prepped)
		cryptDestroyContext(cfg->tls_certificate);
#endif
291 292 293 294 295 296
	free_node_cfg(cfg);
	free_main_cfg(cfg);
	free_msgs_cfg(cfg);
	free_file_cfg(cfg);
	free_chat_cfg(cfg);
	free_xtrn_cfg(cfg);
297
	free_attr_cfg(cfg);
298 299 300

	if(cfg->text != NULL)
		free_text(cfg->text);
301 302
}

Rob Swindell's avatar
Rob Swindell committed
303
void free_text(char* text[])
304 305 306 307 308 309 310 311 312 313 314
{
	int i;

	if(text==NULL)
		return;

	for(i=0;i<TOTAL_TEXT;i++) {
		FREE_AND_NULL(text[i]); 
	}
}

315 316 317
/****************************************************************************/
/* If the directory 'path' doesn't exist, create it.                      	*/
/****************************************************************************/
318
int md(const char* inpath)
319
{
320
	char	path[MAX_PATH+1];
321
	char*	p;
322

323
	if(inpath[0]==0)
324
		return EINVAL;
325

326 327
	SAFECOPY(path,inpath);

328
	/* Remove trailing '.' if present */
329 330 331
	p = lastchar(path);
	if(*p=='.')
		*p = '\0';
332 333

	/* Remove trailing slash if present */
334 335 336
	p = lastchar(path);
	if(*p == '\\' || *p == '/')
		*p = '\0';
337

338
	if(!isdir(path)) {
339 340 341 342 343
		if(mkpath(path) != 0) {
			int result = errno;
			if(!isdir(path)) // race condition: did another thread make the directory already?
				return result;
		}
344
	}
345
	
346
	return 0;
347 348 349 350 351
}

/****************************************************************************/
/* Reads in ATTR.CFG and initializes the associated variables               */
/****************************************************************************/
352
BOOL read_attr_cfg(scfg_t* cfg, char* error, size_t maxerrlen)
353
{
rswindell's avatar
rswindell committed
354
	uint*	clr;
355
    char    str[256];
356 357 358
	long	offset=0;
    FILE    *instream;

359
	SAFEPRINTF(str,"%sattr.cfg",cfg->ctrl_dir);
360
	if((instream=fnopen(NULL,str,O_RDONLY))==NULL) {
361
		safe_snprintf(error, maxerrlen,"%d opening %s",errno,str);
362 363
		return(FALSE); 
	}
364
	FREE_AND_NULL(cfg->color);
rswindell's avatar
rswindell committed
365
	if((cfg->color=malloc(MIN_COLORS * sizeof(uint)))==NULL) {
366
		safe_snprintf(error, maxerrlen,"Error allocating memory (%u bytes) for colors"
367
			,MIN_COLORS);
rswindell's avatar
rswindell committed
368
		fclose(instream);
369 370
		return(FALSE);
	}
371 372
	/* Setup default colors here: */
	memset(cfg->color,LIGHTGRAY|HIGH,MIN_COLORS);
373 374
	cfg->color[clr_votes_full] = WHITE|BG_MAGENTA;
	cfg->color[clr_progress_full] = CYAN|HIGH|BG_BLUE;
375 376 377
	for(cfg->total_colors=0;!feof(instream) && !ferror(instream);cfg->total_colors++) {
		if(readline(&offset,str,4,instream)==NULL)
			break;
rswindell's avatar
rswindell committed
378
		if(cfg->total_colors>=MIN_COLORS) {
rswindell's avatar
rswindell committed
379
			if((clr=realloc(cfg->color,(cfg->total_colors+1) * sizeof(uint)))==NULL)
380
				break;
rswindell's avatar
rswindell committed
381
			cfg->color=clr;
rswindell's avatar
rswindell committed
382
		}
383
		cfg->color[cfg->total_colors]=attrstr(str); 
384
	}
385
	fclose(instream);
386 387
	if(cfg->total_colors<MIN_COLORS)
		cfg->total_colors=MIN_COLORS;
388 389 390
	return(TRUE);
}

391 392 393 394 395 396 397
static void free_attr_cfg(scfg_t* cfg)
{
	if(cfg->color!=NULL)
		FREE_AND_NULL(cfg->color);
	cfg->total_colors=0;
}

Rob Swindell's avatar
Rob Swindell committed
398
char* prep_dir(const char* base, char* path, size_t buflen)
399 400 401 402
{
#ifdef __unix__
	char	*p;
#endif
403
	char	str[MAX_PATH+1];
404
	char	abspath[MAX_PATH+1];
405
	char	ch;
406 407

	if(!path[0])
408
		return(path);
409 410 411
	if(path[0]!='\\' && path[0]!='/' && path[1]!=':') {	/* Relative directory */
		ch=*lastchar(base);
		if(ch=='\\' || ch=='/')
412
			SAFEPRINTF2(str,"%s%s",base,path);
413
		else
414
			SAFEPRINTF3(str,"%s%c%s",base,PATH_DELIM,path);
415
	} else
416
		SAFECOPY(str,path);
417 418 419 420 421 422 423 424

#ifdef __unix__				/* Change backslashes to forward slashes on Unix */
	for(p=str;*p;p++)
		if(*p=='\\') 
			*p='/';
#endif

	backslashcolon(str);
425
	SAFECAT(str,".");               /* Change C: to C:. and C:\SBBS\ to C:\SBBS\. */
426
	FULLPATH(abspath,str,buflen);	/* Change C:\SBBS\NODE1\..\EXEC to C:\SBBS\EXEC */
427
	backslash(abspath);
428

429
	strncpy(path, abspath, buflen);
430
	return(path);
431 432
}

433
char* prep_path(char* path)
434 435 436 437 438 439 440 441
{
#ifdef __unix__				/* Change backslashes to forward slashes on Unix */
	char	*p;

	for(p=path;*p;p++)
		if(*p=='\\') 
			*p='/';
#endif
442 443

	return(path);
444
}
445

446 447 448 449 450 451 452 453 454 455 456 457 458
/* Prepare a string to be used as an internal code */
/* Return the usable code */
char* prep_code(char *str, const char* prefix)
{
	char tmp[1024];
	int i,j;

	if(prefix!=NULL) {	/* skip the grp/lib prefix, if specified */
		i=strlen(prefix);
		if(i && strnicmp(str,prefix,i)==0 && strlen(str)!=i)
			str+=i;
	}
	for(i=j=0;str[i] && i<sizeof(tmp);i++)
459
		if(str[i]>' ' && !(str[i]&0x80) && str[i]!='*' && str[i]!='?' && str[i]!='.'
460 461 462 463 464 465
			&& strchr(ILLEGAL_FILENAME_CHARS,str[i])==NULL)
			tmp[j++]=toupper(str[i]);
	tmp[j]=0;
	strcpy(str,tmp);
	if(j>LEN_CODE) {	/* Extra chars? Strip symbolic chars */
		for(i=j=0;str[i];i++)
466
			if(IS_ALPHANUMERIC(str[i]))
467 468 469 470 471 472 473 474
				tmp[j++]=str[i];
		tmp[j]=0;
		strcpy(str,tmp);
	}
	str[LEN_CODE]=0;
	return(str);
}

475 476 477
/****************************************************************************/
/* Auto-toggle daylight savings time in US time-zones						*/
/****************************************************************************/
Rob Swindell's avatar
Rob Swindell committed
478
ushort sys_timezone(scfg_t* cfg)
479 480 481 482
{
	time_t	now;
	struct tm tm;

483
	if(cfg->sys_misc&SM_AUTO_DST && SMB_TZ_HAS_DST(cfg->sys_timezone)) {
484 485 486 487 488 489 490 491 492 493 494
		now=time(NULL);
		if(localtime_r(&now,&tm)!=NULL) {
			if(tm.tm_isdst>0)
				cfg->sys_timezone|=DAYLIGHT;
			else if(tm.tm_isdst==0)
				cfg->sys_timezone&=~DAYLIGHT;
		}
	}

	return(cfg->sys_timezone);
}
495 496


Rob Swindell's avatar
Rob Swindell committed
497
int smb_storage_mode(scfg_t* cfg, smb_t* smb)
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
{
	if(smb == NULL || smb->subnum == INVALID_SUB || (smb->status.attr&SMB_EMAIL))
		return (cfg->sys_misc&SM_FASTMAIL) ? SMB_FASTALLOC : SMB_SELFPACK;
	if(smb->subnum >= cfg->total_subs)
		return (smb->status.attr&SMB_HYPERALLOC) ? SMB_HYPERALLOC : SMB_FASTALLOC;
	if(cfg->sub[smb->subnum]->misc&SUB_HYPER) {
		smb->status.attr |= SMB_HYPERALLOC;
		return SMB_HYPERALLOC;
	}
	if(cfg->sub[smb->subnum]->misc&SUB_FAST)
		return SMB_FASTALLOC;
	return SMB_SELFPACK;
}

/* Open Synchronet Message Base and create, if necessary (e.g. first time opened) */
/* If return value is not SMB_SUCCESS, sub-board is not left open */
Rob Swindell's avatar
Rob Swindell committed
514
int smb_open_sub(scfg_t* cfg, smb_t* smb, unsigned int subnum)
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
{
	int retval;
	smbstatus_t smb_status = {0};

	if(subnum != INVALID_SUB && subnum >= cfg->total_subs)
		return SMB_FAILURE;
	memset(smb, 0, sizeof(smb_t));
	if(subnum == INVALID_SUB) {
		SAFEPRINTF(smb->file, "%smail", cfg->data_dir);
		smb_status.max_crcs	= cfg->mail_maxcrcs;
		smb_status.max_msgs	= 0;
		smb_status.max_age	= cfg->mail_maxage;
		smb_status.attr		= SMB_EMAIL;
	} else {
		SAFEPRINTF2(smb->file, "%s%s", cfg->sub[subnum]->data_dir, cfg->sub[subnum]->code);
		smb_status.max_crcs	= cfg->sub[subnum]->maxcrcs;
		smb_status.max_msgs	= cfg->sub[subnum]->maxmsgs;
		smb_status.max_age	= cfg->sub[subnum]->maxage;
		smb_status.attr		= cfg->sub[subnum]->misc&SUB_HYPER ? SMB_HYPERALLOC :0;
	}
	smb->retry_time = cfg->smb_retry_time;
	if((retval = smb_open(smb)) == SMB_SUCCESS) {
		if(smb_fgetlength(smb->shd_fp) < sizeof(smbhdr_t) + sizeof(smb->status)) {
			smb->status = smb_status;
			if((retval = smb_create(smb)) != SMB_SUCCESS)
				smb_close(smb);
		}
		if(retval == SMB_SUCCESS)
			smb->subnum = subnum;
	}
	return retval;
}

Rob Swindell's avatar
Rob Swindell committed
548
BOOL smb_init_dir(scfg_t* cfg, smb_t* smb, unsigned int dirnum)
549 550 551 552 553 554 555 556 557
{
	if(dirnum >= cfg->total_dirs)
		return FALSE;
	memset(smb, 0, sizeof(smb_t));
	SAFEPRINTF2(smb->file, "%s%s", cfg->dir[dirnum]->data_dir, cfg->dir[dirnum]->code);
	smb->retry_time = cfg->smb_retry_time;
	return TRUE;
}

Rob Swindell's avatar
Rob Swindell committed
558
int smb_open_dir(scfg_t* cfg, smb_t* smb, unsigned int dirnum)
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
{
	int retval;

	if(!smb_init_dir(cfg, smb, dirnum))
		return SMB_FAILURE;
	if((retval = smb_open(smb)) != SMB_SUCCESS)
		return retval;
	smb->dirnum = dirnum;
	if(filelength(fileno(smb->shd_fp)) < 1) {
		smb->status.max_files	= cfg->dir[dirnum]->maxfiles;
		smb->status.max_age		= cfg->dir[dirnum]->maxage;
		smb->status.attr		= SMB_FILE_DIRECTORY;
		if(cfg->dir[dirnum]->misc & DIR_NOHASH)
			smb->status.attr |= SMB_NOHASH;
		smb_create(smb);
	}
	return SMB_SUCCESS;
}