File: init.c

package info (click to toggle)
xcdroast 0.98%2B0alpha9-9
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,084 kB
  • ctags: 1,001
  • sloc: ansic: 21,608; makefile: 119; sh: 116
file content (830 lines) | stat: -rw-r--r-- 20,451 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
/* 
	init.c
	15.3.99 tn
*/

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#include <strings.h>
#if defined(linux) || defined(__CYGWIN32__)
#include <getopt.h>
#endif
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk_imlib.h>
#include "xcdrdata.h"
#include "xcdroast.h"
#include "main.h"

extern setup_data_t setupdata;
extern current_set_t curset;
extern cd_info_t cdinfo;
extern track_info_t **trackinfo;
extern gint language;
extern track_read_set_t trackreadset;
extern GList *imagelist;
extern GList *writelist;
extern write_track_param_t writeparams;
extern gint wav_in;
extern GList *tocfiles;
extern gint debug;
extern gchar xcdroast_version_loaded[MAXLINE];
extern master_param_t masterparam;
extern gint oldfontcode;
extern gint ignorescanbus;
extern writer_driver_t **drv_options;
extern gint drvoptcount;
extern GtkWidget *toplevel;
extern gchar **charset_types;

gchar *system_platform;
gchar hostname[MAXLINE];
gchar username[MAXLINE];
gchar configdir[MAXLINE];
gchar sharedir[MAXLINE];
gchar rootconfig[MAXLINE];
gchar prefixdir[MAXLINE];
gint runningbash2;

/* give the setupdata-structure valid startvalues */

void init_setupdata() {
gchar tmp[MAXLINE];

	setupdata.writer_devnr = -1;
	strcpy(setupdata.writer_vendor,"");
	strcpy(setupdata.writer_model,"");
	setupdata.writer_mode = -1;
	setupdata.writer_speed = 1;
	setupdata.writer_fifo = 4096;

	setupdata.readdev1_devnr = -1;
	strcpy(setupdata.readdev1_vendor,"");
	strcpy(setupdata.readdev1_model,"");
	setupdata.readdev2_devnr = -1;
	strcpy(setupdata.readdev2_vendor,"");
	strcpy(setupdata.readdev2_model,"");
	setupdata.audioread_interface = 0;
	setupdata.audioread_speed = 1;
	setupdata.audioread_overlap = 0;
	setupdata.audioread_sectorburst = 75;

	setupdata.image_dirs = NULL;
	
	setupdata.dsp_device = g_strdup("");
	setupdata.mix_device = g_strdup("");
	setupdata.notify_via = 1;
	setupdata.notify_at = 0;

	setupdata.cddb_host = g_strdup("freedb.freedb.org");
	setupdata.cddb_port = 888;

	g_snprintf(tmp,MAXLINE,"%s/%s", CONFIGDIR, LOGFILE);
	setupdata.logfile = g_strdup(tmp);
	setupdata.loglevel = 0;

	setupdata.language = -1;	

	setupdata.option_tooltips = 1;
	setupdata.option_autoraise = 0;
	setupdata.option_savepos = 0;
	setupdata.option_personimage = 0;
	setupdata.option_overwritewarn = 0;
	setupdata.option_autodelete = 0;
	setupdata.option_titleprogress = 0;
	setupdata.option_displaycdtext = 1;
	setupdata.option_selectionmode = 0;
	setupdata.def_write_mode = 0;

	setupdata.root_users_access = 0;
	setupdata.root_users_lists = NULL;
	setupdata.root_hosts_access = 0;
	setupdata.root_hosts_lists = NULL;

        setupdata.root_option_change_writer = 0;
        setupdata.root_option_change_writeparam = 0;
        setupdata.root_option_change_reader = 0;
        setupdata.root_option_change_readparam = 0;
        setupdata.root_option_change_imagedirs = 0;
        setupdata.root_option_change_logoptions = 0;

}


/* init current-set-structure */

void init_curset() {

	curset.writer_devnr = -1;
	curset.reader_devnr = -1;
	curset.writer_speed = -1;
	curset.audioread_speed = -1;
	curset.image_index = -1;
	curset.proc_view = 2;
	curset.file_prefix = g_strdup("");
	curset.tocfile = g_strdup("");
	curset.cdrtype = 0;
	curset.writemode = 0;
	curset.writesimul = 0;
	curset.writeeject = 1;
	curset.writepad = 1;
	curset.writeswap = 0;
	curset.nofixate = 0;
	curset.multisession = 0;
	curset.blankmode = 1;
	curset.blank_force = 0;
	curset.blank_eject = 1;
	curset.noaudioverify = 0;
	curset.verifyfailabort = 0;
	curset.indexscan = 1;
}


/* init cdinfo and trackinfo-structure */

void init_cdinfo() {

	cdinfo.nr_tracks = 0;
	cdinfo.total_size = 0;
	strcpy(cdinfo.cddb_discid,"00000000");
	cdinfo.have_cdtext = 0;
	cdinfo.have_cdextra = 0;
	cdinfo.title = NULL;
	cdinfo.artist = NULL;
	cdinfo.cddb_dtitle = NULL;
	cdinfo.leadout = 0;	

	/* allocate tracks */
	trackinfo = g_new0(track_info_t *,MAXTRACKS);
}


/* init trackreadset-variable */

void init_trackreadset() {

	trackreadset.nrtracks = 0;
	trackreadset.tocfile = g_strdup("");
	trackreadset.cdtitle = g_strdup("");
	trackreadset.trackparams = NULL;
}


/* init writeparams-structure */

void init_writeparams() {

	writeparams.nrtracks = 0;
	writeparams.simulation = 0;
	writeparams.tracktype = NULL;
	writeparams.frames = NULL;
	writeparams.pct_so_far_arr = NULL;
	writeparams.pct_this_track_arr = NULL;
}


/* init master-parameters */

void init_masterparams() {
int i;

	masterparam.mstr_redir = NULL;
	masterparam.exclude_paths = NULL;
	masterparam.show_only_dirs = 1;
	masterparam.image_type = -1;
	for (i=0; i<16; i++) 
		masterparam.opt[i] = 0;	
	masterparam.bootable = 0;
	masterparam.boot_image = g_strdup("");
	masterparam.boot_catalog = g_strdup(DEF_BOOT_CATALOG);
	masterparam.boot_type = 0;
	masterparam.sparc_boot = g_strdup("");
	masterparam.volid = g_strdup("");
	masterparam.publisher = g_strdup("");
	masterparam.preparer = g_strdup("");
	masterparam.application = g_strdup("");
	masterparam.abstract = g_strdup("");
	masterparam.biblio = g_strdup("");
	masterparam.copyright = g_strdup("");
	masterparam.image_filename = g_strdup("");
	masterparam.old_session_size = 0;
	masterparam.session_size = 0;
	masterparam.charset = 0;
	masterparam.redirtype = 1;
	masterparam.lastredirpath = g_strdup("");
}

void init_drv_options() {

	drv_options=NULL;
	drvoptcount = 0;
}


/* make a stat on a file return 1 if it does exist, 0 if not */

gint stat_file(gchar *file) {
struct stat buf;
gchar tmp[MAXLINE];
gchar tmp2[MAXLINE];
gchar *p;

	/* strip first all after a space in filename (arguments) */
	strcpy(tmp,file);
	p = strtok(tmp," ");
	if (p != NULL) {
		strcpy(tmp2,p);
		strcpy(tmp,tmp2);
	}

	/* file does exist? */
	if (stat(tmp,&buf) == 0) {
		if (!(buf.st_mode & S_IEXEC)) {
			g_warning("%s not executable\n", file);
			gtk_exit(1);
		}
		return 1;
	} 
	return 0;
}


/* check if a given file got the suid-bit set */

void suid_set(gchar *file) {
struct stat buf;

#if 0  /* not needed for Debian */
	/* file does exist? */
	if (stat(file,&buf) == 0) {
		if (!(buf.st_mode & S_ISUID)) {
			g_warning("Installation problem? No set-uid bit on %s\n", file);
			dodebug(1,"Warning: No set-uid bit on %s\n", file);
		}
	}
#endif
}


/* check if a given file got the gid-bit set */
/* return the value gid_t */

gid_t sgid_set(gchar *file) {
struct stat buf;

	/* file does exist? */
	if (stat(file,&buf) == 0) {
#if 0
	  (!(buf.st_mode & S_ISGID)) {
			g_warning("Installation problem? No set-gid bit on %s\n", file);
			dodebug(1,"Warning: No set-gid bit on %s\n", file);
		}
#endif
		return buf.st_gid;
	}
	return (gid_t) 0;
}


/* stat a file and see if its a binary */

gint check_executable(gchar *file, gchar *altfile, gint share) {
gint second;

	second = 0;
	if (altfile != NULL) {
		second = stat_file(altfile);
	}

	if (stat_file(file) == 0 && !second) {
		if (altfile == NULL) 
			g_warning("No %s installed\n", file);
		else
			g_warning("No %s or %s installed\n", file, altfile);
			
		if (share) 
			g_warning("(Invalid lib-directory? Check -l option)\n");
		gtk_exit(1);
	}

	return 0;
}


/* check if needed binaries are installed */

void check_binaries(gint noversioncheck) {
gchar tmp[MAXLINE];
gchar ver[MAXLINE];
gint stat;
	
	check_executable(UNAME,UNAME2,0);
	check_executable(DF,DF2,0);

	get_spawn_path(CDRECORD,tmp);
	check_executable(tmp,NULL,1);
	suid_set(tmp);
	stat = check_version_cdrecord(CDRECORD_VERSION,ver);
	if (stat == 1 && !noversioncheck) {
		g_warning("Invalid cdrecord version %s found. Expecting version %s\n", ver, CDRECORD_VERSION);	
		gtk_exit(1);
	}
	if (stat == 2) {
		g_warning("Failed to access cdrecord. Please check the permissions and ownership of %s\n", tmp);
		gtk_exit(1);
	}


	get_spawn_path(MKISOFS,tmp);
	check_executable(tmp,NULL,1);
	suid_set(tmp);
	stat = check_version_mkisofs(MKISOFS_VERSION,ver);
	if (stat == 1 && !noversioncheck) {
		g_warning("Invalid mkisofs version %s found. Expecting version %s\n", ver, MKISOFS_VERSION);	
		gtk_exit(1);
	}
	if (stat == 2) {
		g_warning("Failed to access mkisofs. Please check the permissions and ownership of %s\n", tmp);
		gtk_exit(1);
	}

	get_spawn_path(READCD,tmp);
	check_executable(tmp,NULL,1);
	suid_set(tmp);
	stat = check_version_readcd(READCD_VERSION,ver);
	if (stat == 1 && !noversioncheck) {
		g_warning("Invalid readcd version %s found. Expecting version %s\n", ver, READCD_VERSION);	
		gtk_exit(1);
	}
	if (stat == 2) {
		g_warning("Failed to access readcd. Please check the permissions and ownership of %s\n", tmp);
		gtk_exit(1);
	}


	get_spawn_path(CDDA2WAV,tmp);
	check_executable(tmp,NULL,1);
	suid_set(tmp);
	stat = check_version_cdda2wav(CDDA2WAV_VERSION,ver);
	if (stat == 1 && !noversioncheck) {
		g_warning("Invalid cdda2wav version %s found. Expecting version %s\n", ver, CDDA2WAV_VERSION);	
		gtk_exit(1);
	}
	if (stat == 2) {
		g_warning("Failed to access cdda2wav. Please check the permissions and ownership of %s\n", tmp);
		gtk_exit(1);
	}

	g_snprintf(tmp,MAXLINE,"%s/%s", sharedir, WAVPLAY);
	check_executable(tmp,NULL,1);
	g_snprintf(tmp,MAXLINE,"%s/%s", sharedir, RMTOOL);
	check_executable(tmp,NULL,1);
	g_snprintf(tmp,MAXLINE,"%s/%s", sharedir, VRFYTOOL);
	check_executable(tmp,NULL,1);
	g_snprintf(tmp,MAXLINE,"%s/%s", sharedir, CDDBTOOL);
	check_executable(tmp,NULL,1);

}


/* check the wrapper binary */
/* return 1 when user got no permission */
/* return 2 if rootconfig not readable */

gint check_wrapper_binary() {
gchar tmp[MAXLINE];
gid_t wrap_gid;
gint stat;

	g_snprintf(tmp,MAXLINE,"%s/%s", sharedir, WRAPPER);
	check_executable(tmp,NULL,1);
	wrap_gid = sgid_set(tmp);

	/* security check. If this fails then the wrapper is wrong */
	stat = check_version_wrapper(tmp);
	if (stat == 1) {
		fprintf(stderr, "Aborting...\n");
		gtk_exit(1);
	}
	if (stat == 2) {
		/* this user is not allowed to start the wrapper */
		return 1;
	}
	if (stat == 3) {
		/* no rootconfig readable */
		return 2;
	}
#if 0 /* not needed for Debian */
	if (!match_group_name(wrap_gid,"cdrom")) {
		g_warning("The X-CD-Roast wrapper seems not to have the correct\n\t permissions set");
		g_warning("So do as root something like that: (and read the Manual)\n\t chown root:cdrom %s;\n\t chmod 2755 %s\n", tmp,tmp);



		/* if root, let user continue */
		if (!isroot()) {
			gtk_exit(1);
		} else {
			fprintf(stderr, "*** NOTE ***:\n\t---------------------------------------------------------------\n\tThis permission warning and the following set-uid bit warnings\n\tcan be safely ignored, if you want to run X-CD-Roast as root only.\n\t---------------------------------------------------------------\n");
		}
	}
#endif
	return 0;
}


/* a graphically root-warning */

void check_root() {

	if (!isroot()) {
		/* we need a toplevel for the show_dialog function */
		toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL);
		gtk_widget_realize(toplevel);
	
		show_dialog(ICO_WARN, text(413), T_OK, NULL, NULL, 0);
		gtk_exit(1);
	}
}


/* check if we have at least 800x600 virtual screen size */
/* for bigfonts we need 1024x768 */

gint check_screensize(gint bigfonts) {
gint xsize, ysize;

	xsize = gdk_screen_width();
	ysize = gdk_screen_height();

	if (bigfonts == 0) {
		if (xsize < 800 || ysize < 600) 
			return 1;
	} else {
		if (xsize < 1024 || ysize < 768) 
			return 1;
	}
	return 0;
}


/* do check if the current user and host is allowed to start xcdroast */
/* return 1 if so, 0 if denied */

gint checkuserhost(gchar *username,gchar *hostname) {
gint userok, hostok;
gint match;
GList *loop;

	match = 0;
	/* user first */
	if (setupdata.root_users_access == 0) {
		userok = 1;
	} else 
	if (setupdata.root_users_access == 1) {
		userok = 0;
	} else {
		loop = g_list_first(setupdata.root_users_lists);
		while (loop) {
			if (strcmp(username,(gchar *)loop->data) == 0) {
				/* found our login on the list */
				match = 1;
			}		
			loop = loop->next;
		}
		if ((setupdata.root_users_access == 2 && match) ||
		    (setupdata.root_users_access == 3 && !match)) {
			userok = 1;
		} else  {
			userok = 0;
		}
	}	

	match = 0;
	/* now check host */
	if (setupdata.root_hosts_access == 0) {
		hostok = 1;
	} else 
	if (setupdata.root_hosts_access == 1) {
		hostok = 0;
	} else {
		loop = g_list_first(setupdata.root_hosts_lists);
		while (loop) {
			if (strcmp(hostname,(gchar *)loop->data) == 0) {
				/* found our login on the list */
				match = 1;
			}		
			loop = loop->next;
		}
		if ((setupdata.root_hosts_access == 2 && match) ||
		    (setupdata.root_hosts_access == 3 && !match)) {
			hostok = 1;
		} else  {
			hostok = 0;
		}
	}

	/* only when both the host and the user are allowed, allow access */
	if (userok && hostok) {
		return 1;
	} else {
		return 0;
	}
}


/* print usage-info */

void usage(gchar *cmd) {

	g_print("Usage: %s [options]  (Version: %s)\n", cmd, XCDROAST_VERSION);
	g_print("Options:\n");
	g_print("\t-d <debug level>\n");
	g_print("\t-c <config directory>  (currently: %s)\n", configdir);
	g_print("\t-l <lib directory>     (currently: %s)\n", sharedir);
/*	g_print("\t-r <root config-file>  (currently: %s)\n", rootconfig); */
	g_print("\t-o : Disable multibyte font support\n");
	g_print("\t-n : Disable cdrtools version check (use at own risk)\n");
	g_print("\t-i : Ignore SCSI-scan (allows you to start xcdroast without\n\t     any scsi-support)\n");
	g_print("\t-f \"<list of scsi-devices>\" : Won't scan for devices, but force\n\t     X-CD-Roast to use the given ones (semicolon seperated list).\n\t     Most useful on AIX or OpenBSD systems where scanning fails.\n");
	
	g_print("Some GTK-Options:\n");
	g_print("\t--display <remote host>\n");
	g_print("\t--sync\n");
	g_print("\t--no-xshm\n");
}


/* Misc-init-stuff. stuff done once at program-startup */
/* return 0 if config file ok loaded, 1 on failure */

gint init(gint argc, gchar *argv[]) { 
gchar tmp[MAXLINE];
gchar *p1;
gchar *alt_dev_string;
gint c, usercnf, noversioncheck, stat;
	
	language = -1;
	debug = 0;
	oldfontcode = 0;
	ignorescanbus = 0;
	noversioncheck = 0;
	alt_dev_string = NULL;
	strncpy(configdir, CONFIGDIR, MAXLINE);
	strncpy(rootconfig, ROOTCONFIG, MAXLINE);

#ifdef PRE_LIBDIR 
	/* use prefix as sharedir as it came from the makefile-option */
	strncpy(sharedir, PRE_LIBDIR, MAXLINE);
#else
	/* otherwise install our default prefix */
	strncpy(sharedir, LIBDIR, MAXLINE);
#endif

#ifdef CDRTOOLS_PREFIX
        /* use prefix as it came from the makefile-option */
        strncpy(prefixdir, CDRTOOLS_PREFIX, MAXLINE);
#else
# ifdef PREFIX
	/* use prefix as it came from the makefile-option */
	strncpy(prefixdir, PRE_PREFIX, MAXLINE);
# else
	/* otherwise install our default prefix */
	strncpy(prefixdir, PREFIX, MAXLINE);
# endif	
#endif	
	/* parse command-line */
	while ((c = getopt(argc,argv,"d:c:l:r:oinf:")) != EOF)
	switch ((gchar)c) {
	
	case 'd':
		debug = atoi(optarg);
		break;

	case 'c':
		strncpy(configdir, optarg, MAXLINE);
		break;

/*
	case 'r':
		strncpy(rootconfig, optarg, MAXLINE);
		break;
*/
	case 'l':
		strncpy(sharedir, optarg, MAXLINE);
		break;

	case 'o':
		oldfontcode = 1;
		break;

	case 'i':
		ignorescanbus = 1;
		break;

	case 'n':
		noversioncheck = 1;
		break;

	case 'f':
		alt_dev_string = g_strdup(optarg);
		break;

	default:
		usage(argv[0]);
		gtk_exit(1);
	}

	/* --- all the following commands were needed for pre alpha9
	   non root code --- */
	/* something needed for debian ?????*/
	/* setregid(getegid(),getegid()); */

	/* check which kind of shell runs us */
	/*
	runningbash2 = check_version_shell();
	dodebug(3, "/bin/sh is bash2? = %d\n", runningbash2);
	*/

	/* this call does swap the egid with the gid - needed for
 	   the nonroot mode */
	/*	fix_guid(); */

	/* get some system-info */
	system_platform = g_strdup(strip_string(get_uname_info(tmp)));
	if (gethostname(hostname,MAXLINE) != 0) {
		strncpy(hostname,"not_available",MAXLINE);
	}

	p1 = g_get_user_name();
	if (p1 != NULL) {
		strncpy(username,p1, MAXLINE);
	} else {
		strncpy(username,"not_available",MAXLINE);
	}

	/* subst ~/ by $HOME */
	check_tilde(configdir);

	dodebug(1, "Starting X-CD-Roast %s by %s@%s on %s\n", 
		XCDROAST_VERSION,  username, hostname, system_platform);
	dodebug(1, "debug level: %d\n", debug);
	dodebug(1, "configdir: %s\n", configdir);
	dodebug(1, "rootconfig: %s\n", rootconfig);
	dodebug(1, "libdir: %s\n",sharedir);


	/* load language files */
	g_snprintf(tmp,MAXLINE,"%s/lang/language.def", sharedir);
	load_langfile(tmp);
	g_snprintf(tmp,MAXLINE,"%s/lang/langhelp.def", sharedir);
	load_helpfile(tmp);

	/* look for enviroment-variable $LANG - if not found set language
	   to english */
	scan_lang();

	dodebug(3, "Checking X-CD-Roast wrapper permissions\n");
	stat = check_wrapper_binary();
	if (stat == 1) {
		/* we need a toplevel for the show_dialog function */
		toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL);
		gtk_widget_realize(toplevel);
		show_dialog(ICO_WARN, text(437), T_OK, NULL, NULL, 0);
		gtk_exit(1);
	}
	/* no root config file yet */
	if (stat == 2) {
		if (!isroot()) {
			/* we need a toplevel for the show_dialog function */
			toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL);
			gtk_widget_realize(toplevel);
			show_dialog(ICO_WARN, text(435), T_OK, NULL, NULL, 0);
			gtk_exit(1);
		} 
	}

	dodebug(3, "Checking for helper binaries (noversioncheck = %d)\n", noversioncheck);
	check_binaries(noversioncheck);


	/* config-directory available? */
	if (!is_directory(configdir)) {
		/* try to create directory */
		mkdir(configdir, 0700);
		dodebug(2, "trying to mkdir %s\n", configdir);
	}


	/* check for permissions */
#if !defined(__CYGWIN32__)
	/* check_root(); */
#endif
	parse_alt_devs(alt_dev_string);
	scanbus();
	scandrivers();
	scanblankmodes();
	scancharsets();

	dodebug(3, "Initializing global data structures\n");
	wav_in = -1;
	init_setupdata();
	init_curset();
	init_cdinfo();
	init_trackreadset();
	init_writeparams();
	init_masterparams();
	init_drv_options();
	imagelist = (GList *) NULL;
	writelist = (GList *) NULL;
	tocfiles = (GList *) NULL;
	strcpy(xcdroast_version_loaded, "");

	dolog(1, "Starting X-CD-Roast %s by %s@%s on %s\n", 
		XCDROAST_VERSION,  username, hostname, system_platform);

	/* load iso-options if available */
	g_snprintf(tmp,MAXLINE,"%s/%s", configdir, ISOOPTFILE);
	load_isooptions_file(tmp);

	/* load iso-headers if available */
	g_snprintf(tmp,MAXLINE,"%s/%s", configdir, ISOHEADERFILE);
	load_isoheaders_file(tmp);

	/* get the language from locale - can be overriden later */
	scan_lang();

	/* first load config-file from root */
	/* fix here guid, so that we are allowed to read the config */
	/* fix_guid(); */
	if (load_setup_config(rootconfig,1) != 0) {
		/* failed */
		if (!isroot()) {
			/* we need a toplevel for the show_dialog function */
			toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL);
			gtk_widget_realize(toplevel);
			show_dialog(ICO_WARN, text(435), T_OK, NULL, NULL, 0);
			gtk_exit(1);
		} else {
			/* first start for root - let him create config */
			/* restore guid again */
			/* fix_guid(); */
			return 1;
		}
	}
	/* restore guid again */
	/* fix_guid(); */

	/* set the language to the one defined in the root config */
        if (setupdata.language >= 0) {
	        language = setupdata.language;
       	}

	/* now check if the loaded root-config was really from root */
	if (get_file_owner(rootconfig) != 0) {
		/* we need a toplevel for the show_dialog function */
		toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL);
		gtk_widget_realize(toplevel);
		show_dialog(ICO_WARN, text(436), T_OK, NULL, NULL, 0);
		gtk_exit(1);
	}

	/* here check if the current user is allowed to run xcdroast */
	if (!isroot()) {
		if (!checkuserhost(username,hostname)) {
			/* we need a toplevel for the show_dialog function */
			toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL);
			gtk_widget_realize(toplevel);
			show_dialog(ICO_WARN, text(437), T_OK, NULL, NULL, 0);
			gtk_exit(1);
		}
	}


	/* load user config file - if possible */
	g_snprintf(tmp,MAXLINE,"%s/%s", configdir, CONFFILE);
	if (!isroot()) {
		/* load only when not root */
		usercnf = load_setup_config(tmp,0);
	} else {
		usercnf = 0;
	}
	if (usercnf == 0) {
		/* load ok */

		/* set language to the one in user-config */
	        if (setupdata.language >= 0) {
       		        language = setupdata.language;
        	}

		return 0;
	} else {
		/* load failed */
		strcpy(xcdroast_version_loaded,"");
		return 1;
	}
}