129
129
#include <printf.c>
133
int clen, blen, tlen;
133
int clen, blen, tlen;
137
outCh_OCA( void *bp, char c )
139
OCABuf *ocabp = (OCABuf *)bp;
142
if (ocabp->clen >= ocabp->blen) {
143
ocabp->blen = ocabp->blen * 3 / 2 + 100;
144
ocabp->buf = mrealloc( ocabp->buf, ocabp->blen );
146
ocabp->buf[ocabp->clen++] = c;
150
VASPrintf( char **strp, const char *fmt, va_list args )
152
OCABuf ocab = { 0, 0, 0, -1 };
154
doPrint( outCh_OCA, &ocab, fmt, args );
155
outCh_OCA( &ocab, 0 );
156
*strp = realloc( ocab.buf, ocab.clen );
163
ASPrintf( char **strp, const char *fmt, ... )
168
va_start( args, fmt );
169
len = VASPrintf( strp, fmt, args );
137
outCh_OCA(void *bp, char c)
139
OCABuf *ocabp = (OCABuf *)bp;
142
if (ocabp->clen >= ocabp->blen) {
143
ocabp->blen = ocabp->blen * 3 / 2 + 100;
144
ocabp->buf = mrealloc(ocabp->buf, ocabp->blen);
146
ocabp->buf[ocabp->clen++] = c;
150
VASPrintf(char **strp, const char *fmt, va_list args)
152
OCABuf ocab = { 0, 0, 0, -1 };
154
doPrint(outCh_OCA, &ocab, fmt, args);
156
*strp = realloc(ocab.buf, ocab.clen);
163
ASPrintf(char **strp, const char *fmt, ...)
169
len = VASPrintf(strp, fmt, args);
175
strCat( char **strp, const char *fmt, ... )
175
strCat(char **strp, const char *fmt, ...)
181
va_start( args, fmt );
182
el = VASPrintf( &str, fmt, args );
185
int ol = strlen( *strp );
186
tstr = mmalloc( el + ol + 1 );
187
memcpy( tstr, *strp, ol );
188
memcpy( tstr + ol, str, el + 1 );
182
el = VASPrintf(&str, fmt, args);
185
int ol = strlen(*strp);
186
tstr = mmalloc(el + ol + 1);
187
memcpy(tstr, *strp, ol);
188
memcpy(tstr + ol, str, el + 1);
197
198
#define WANT_CLOSE 1
199
200
typedef struct File {
200
char *buf, *eof, *cur;
201
char *buf, *eof, *cur;
201
202
#if defined(HAVE_MMAP) && defined(WANT_CLOSE)
207
readFile( File *file, const char *fn )
208
readFile(File *file, const char *fn)
212
if ((fd = open( fn, O_RDONLY )) < 0)
215
flen = lseek( fd, 0, SEEK_END );
213
if ((fd = open(fn, O_RDONLY)) < 0)
216
flen = lseek(fd, 0, SEEK_END);
217
218
# ifdef WANT_CLOSE
218
file->ismapped = False;
219
file->ismapped = False;
220
file->buf = mmap( 0, flen + 1, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0 );
221
file->buf = mmap(0, flen + 1, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
221
222
# ifdef WANT_CLOSE
223
file->ismapped = True;
224
file->ismapped = True;
230
file->buf = mmalloc( flen + 1 );
231
lseek( fd, 0, SEEK_SET );
232
if (read( fd, file->buf, flen ) != flen) {
235
fprintf( stderr, "Cannot read file\n" );
236
return False; /* maybe better abort? */
239
file->eof = file->buf + flen;
231
file->buf = mmalloc(flen + 1);
232
lseek(fd, 0, SEEK_SET);
233
if (read(fd, file->buf, flen) != flen) {
236
fprintf(stderr, "Cannot read file\n");
237
return False; /* maybe better abort? */
240
file->eof = file->buf + flen;
244
245
#ifdef WANT_CLOSE
246
freeBuf( File *file )
248
249
# ifdef HAVE_MMAP
250
munmap( file->buf, file->eof - file->buf );
251
munmap(file->buf, file->eof - file->buf);
258
isTrue( const char *val )
260
return !strcmp( val, "true" ) ||
261
!strcmp( val, "yes" ) ||
262
!strcmp( val, "on" ) ||
268
mkpdirs( const char *name, const char *what )
270
char *mfname = mstrdup( name );
274
for (i = 1; mfname[i]; i++)
275
if (mfname[i] == '/') {
277
if (stat( mfname, &st )) {
278
if (mkdir( mfname, 0755 )) {
279
fprintf( stderr, "Cannot create parent %s of %s directory %s: %s\n",
280
mfname, what, name, strerror( errno ) );
284
chmod( mfname, 0755 );
293
mkdirp( const char *name, int mode, const char *what, int existok )
297
if (stat( name, &st )) {
298
mkpdirs( name, what );
299
if (mkdir( name, mode )) {
300
fprintf( stderr, "Cannot create %s directory %s: %s\n",
301
what, name, strerror( errno ) );
259
isTrue(const char *val)
261
return !strcmp(val, "true") ||
262
!strcmp(val, "yes") ||
263
!strcmp(val, "on") ||
269
mkpdirs(const char *name, const char *what)
271
char *mfname = mstrdup(name);
275
for (i = 1; mfname[i]; i++)
276
if (mfname[i] == '/') {
278
if (stat(mfname, &st)) {
279
if (mkdir(mfname, 0755)) {
280
fprintf(stderr, "Cannot create parent %s of %s directory %s: %s\n",
281
mfname, what, name, strerror(errno));
294
mkdirp(const char *name, int mode, const char *what, int existok)
298
if (stat(name, &st)) {
300
if (mkdir(name, mode)) {
301
fprintf(stderr, "Cannot create %s directory %s: %s\n",
302
what, name, strerror(errno));
312
displace( const char *fn )
313
displace(const char *fn)
315
char bn[PATH_MAX + 4];
316
sprintf( bn, "%s.bak", fn ); /* won't overflow if only existing paths are passed */
316
char bn[PATH_MAX + 4];
317
sprintf(bn, "%s.bak", fn); /* won't overflow if only existing paths are passed */
947
952
/* Make a possibly modified copy of a file under KDMCONF */
949
copyFile( Entry *ce, int mode, int (*proc)( File * ) )
954
copyFile(Entry *ce, int mode, int (*proc)(File *))
959
if ((nname = (char *)getMapping( cfmap, ce->value ))) {
960
rt = inList( aflist, nname );
964
int olen = strlen( oldkde );
965
if (!memcmp( ce->value, oldkde, olen )) {
966
if (!memcmp( ce->value + olen, "/kdm/", 5 )) {
967
tptr = ce->value + olen + 4;
970
if (ce->value[olen] == '/') {
971
tptr = ce->value + olen;
977
int olen = strlen( oldxdm );
978
if (!memcmp( ce->value, oldxdm, olen ) && ce->value[olen] == '/') {
979
tptr = ce->value + olen;
983
if (!(tptr = strrchr( ce->value, '/' ))) {
984
fprintf( stderr, "Warning: cannot cope with relative path %s\n", ce->value );
964
if ((nname = (char *)getMapping(cfmap, ce->value))) {
965
rt = inList(aflist, nname);
969
int olen = strlen(oldkde);
970
if (!memcmp(ce->value, oldkde, olen)) {
971
if (!memcmp(ce->value + olen, "/kdm/", 5)) {
972
tptr = ce->value + olen + 4;
975
if (ce->value[olen] == '/') {
976
tptr = ce->value + olen;
982
int olen = strlen(oldxdm);
983
if (!memcmp(ce->value, oldxdm, olen) && ce->value[olen] == '/') {
984
tptr = ce->value + olen;
988
if (!(tptr = strrchr(ce->value, '/'))) {
989
fprintf(stderr, "Warning: cannot cope with relative path %s\n", ce->value);
988
ASPrintf( &nname, KDMCONF "%s", tptr );
989
if (inList( aflist, nname )) {
993
ASPrintf( &nname, KDMCONF "%s-%d", tptr , ++cnt );
994
} while (inList( aflist, nname ));
996
addMapping( &cfmap, ce->value, nname );
997
if (!readFile( &file, ce->value )) {
998
fprintf( stderr, "Warning: cannot copy file %s\n", ce->value );
1001
if (!proc || !proc( &file )) {
1002
if (!use_destdir && !strcmp( ce->value, nname ))
1003
linkedFile( nname );
1006
stat( ce->value, &st );
1007
writeCopy( nname + sizeof(KDMCONF), mode, st.st_mtime,
1008
file.buf, file.eof - file.buf );
1009
copiedFile( ce->value );
1012
writeCopy( nname + sizeof(KDMCONF), mode, 0,
1013
file.buf, file.eof - file.buf );
1014
editedFile( ce->value );
1016
if (strcmp( ce->value, nname ) && inNewDir( ce->value ) && !use_destdir)
1017
displace( ce->value );
993
ASPrintf(&nname, KDMCONF "%s", tptr);
994
if (inList(aflist, nname)) {
998
ASPrintf(&nname, KDMCONF "%s-%d", tptr , ++cnt);
999
} while (inList(aflist, nname));
1001
addMapping(&cfmap, ce->value, nname);
1002
if (!readFile(&file, ce->value)) {
1003
fprintf(stderr, "Warning: cannot copy file %s\n", ce->value);
1006
if (!proc || !proc(&file)) {
1007
if (!use_destdir && !strcmp(ce->value, nname)) {
1011
stat(ce->value, &st);
1012
writeCopy(nname + sizeof(KDMCONF), mode, st.st_mtime,
1013
file.buf, file.eof - file.buf);
1014
copiedFile(ce->value);
1017
writeCopy(nname + sizeof(KDMCONF), mode, 0,
1018
file.buf, file.eof - file.buf);
1019
editedFile(ce->value);
1021
if (strcmp(ce->value, nname) && inNewDir(ce->value) && !use_destdir)
1022
displace(ce->value);
1027
doLinkFile( const char *name )
1032
doLinkFile(const char *name)
1031
if (inList( aflist, name ))
1033
if (!readFile( &file, name )) {
1034
fprintf( stderr, "Warning: cannot read file %s\n", name );
1037
if (inNewDir( name ) && use_destdir) {
1040
writeCopy( name + sizeof(KDMCONF), st.st_mode, st.st_mtime,
1041
file.buf, file.eof - file.buf );
1036
if (inList(aflist, name))
1038
if (!readFile(&file, name)) {
1039
fprintf(stderr, "Warning: cannot read file %s\n", name);
1042
if (inNewDir(name) && use_destdir) {
1045
writeCopy(name + sizeof(KDMCONF), st.st_mode, st.st_mtime,
1046
file.buf, file.eof - file.buf);
1048
1054
/* Incorporate an existing file */
1050
linkFile( Entry *ce )
1052
if (ce->written && *ce->value)
1053
doLinkFile( ce->value );
1058
if (ce->written && *ce->value)
1059
doLinkFile(ce->value);
1056
1062
/* Create a new file in KDMCONF and fill it */
1058
writeFile( const char *tname, int mode, const char *cont )
1064
writeFile(const char *tname, int mode, const char *cont)
1060
FILE *f = createFile( tname + sizeof(KDMCONF), mode );
1066
FILE *f = createFile(tname + sizeof(KDMCONF), mode);
1068
handleBgCfg( Entry *ce, Section *cs )
1074
handleBgCfg(Entry *ce, Section *cs)
1070
if (!ce->active) /* can be only the X-*-Greeter one */
1071
writeFile( def_BackgroundCfg, 0644, def_background );
1076
if (!ce->active) { /* can be only the X-*-Greeter one */
1077
writeFile(def_BackgroundCfg, 0644, def_background);
1072
1078
#if 0 /* risk of kcontrol clobbering the original file */
1079
} else if (old_confs) {
1077
if (!copyFile( ce, 0644, 0 )) {
1078
if (!strcmp( cs->name, "X-*-Greeter" ))
1079
writeFile( def_BackgroundCfg, 0644, def_background );
1083
if (!copyFile(ce, 0644, 0)) {
1084
if (!strcmp(cs->name, "X-*-Greeter"))
1085
writeFile(def_BackgroundCfg, 0644, def_background);
1086
1092
#ifdef HAVE_VTS
1088
memMem( char *mem, int lmem, const char *smem, int lsmem )
1094
memMem(char *mem, int lmem, const char *smem, int lsmem)
1090
for (; lmem >= lsmem; mem++, lmem--)
1091
if (!memcmp( mem, smem, lsmem ))
1096
for (; lmem >= lsmem; mem++, lmem--)
1097
if (!memcmp(mem, smem, lsmem))
1096
1102
static int maxTTY, TTYmask;
1107
if (readFile( &it, "/etc/inittab" )) {
1108
usedFile( "/etc/inittab" );
1109
for (p = it.buf; p < it.eof; p = eol + 1) {
1110
for (eol = p; eol < it.eof && *eol != '\n'; eol++);
1112
if ((ep = memMem( p, eol - p, " tty", 4 )) &&
1113
ep < eol && isdigit( *ep ))
1115
if (ep + 1 == eol || isspace( *(ep + 1) ))
1117
else if (isdigit( *(ep + 1) ) &&
1118
(ep + 2 == eol || isspace( *(ep + 2) )))
1119
tty = (*ep - '0') * 10 + (*(ep + 1) - '0');
1122
TTYmask |= 1 << (tty - 1);
1113
if (readFile(&it, "/etc/inittab")) {
1114
usedFile("/etc/inittab");
1115
for (p = it.buf; p < it.eof; p = eol + 1) {
1116
for (eol = p; eol < it.eof && *eol != '\n'; eol++);
1118
if ((ep = memMem(p, eol - p, " tty", 4)) &&
1119
ep < eol && isdigit(*ep))
1121
if (ep + 1 == eol || isspace(*(ep + 1)))
1123
else if (isdigit(*(ep + 1)) &&
1124
(ep + 2 == eol || isspace(*(ep + 2))))
1125
tty = (*ep - '0') * 10 + (*(ep + 1) - '0');
1128
TTYmask |= 1 << (tty - 1);
1139
readWord( File *file, int EOFatEOL )
1145
readWord(File *file, int EOFatEOL)
1141
char *wordp, *wordBuffer;
1147
char *wordp, *wordBuffer;
1146
wordp = wordBuffer = file->cur;
1152
wordp = wordBuffer = file->cur;
1150
if (file->cur == file->eof) {
1152
if (wordp == wordBuffer)
1164
if (file->cur == file->eof)
1167
} while (c != '\n');
1170
if (EOFatEOL && !quoted) {
1174
if (wordp != wordBuffer) {
1181
if (wordp != wordBuffer)
1156
if (file->cur == file->eof) {
1158
if (wordp == wordBuffer)
1170
if (file->cur == file->eof)
1173
} while (c != '\n');
1176
if (EOFatEOL && !quoted) {
1180
if (wordp != wordBuffer) {
1187
if (wordp != wordBuffer)
1195
1201
/* backslashes are double-escaped - first parseArgs, then KConfig */
1197
1203
static StrList *
1198
splitArgs( const char *string )
1204
splitArgs(const char *string)
1203
StrList *args, **argp = &args;
1209
StrList *args, **argp = &args;
1206
if (isspace( *string )) {
1213
if (*string == '\\') {
1214
if (*++string != '\\')
1216
if (*++string != '\\')
1221
} else if (*string == '\'') {
1222
while (*++string != '\'' && *string) {
1223
if (*string == '\\' && *++string != '\\')
1227
} else if (*string == '"') {
1228
while (*++string != '"' && *string) {
1229
if (*string == '\\') {
1230
if (*++string != '\\')
1232
if (*++string != '\\')
1241
} while (*++string && !isspace( *string ));
1242
*argp = mmalloc( sizeof(**argp) );
1243
(*argp)->str = str = mmalloc( wlen + 1 );
1245
if (*word == '\\') {
1246
if (*++word != '\\')
1248
if (*++word != '\\')
1253
} else if (*word == '\'') {
1254
while (*++word != '\'' && *word) {
1255
if (*word == '\\' && *++word != '\\')
1259
} else if (*word == '"') {
1260
while (*++word != '"' && *word) {
1261
if (*word == '\\') {
1262
if (*++word != '\\')
1264
if (*++word != '\\')
1273
} while (*++word && !isspace( *word ));
1275
argp = &(*argp)->next;
1212
if (isspace(*string)) {
1219
if (*string == '\\') {
1220
if (*++string != '\\')
1222
if (*++string != '\\')
1227
} else if (*string == '\'') {
1228
while (*++string != '\'' && *string) {
1229
if (*string == '\\' && *++string != '\\')
1233
} else if (*string == '"') {
1234
while (*++string != '"' && *string) {
1235
if (*string == '\\') {
1236
if (*++string != '\\')
1238
if (*++string != '\\')
1248
} while (*++string && !isspace(*string));
1249
*argp = mmalloc(sizeof(**argp));
1250
(*argp)->str = str = mmalloc(wlen + 1);
1252
if (*word == '\\') {
1253
if (*++word != '\\')
1255
if (*++word != '\\')
1260
} else if (*word == '\'') {
1261
while (*++word != '\'' && *word) {
1262
if (*word == '\\' && *++word != '\\')
1266
} else if (*word == '"') {
1267
while (*++word != '"' && *word) {
1268
if (*word == '\\') {
1269
if (*++word != '\\')
1271
if (*++word != '\\')
1281
} while (*++word && !isspace(*word));
1283
argp = &(*argp)->next;
1281
1289
static const char *
1282
joinArgs( StrList *argv )
1290
joinArgs(StrList *argv)
1291
for (slen = 0, av = argv; slen++, av; av = av->next) {
1293
for (s = av->str; *s; s++, slen++)
1294
if (isspace( *s ) || *s == '\'')
1298
else if (*s == '\\')
1302
rs = str = mmalloc( slen );
1303
for (av = argv; av; av = av->next) {
1305
for (s = av->str; *s; s++)
1306
if (isspace( *s ) || *s == '\'')
1312
for (s = av->str; *s; s++) {
1315
if (*s == '"' || *s == '\\') {
1299
for (slen = 0, av = argv; slen++, av; av = av->next) {
1301
for (s = av->str; *s; s++, slen++)
1302
if (isspace(*s) || *s == '\'')
1306
else if (*s == '\\')
1310
rs = str = mmalloc(slen);
1311
for (av = argv; av; av = av->next) {
1313
for (s = av->str; *s; s++)
1314
if (isspace(*s) || *s == '\'')
1320
for (s = av->str; *s; s++) {
1323
if (*s == '"' || *s == '\\') {
1328
1336
typedef enum { InvalidDpy, LocalDpy, LocalUidDpy, ForeignDpy } DisplayMatchType;
1330
1338
static struct displayMatch {
1333
DisplayMatchType type;
1341
DisplayMatchType type;
1334
1342
} displayTypes[] = {
1335
{ "local", 5, LocalDpy },
1336
{ "local_uid", 9, LocalUidDpy },
1337
{ "foreign", 7, ForeignDpy },
1343
{ "local", 5, LocalDpy },
1344
{ "local_uid", 9, LocalUidDpy },
1345
{ "foreign", 7, ForeignDpy },
1340
1348
static DisplayMatchType
1341
parseDisplayType( const char *string, const char **atPos )
1349
parseDisplayType(const char *string, const char **atPos)
1343
struct displayMatch *d;
1351
struct displayMatch *d;
1346
for (d = displayTypes; d < displayTypes + as(displayTypes); d++) {
1347
if (!memcmp( d->name, string, d->len ) &&
1348
(!string[d->len] || string[d->len] == '@'))
1350
if (string[d->len] == '@' && string[d->len + 1])
1351
*atPos = string + d->len + 1;
1354
for (d = displayTypes; d < displayTypes + as(displayTypes); d++) {
1355
if (!memcmp(d->name, string, d->len) &&
1356
(!string[d->len] || string[d->len] == '@'))
1358
if (string[d->len] == '@' && string[d->len + 1])
1359
*atPos = string + d->len + 1;
1358
1366
typedef struct serverEntry {
1359
struct serverEntry *next;
1360
const char *name, *class2, *console, *owner, *argvs, *arglvs;
1361
StrList *argv, *arglv;
1362
DisplayMatchType type;
1367
struct serverEntry *next;
1368
const char *name, *class2, *console, *owner, *argvs, *arglvs;
1369
StrList *argv, *arglv;
1370
DisplayMatchType type;
1367
mstrcmp( const char *s1, const char *s2 )
1375
mstrcmp(const char *s1, const char *s2)
1375
return strcmp( s1, s2 );
1383
return strcmp(s1, s2);
1379
absorbXservers( const char *sect ATTR_UNUSED, char **value )
1387
absorbXservers(const char *sect ATTR_UNUSED, char **value)
1381
ServerEntry *se, *se1, *serverList, **serverPtr;
1382
const char *word, *word2;
1383
char *sdpys, *rdpys;
1384
StrList **argp, **arglp, *ap, *ap2;
1386
int nldpys = 0, nrdpys = 0, dpymask = 0;
1387
int cpuid, cpcmd, cpcmdl;
1389
ServerEntry *se, *se1, *serverList, **serverPtr;
1390
const char *word, *word2;
1391
char *sdpys, *rdpys;
1392
StrList **argp, **arglp, *ap, *ap2;
1394
int nldpys = 0, nrdpys = 0, dpymask = 0;
1395
int cpuid, cpcmd, cpcmdl;
1388
1396
#ifdef HAVE_VTS
1392
if (**value == '/') {
1393
if (!readFile( &file, *value ))
1398
file.eof = *value + strlen( *value );
1400
file.cur = file.buf;
1400
if (**value == '/') {
1401
if (!readFile(&file, *value))
1406
file.eof = *value + strlen(*value);
1408
file.cur = file.buf;
1402
serverPtr = &serverList;
1410
serverPtr = &serverList;
1403
1411
#ifdef HAVE_VTS
1406
while ((word = readWord( &file, 0 ))) {
1407
se = mcalloc( sizeof(*se) );
1409
if (!(word = readWord( &file, 1 )))
1411
se->type = parseDisplayType( word, &se->console );
1412
if (se->type == InvalidDpy) {
1414
if (!(word = readWord( &file, 1 )))
1416
se->type = parseDisplayType( word, &se->console );
1417
if (se->type == InvalidDpy) {
1418
while (readWord( &file, 1 ));
1422
if (se->type == LocalUidDpy)
1423
if (!(se->owner = readWord( &file, 1 )))
1425
word = readWord( &file, 1 );
1426
if (word && !strcmp( word, "reserve" )) {
1428
word = readWord( &file, 1 );
1430
if ((se->type != ForeignDpy) != (word != 0))
1436
if (word[0] == 'v' && word[1] == 't')
1437
se->vt = atoi( word + 2 );
1438
else if (!strcmp( word, "-crt" )) { /* SCO style */
1439
if (!(word = readWord( &file, 1 )) ||
1440
memcmp( word, "/dev/tty", 8 ))
1442
se->vt = atoi( word + 8 );
1445
if (strcmp( word, se->name )) {
1446
ap = mmalloc( sizeof(*ap) );
1448
if (!strcmp( word, "-nolisten" )) {
1449
if (!(word2 = readWord( &file, 1 )))
1451
ap2 = mmalloc( sizeof(*ap2) );
1454
if (!strcmp( word2, "unix" )) {
1466
word = readWord( &file, 1 );
1469
if (se->type != ForeignDpy) {
1471
dpymask |= 1 << atoi( se->name + 1 );
1476
serverPtr = &se->next;
1481
/* don't copy only if all local displays are ordered and have a vt */
1484
for (se = serverList, mtty = maxTTY; se; se = se->next)
1485
if (se->type != ForeignDpy) {
1487
if (se->vt != mtty) {
1494
for (se = serverList; se; se = se->next) {
1495
se->argvs = joinArgs( se->argv );
1496
se->arglvs = joinArgs( se->arglv );
1499
se1 = 0, cpuid = cpcmd = cpcmdl = False;
1500
for (se = serverList; se; se = se->next)
1501
if (se->type != ForeignDpy) {
1505
if (strcmp( se1->argvs, se->argvs ))
1507
if (strcmp( se1->arglvs, se->arglvs ))
1509
if (mstrcmp( se1->owner, se->owner ))
1514
putFqVal( "X-:*-Core", "ServerCmd", se1->argvs );
1516
putFqVal( "X-:*-Core", "ServerUID", se1->owner );
1517
putFqVal( "X-:*-Core", "ServerArgsLocal", se1->arglvs );
1518
for (se = serverList; se; se = se->next)
1519
if (se->type != ForeignDpy) {
1521
sprintf( sec, "X-%s-Core", se->name );
1523
putFqVal( sec, "ServerCmd", se->argvs );
1525
putFqVal( sec, "ServerArgsLocal", se->arglvs );
1527
if (cpvt && se->vt) {
1529
sprintf( vt, "%d", se->vt );
1530
putFqVal( sec, "ServerVT", vt );
1414
while ((word = readWord(&file, 0))) {
1415
se = mcalloc(sizeof(*se));
1417
if (!(word = readWord(&file, 1)))
1419
se->type = parseDisplayType(word, &se->console);
1420
if (se->type == InvalidDpy) {
1422
if (!(word = readWord(&file, 1)))
1424
se->type = parseDisplayType(word, &se->console);
1425
if (se->type == InvalidDpy) {
1426
while (readWord(&file, 1));
1430
if (se->type == LocalUidDpy)
1431
if (!(se->owner = readWord(&file, 1)))
1433
word = readWord(&file, 1);
1434
if (word && !strcmp(word, "reserve")) {
1436
word = readWord(&file, 1);
1438
if ((se->type != ForeignDpy) != (word != 0))
1444
if (word[0] == 'v' && word[1] == 't') {
1445
se->vt = atoi(word + 2);
1446
} else if (!strcmp(word, "-crt")) { /* SCO style */
1447
if (!(word = readWord(&file, 1)) || memcmp(word, "/dev/tty", 8))
1449
se->vt = atoi(word + 8);
1452
if (strcmp(word, se->name)) {
1453
ap = mmalloc(sizeof(*ap));
1455
if (!strcmp(word, "-nolisten")) {
1456
if (!(word2 = readWord(&file, 1)))
1458
ap2 = mmalloc(sizeof(*ap2));
1461
if (!strcmp(word2, "unix")) {
1473
word = readWord(&file, 1);
1476
if (se->type != ForeignDpy) {
1478
dpymask |= 1 << atoi(se->name + 1);
1483
serverPtr = &se->next;
1488
/* don't copy only if all local displays are ordered and have a vt */
1491
for (se = serverList, mtty = maxTTY; se; se = se->next)
1492
if (se->type != ForeignDpy) {
1494
if (se->vt != mtty) {
1501
for (se = serverList; se; se = se->next) {
1502
se->argvs = joinArgs(se->argv);
1503
se->arglvs = joinArgs(se->arglv);
1506
se1 = 0, cpuid = cpcmd = cpcmdl = False;
1507
for (se = serverList; se; se = se->next)
1508
if (se->type != ForeignDpy) {
1512
if (strcmp(se1->argvs, se->argvs))
1514
if (strcmp(se1->arglvs, se->arglvs))
1516
if (mstrcmp(se1->owner, se->owner))
1521
putFqVal("X-:*-Core", "ServerCmd", se1->argvs);
1523
putFqVal("X-:*-Core", "ServerUID", se1->owner);
1524
putFqVal("X-:*-Core", "ServerArgsLocal", se1->arglvs);
1525
for (se = serverList; se; se = se->next)
1526
if (se->type != ForeignDpy) {
1528
sprintf(sec, "X-%s-Core", se->name);
1530
putFqVal(sec, "ServerCmd", se->argvs);
1532
putFqVal(sec, "ServerArgsLocal", se->arglvs);
1534
if (cpvt && se->vt) {
1536
sprintf(vt, "%d", se->vt);
1537
putFqVal(sec, "ServerVT", vt);
1534
putFqVal( sec, "ServerTTY", se->console );
1536
if (cpuid && se->owner)
1537
putFqVal( sec, "ServerUID", se->owner );
1542
for (se = serverList; se; se = se->next)
1543
strCat( se->reserve ? &rdpys : &sdpys,
1544
se->class2 ? ",%s_%s" : ",%s", se->name, se->class2 );
1547
/* add reserve dpys */
1548
if (nldpys < 4 && nldpys && !nrdpys)
1549
for (; nldpys < 4; nldpys++) {
1550
for (dn = 0; dpymask & (1 << dn); dn++);
1551
dpymask |= (1 << dn);
1552
strCat( &rdpys, ",:%d", dn );
1556
putFqVal( "General", "StaticServers", sdpys ? sdpys + 1 : "" );
1557
putFqVal( "General", "ReserveServers", rdpys ? rdpys + 1 : "" );
1559
if (**value == '/' && inNewDir( *value ) && !use_destdir)
1565
upd_servervts( Entry *ce, Section *cs ATTR_UNUSED )
1567
if (!ce->active) { /* there is only the Global one */
1568
#ifdef __linux__ /* XXX actually, sysvinit */
1570
ASPrintf( (char **)&ce->value, "-%d", maxTTY + 1 );
1571
ce->active = ce->written = True;
1577
upd_consolettys( Entry *ce, Section *cs ATTR_UNUSED )
1579
if (!ce->active) { /* there is only the Global one */
1580
#ifdef __linux__ /* XXX actually, sysvinit */
1585
for (i = 0, buf = 0; i < 16; i++)
1586
if (TTYmask & (1 << i))
1587
strCat( &buf, ",tty%d", i + 1 );
1589
ce->value = buf + 1;
1590
ce->active = ce->written = True;
1598
upd_servercmd( Entry *ce, Section *cs ATTR_UNUSED )
1605
if (!ce->active || oldver >= 0x0204)
1607
if (!(sa = splitArgs( ce->value )))
1609
ASPrintf( &svr, "%s -help 2>&1", sa->str );
1610
if (!(fp = popen( svr, "r" )))
1612
buf[fread( buf, 1, sizeof(buf) - 1, fp )] = 0;
1614
if (strstr( buf, "\n-br " ))
1615
addStr( &sa, "-br" );
1616
if (strstr( buf, "\n-novtswitch " ))
1617
addStr( &sa, "-novtswitch" );
1618
if (strstr( buf, "\n-quiet " ))
1619
addStr( &sa, "-quiet" );
1620
ce->value = joinArgs( sa );
1541
putFqVal(sec, "ServerTTY", se->console);
1543
if (cpuid && se->owner)
1544
putFqVal(sec, "ServerUID", se->owner);
1549
for (se = serverList; se; se = se->next)
1550
strCat(se->reserve ? &rdpys : &sdpys,
1551
se->class2 ? ",%s_%s" : ",%s", se->name, se->class2);
1554
/* add reserve dpys */
1555
if (nldpys < 4 && nldpys && !nrdpys)
1556
for (; nldpys < 4; nldpys++) {
1557
for (dn = 0; dpymask & (1 << dn); dn++);
1558
dpymask |= (1 << dn);
1559
strCat(&rdpys, ",:%d", dn);
1563
putFqVal("General", "StaticServers", sdpys ? sdpys + 1 : "");
1564
putFqVal("General", "ReserveServers", rdpys ? rdpys + 1 : "");
1566
if (**value == '/' && inNewDir(*value) && !use_destdir)
1572
upd_servervts(Entry *ce, Section *cs ATTR_UNUSED)
1574
if (!ce->active) { /* there is only the Global one */
1575
#ifdef __linux__ /* XXX actually, sysvinit */
1577
ASPrintf((char **)&ce->value, "-%d", maxTTY + 1);
1578
ce->active = ce->written = True;
1584
upd_consolettys(Entry *ce, Section *cs ATTR_UNUSED)
1586
if (!ce->active) { /* there is only the Global one */
1587
#ifdef __linux__ /* XXX actually, sysvinit */
1592
for (i = 0, buf = 0; i < 16; i++)
1593
if (TTYmask & (1 << i))
1594
strCat(&buf, ",tty%d", i + 1);
1596
ce->value = buf + 1;
1597
ce->active = ce->written = True;
1605
upd_servercmd(Entry *ce, Section *cs ATTR_UNUSED)
1612
if (!ce->active || oldver >= 0x0204)
1614
if (!(sa = splitArgs(ce->value)))
1616
ASPrintf(&svr, "%s -help 2>&1", sa->str);
1617
if (!(fp = popen(svr, "r")))
1619
buf[fread(buf, 1, sizeof(buf) - 1, fp)] = 0;
1621
if (strstr(buf, "\n-br "))
1623
if (strstr(buf, "\n-novtswitch "))
1624
addStr(&sa, "-novtswitch");
1625
if (strstr(buf, "\n-quiet "))
1626
addStr(&sa, "-quiet");
1627
ce->value = joinArgs(sa);
1626
cp_keyfile( Entry *ce, Section *cs ATTR_UNUSED )
1628
if (!ce->active) /* there is only the Global one */
1633
if (!copyFile( ce, 0600, 0 ))
1638
mk_xaccess( Entry *ce, Section *cs ATTR_UNUSED )
1640
if (!ce->active) /* there is only the Global one */
1641
writeFile( def_Xaccess, 0644, def_xaccess );
1645
copyFile( ce, 0644, 0 ); /* don't handle error, it will disable Xdmcp automatically */
1649
mk_willing( Entry *ce, Section *cs ATTR_UNUSED )
1653
if (!ce->active) /* there is only the Global one */
1656
if (!(fname = strchr( ce->value, '/' )))
1657
return; /* obviously in-line (or empty) */
1658
if (old_scripts || inNewDir( fname ))
1659
doLinkFile( fname );
1662
ce->value = KDMCONF "/Xwilling";
1663
ce->active = ce->written = True;
1664
writeFile( ce->value, 0755, def_willing );
1633
cp_keyfile(Entry *ce, Section *cs ATTR_UNUSED)
1635
if (!ce->active) /* there is only the Global one */
1640
if (!copyFile(ce, 0600, 0))
1645
mk_xaccess(Entry *ce, Section *cs ATTR_UNUSED)
1647
if (!ce->active) /* there is only the Global one */
1648
writeFile(def_Xaccess, 0644, def_xaccess);
1652
copyFile(ce, 0644, 0); /* don't handle error, it will disable Xdmcp automatically */
1656
mk_willing(Entry *ce, Section *cs ATTR_UNUSED)
1660
if (!ce->active) { /* there is only the Global one */
1663
if (!(fname = strchr(ce->value, '/')))
1664
return; /* obviously in-line (or empty) */
1665
if (old_scripts || inNewDir(fname)) {
1669
ce->value = KDMCONF "/Xwilling";
1670
ce->active = ce->written = True;
1671
writeFile(ce->value, 0755, def_willing);
1672
edit_resources( File *file )
1679
edit_resources(File *file)
1674
// XXX remove any login*, chooser*, ... resources
1681
// XXX remove any login*, chooser*, ... resources
1680
cp_resources( Entry *ce, Section *cs ATTR_UNUSED )
1687
cp_resources(Entry *ce, Section *cs ATTR_UNUSED)
1682
if (!ce->active) /* the X-*-Greeter one */
1687
if (!copyFile( ce, 0644, 0/*edit_resources*/ ))
1689
if (!ce->active) /* the X-*-Greeter one */
1694
if (!copyFile(ce, 0644, 0/*edit_resources*/))
1692
delstr( File *fil, const char *pat )
1699
delstr(File *fil, const char *pat)
1695
const char *pap, *paap;
1702
const char *pap, *paap;
1698
for (p = fil->buf; *p; p++) {
1699
for (pp = p, pap = pat; ; ) {
1702
memcpy( p + 1, pp, fil->eof - pp + 1 );
1703
fil->eof -= pp - p - 1;
1705
} else if (!memcmp( pap, "*/", 2 )) {
1707
while (!isspace( *pap ))
1712
for (bpp = ++pp; *pp != '/'; pp++)
1713
if (!*pp || isspace( *pp ))
1716
if ((pp - bpp != pap - paap) || memcmp( bpp, paap, pap - paap ))
1718
} else if (*pap == '\t') {
1720
while (*pp == ' ' || *pp == '\t')
1722
} else if (*pap == '[') {
1726
fprintf( stderr, "Internal error: unterminated char set\n" );
1730
while (*++pap != ']')
1732
fprintf( stderr, "Internal error: unterminated char set\n" );
1744
while (*pp == ' ' || *pp == '\t')
1705
for (p = fil->buf; *p; p++) {
1706
for (pp = p, pap = pat; ;) {
1709
memcpy(p + 1, pp, fil->eof - pp + 1);
1710
fil->eof -= pp - p - 1;
1712
} else if (!memcmp(pap, "*/", 2)) {
1714
while (!isspace(*pap))
1719
for (bpp = ++pp; *pp != '/'; pp++)
1720
if (!*pp || isspace(*pp))
1723
if ((pp - bpp != pap - paap) || memcmp(bpp, paap, pap - paap))
1725
} else if (*pap == '\t') {
1727
while (*pp == ' ' || *pp == '\t')
1729
} else if (*pap == '[') {
1733
fprintf(stderr, "Internal error: unterminated char set\n");
1737
while (*++pap != ']')
1739
fprintf(stderr, "Internal error: unterminated char set\n");
1751
while (*pp == ' ' || *pp == '\t')
1853
"exec sessreg -a -l $DISPLAY -x */Xservers -u " _PATH_UTMP " $USER\n" ) |
1860
"exec sessreg -a -l $DISPLAY -x */Xservers -u " _PATH_UTMP " $USER\n") |
1855
1862
#endif /* _AIX */
1857
1864
"exec sessreg -a -l $DISPLAY"
1859
1866
" -x */Xservers"
1863
"exec sessreg -a -l $DISPLAY -u /var/run/utmp -x */Xservers $USER\n" );
1864
putVal( "UseSessReg", chg2 ? "true" : "false" );
1870
"exec sessreg -a -l $DISPLAY -u /var/run/utmp -x */Xservers $USER\n");
1871
putVal("UseSessReg", chg2 ? "true" : "false");
1870
mk_startup( Entry *ce, Section *cs )
1877
mk_startup(Entry *ce, Section *cs)
1872
setSect( cs->name );
1873
if (old_scripts || mixed_scripts)
1876
if (ce->active && inNewDir( ce->value )) {
1877
if (mod_usebg || oldver < 0x0203)
1878
copyFile( ce, 0755, edit_startup );
1882
ce->value = KDMCONF "/Xstartup";
1883
ce->active = ce->written = True;
1884
writeFile( ce->value, 0755, def_startup );
1880
if (old_scripts || mixed_scripts) {
1883
if (ce->active && inNewDir(ce->value)) {
1884
if (mod_usebg || oldver < 0x0203)
1885
copyFile(ce, 0755, edit_startup);
1889
ce->value = KDMCONF "/Xstartup";
1890
ce->active = ce->written = True;
1891
writeFile(ce->value, 0755, def_startup);
1890
edit_reset( File *file )
1897
edit_reset(File *file)
1895
1902
"if [[] -f /usr/lib/X11/xdm/sessreg ]; then\n"
1896
1903
" devname=`echo $DISPLAY | /usr/bin/sed -e 's/[[]:\\.]/_/g' | /usr/bin/cut -c1-8`\n"
1897
1904
" exec /usr/lib/X11/xdm/sessreg -d -l [kx]dm/$devname $USER\n"
1902
"exec sessreg -d -l $DISPLAY -x */Xservers -u " _PATH_UTMP " $USER\n" ) |
1909
"exec sessreg -d -l $DISPLAY -x */Xservers -u " _PATH_UTMP " $USER\n") |
1904
1911
#endif /* _AIX */
1906
1913
"exec sessreg -d -l $DISPLAY"
1908
1915
" -x */Xservers"
1912
"exec sessreg -d -l $DISPLAY -u /var/run/utmp -x */Xservers $USER\n" );
1916
mk_reset( Entry *ce, Section *cs ATTR_UNUSED )
1918
if (old_scripts || mixed_scripts)
1921
if (ce->active && inNewDir( ce->value )) {
1922
if (oldver < 0x0203)
1923
copyFile( ce, 0755, edit_reset );
1927
ce->value = KDMCONF "/Xreset";
1928
ce->active = ce->written = True;
1929
writeFile( ce->value, 0755, def_reset );
1935
mk_session( Entry *ce, Section *cs ATTR_UNUSED )
1940
if ((old_scripts || (ce->active && inNewDir( ce->value ))) &&
1944
tmpf = locate( "mktemp" ) ?
1945
"`mktemp /tmp/xsess-env-XXXXXX`" :
1946
locate( "tempfile" ) ?
1948
"$HOME/.xsession-env-$DISPLAY";
1949
ASPrintf( &def_session, "%s%s%s", def_session1, tmpf, def_session2 );
1950
ce->value = KDMCONF "/Xsession";
1951
ce->active = ce->written = True;
1952
writeFile( ce->value, 0755, def_session );
1957
upd_language( Entry *ce, Section *cs ATTR_UNUSED )
1959
if (!strcmp( ce->value, "C" ))
1960
ce->value = (char *)"en_US";
1964
upd_guistyle( Entry *ce, Section *cs ATTR_UNUSED )
1966
if (!strcmp( ce->value, "Motif+" ))
1967
ce->value = (char *)"MotifPlus";
1968
else if (!strcmp( ce->value, "KDE" ))
1969
ce->value = (char *)"Default";
1973
upd_showusers( Entry *ce, Section *cs )
1975
if (!strcmp( ce->value, "All" ))
1976
ce->value = (char *)"NotHidden";
1977
else if (!strcmp( ce->value, "None" )) {
1979
putFqVal( cs->name, "UserList", "false" );
1980
ce->value = (char *)"Selected";
1919
"exec sessreg -d -l $DISPLAY -u /var/run/utmp -x */Xservers $USER\n");
1923
mk_reset(Entry *ce, Section *cs ATTR_UNUSED)
1925
if (old_scripts || mixed_scripts) {
1928
if (ce->active && inNewDir(ce->value)) {
1929
if (oldver < 0x0203)
1930
copyFile(ce, 0755, edit_reset);
1934
ce->value = KDMCONF "/Xreset";
1935
ce->active = ce->written = True;
1936
writeFile(ce->value, 0755, def_reset);
1942
mk_session(Entry *ce, Section *cs ATTR_UNUSED)
1947
if ((old_scripts || (ce->active && inNewDir(ce->value))) &&
1951
tmpf = locate("mktemp") ?
1952
"`mktemp /tmp/xsess-env-XXXXXX`" :
1953
locate("tempfile") ?
1955
"$HOME/.xsession-env-$DISPLAY";
1956
ASPrintf(&def_session, "%s%s%s", def_session1, tmpf, def_session2);
1957
ce->value = KDMCONF "/Xsession";
1958
ce->active = ce->written = True;
1959
writeFile(ce->value, 0755, def_session);
1964
upd_language(Entry *ce, Section *cs ATTR_UNUSED)
1966
if (!strcmp(ce->value, "C"))
1967
ce->value = (char *)"en_US";
1971
upd_guistyle(Entry *ce, Section *cs ATTR_UNUSED)
1973
if (!strcmp(ce->value, "Motif+"))
1974
ce->value = (char *)"MotifPlus";
1975
else if (!strcmp(ce->value, "KDE"))
1976
ce->value = (char *)"Default";
1980
upd_showusers(Entry *ce, Section *cs)
1982
if (!strcmp(ce->value, "All")) {
1983
ce->value = (char *)"NotHidden";
1984
} else if (!strcmp(ce->value, "None")) {
1986
putFqVal(cs->name, "UserList", "false");
1987
ce->value = (char *)"Selected";
1986
1993
static const char *defminuid, *defmaxuid;
1989
upd_minshowuid( Entry *ce, Section *cs ATTR_UNUSED )
1992
ce->value = defminuid;
1993
ce->active = ce->written = True;
1998
upd_maxshowuid( Entry *ce, Section *cs ATTR_UNUSED )
2001
ce->value = defmaxuid;
2002
ce->active = ce->written = True;
2007
upd_hiddenusers( Entry *ce, Section *cs )
2010
const char *msu, *pt, *et;
2012
unsigned minuid, maxuid;
2018
msu = getFqVal( cs->name, "MinShowUID", "0" );
2019
sscanf( msu, "%u", &minuid );
2020
msu = getFqVal( cs->name, "MaxShowUID", "65535" );
2021
sscanf( msu, "%u", &maxuid );
2026
et = strpbrk( pt, ";," );
2028
memcpy( nbuf, pt, et - pt );
2032
if ((pw = getpwnam( nbuf ))) {
2034
(pw->pw_uid >= minuid && pw->pw_uid <= maxuid))
2037
strCat( &nv, ",%s", nbuf );
2039
nv = mstrdup( nbuf );
2046
ce->value = nv ? nv : "";
2050
upd_forgingseed( Entry *ce, Section *cs ATTR_UNUSED )
2053
ASPrintf( (char **)&ce->value, "%d", time( 0 ) );
2054
ce->active = ce->written = True;
2059
upd_fifodir( Entry *ce, Section *cs ATTR_UNUSED )
2066
dir = ce->active ? ce->value : def_FifoDir;
2068
chmod( dir, st.st_mode | 0755 );
1996
upd_minshowuid(Entry *ce, Section *cs ATTR_UNUSED)
1999
ce->value = defminuid;
2000
ce->active = ce->written = True;
2005
upd_maxshowuid(Entry *ce, Section *cs ATTR_UNUSED)
2008
ce->value = defmaxuid;
2009
ce->active = ce->written = True;
2014
upd_hiddenusers(Entry *ce, Section *cs)
2017
const char *msu, *pt, *et;
2019
unsigned minuid, maxuid;
2025
msu = getFqVal(cs->name, "MinShowUID", "0");
2026
sscanf(msu, "%u", &minuid);
2027
msu = getFqVal(cs->name, "MaxShowUID", "65535");
2028
sscanf(msu, "%u", &maxuid);
2033
et = strpbrk(pt, ";,");
2035
memcpy(nbuf, pt, et - pt);
2040
if ((pw = getpwnam(nbuf))) {
2042
(pw->pw_uid >= minuid && pw->pw_uid <= maxuid))
2045
strCat(&nv, ",%s", nbuf);
2054
ce->value = nv ? nv : "";
2058
upd_forgingseed(Entry *ce, Section *cs ATTR_UNUSED)
2061
ASPrintf((char **)&ce->value, "%d", time(0));
2062
ce->active = ce->written = True;
2067
upd_fifodir(Entry *ce, Section *cs ATTR_UNUSED)
2074
dir = ce->active ? ce->value : def_FifoDir;
2076
chmod(dir, st.st_mode | 0755);
2071
2079
static gid_t greeter_gid;
2072
2080
static uid_t greeter_uid;
2075
upd_greeteruid( Entry *ce, Section *cs ATTR_UNUSED )
2081
if (use_destdir || !ce->active)
2083
if (!(pw = getpwnam( ce->value ))) {
2084
uid = strtol( ce->value, &ok, 10 );
2085
if (*ok || !(pw = getpwuid( uid ))) {
2086
if (!access( "/etc/debian_version", R_OK )
2087
&& (adduser = locate( "adduser" ))) {
2088
const char *args[] = {
2089
adduser, "--system", "--group",
2090
"--home", "/var", "--no-create-home",
2093
if (runAndWait( (char **)args )) {
2094
fprintf( stderr, "Warning: Creation of missing GreeterUID"
2095
" user %s failed\n", ce->value );
2100
fprintf( stderr, "Warning: Do not know how to create missing"
2101
" GreeterUID user %s\n", ce->value );
2105
if (!(pw = getpwnam( ce->value ))) {
2106
fprintf( stderr, "Warning: Newly created GreeterUID user %s"
2107
" still missing!?\n", ce->value );
2113
greeter_uid = pw->pw_uid;
2114
greeter_gid = pw->pw_gid;
2118
upd_datadir( Entry *ce, Section *cs ATTR_UNUSED )
2120
char *oldsts, *newsts;
2126
dir = ce->active ? ce->value : def_DataDir;
2127
ASPrintf( &newsts, "%s/kdmsts", dir );
2128
if (mkdirp( dir, 0755, "data", 0 ) && oldkde) {
2129
ASPrintf( &oldsts, "%s/kdm/kdmsts", oldkde );
2130
rename( oldsts, newsts );
2132
if (stat( dir, &st ))
2134
if ((st.st_uid != greeter_uid || st.st_gid != greeter_gid) &&
2135
chown( dir, greeter_uid, greeter_gid ))
2136
fprintf( stderr, "Warning: Cannot assign ownership of data directory"
2137
" %s: %s\n", dir, strerror( errno ) );
2138
if (stat( newsts, &st ))
2140
if ((st.st_uid != greeter_uid || st.st_gid != greeter_gid) &&
2141
chown( newsts, greeter_uid, greeter_gid ))
2142
fprintf( stderr, "Warning: Cannot assign ownership of status file"
2143
" %s: %s\n", newsts, strerror( errno ) );
2147
upd_userlogfile( Entry *ce, Section *cs ATTR_UNUSED )
2151
if ((p = strstr( ce->value, "%s" )))
2152
ASPrintf( (char **)&ce->value, "%.*s%%d%s", p - ce->value, ce->value, p + 2 );
2083
upd_greeteruid(Entry *ce, Section *cs ATTR_UNUSED)
2089
if (use_destdir || !ce->active)
2091
if (!(pw = getpwnam(ce->value))) {
2092
uid = strtol(ce->value, &ok, 10);
2093
if (*ok || !(pw = getpwuid(uid))) {
2094
if (!access("/etc/debian_version", R_OK)
2095
&& (adduser = locate("adduser"))) {
2096
const char *args[] = {
2097
adduser, "--system", "--group",
2098
"--home", "/var", "--no-create-home",
2101
if (runAndWait((char **)args)) {
2102
fprintf(stderr, "Warning: Creation of missing GreeterUID"
2103
" user %s failed\n", ce->value);
2108
fprintf(stderr, "Warning: Do not know how to create missing"
2109
" GreeterUID user %s\n", ce->value);
2113
if (!(pw = getpwnam(ce->value))) {
2114
fprintf(stderr, "Warning: Newly created GreeterUID user %s"
2115
" still missing!?\n", ce->value);
2121
greeter_uid = pw->pw_uid;
2122
greeter_gid = pw->pw_gid;
2126
upd_datadir(Entry *ce, Section *cs ATTR_UNUSED)
2128
char *oldsts, *newsts;
2134
dir = ce->active ? ce->value : def_DataDir;
2135
ASPrintf(&newsts, "%s/kdmsts", dir);
2136
if (mkdirp(dir, 0755, "data", 0) && oldkde) {
2137
ASPrintf(&oldsts, "%s/kdm/kdmsts", oldkde);
2138
rename(oldsts, newsts);
2142
if ((st.st_uid != greeter_uid || st.st_gid != greeter_gid) &&
2143
chown(dir, greeter_uid, greeter_gid))
2144
fprintf(stderr, "Warning: Cannot assign ownership of data directory"
2145
" %s: %s\n", dir, strerror(errno));
2146
if (stat(newsts, &st))
2148
if ((st.st_uid != greeter_uid || st.st_gid != greeter_gid) &&
2149
chown(newsts, greeter_uid, greeter_gid))
2150
fprintf(stderr, "Warning: Cannot assign ownership of status file"
2151
" %s: %s\n", newsts, strerror(errno));
2155
upd_userlogfile(Entry *ce, Section *cs ATTR_UNUSED)
2159
if ((p = strstr(ce->value, "%s")))
2160
ASPrintf((char **)&ce->value, "%.*s%%d%s", p - ce->value, ce->value, p + 2);
2158
2166
* Do not complain if source cannot be read.
2161
copyPlainFile( const char *from, const char *to )
2169
copyPlainFile(const char *from, const char *to)
2166
if (readFile( &file, from )) {
2167
if ((fd = open( to, O_WRONLY | O_CREAT | O_EXCL, 0644 )) >= 0) {
2168
size_t len = file.eof - file.buf;
2169
if (write( fd, file.buf, len ) != (ssize_t)len) {
2170
fprintf( stderr, "Warning: cannot write %s (disk full?)\n", to );
2173
if (close( fd ) < 0) {
2174
fprintf( stderr, "Warning: cannot write %s (disk full?)\n", to );
2177
} else if (errno != EEXIST)
2178
fprintf( stderr, "Warning: cannot create %s\n", to );
2174
if (readFile(&file, from)) {
2175
if ((fd = open(to, O_WRONLY | O_CREAT | O_EXCL, 0644)) >= 0) {
2176
size_t len = file.eof - file.buf;
2177
if (write(fd, file.buf, len) != (ssize_t)len) {
2178
fprintf(stderr, "Warning: cannot write %s (disk full?)\n", to);
2181
if (close(fd) < 0) {
2182
fprintf(stderr, "Warning: cannot write %s (disk full?)\n", to);
2185
} else if (errno != EEXIST) {
2186
fprintf(stderr, "Warning: cannot create %s\n", to);
2184
copyDir( const char *from, const char *to )
2189
char bn[PATH_MAX], bo[PATH_MAX];
2191
if (!(dir = opendir( from )))
2193
while ((ent = readdir( dir ))) {
2194
if (!strcmp( ent->d_name, "." ) || !strcmp( ent->d_name, ".." ))
2196
sprintf( bo, "%s/%s", from, ent->d_name );
2197
if (stat( bo, &st ) || !S_ISREG( st.st_mode ))
2199
sprintf( bn, "%s/%s", to, ent->d_name );
2200
copyPlainFile( bo, bn );
2207
upd_facedir( Entry *ce, Section *cs ATTR_UNUSED )
2209
char *oldpic, *newpic, *olddir;
2214
if (oldkdepfx) { /* Do we have a previous install? */
2215
/* This would be the prev install's default location */
2216
ASPrintf( &olddir, "%s/share/apps/kdm/faces", oldkdepfx );
2217
if (ce->active && strcmp( olddir, ce->value ))
2218
/* Not default location, so don't touch the setting. */
2220
/* Default location, so absorb it. */
2222
/* Don't copy if old dir == new new. */
2223
if (!strcmp( olddir, def_FaceDir ))
2227
if (mkdirp( def_FaceDir, 0755, "user face", True )) {
2228
const char *defpic = def_FaceDir "/.default.face.icon";
2229
const char *rootpic = def_FaceDir "/root.face.icon";
2230
if (oldkde && (!olddir || !copyDir( olddir, def_FaceDir )) &&
2231
oldver < 0x0201) /* This isn't exact - didn't inc version. */
2234
while ((pw = getpwent()))
2235
if (strcmp( pw->pw_name, "root" )) {
2236
ASPrintf( &oldpic, "%s/share/apps/kdm/pics/users/%s.png",
2237
oldkdepfx, pw->pw_name );
2238
ASPrintf( &newpic, def_FaceDir "/%s.face.icon", pw->pw_name );
2239
rename( oldpic, newpic );
2244
ASPrintf( &oldpic, "%s/share/apps/kdm/pics/users/default.png", oldkdepfx );
2245
if (!rename( oldpic, defpic ))
2247
ASPrintf( &oldpic, "%s/share/apps/kdm/pics/users/root.png", oldkdepfx );
2248
if (!rename( oldpic, rootpic ))
2252
ASPrintf( &oldpic, "%s/default1.png", facesrc );
2253
copyPlainFile( oldpic, defpic );
2256
ASPrintf( &oldpic, "%s/root1.png", facesrc );
2257
copyPlainFile( oldpic, rootpic );
2263
upd_sessionsdirs( Entry *ce, Section *cs ATTR_UNUSED )
2267
char olddir[PATH_MAX];
2270
sprintf( olddir, "%s/share/apps/kdm/sessions", oldkdepfx );
2271
olen = strlen( oldkde );
2272
sl = splitList( ce->value );
2273
for (sp = sl; sp; sp = sp->next) {
2274
if (!strcmp( sp->str, olddir ))
2275
sp->str = def_SessionsDirs;
2276
else if (!memcmp( sp->str, oldkde, olen ) &&
2277
!memcmp( sp->str + olen, "/kdm/", 5 ))
2280
sprintf( nd, "%s%s", newdir, sp->str + olen + 4 );
2281
mkdirp( nd, 0755, "sessions", False );
2282
copyDir( sp->str, nd );
2283
ASPrintf( (char **)&sp->str, KDMCONF "%s", sp->str + olen + 4 );
2286
ce->value = joinList( sl );
2289
sprintf( nd, "%s/sessions", newdir );
2290
mkdirp( nd, 0755, "sessions", False );
2295
upd_preloader( Entry *ce, Section *cs ATTR_UNUSED )
2297
if (ce->written) { /* implies oldkde != 0 */
2299
ASPrintf( &oldpl, "%s/bin/preloadkde", oldkdepfx );
2300
if (!strcmp( ce->value, oldpl ))
2301
ce->value = (char *)KDE_BINDIR "/preloadkde";
2193
copyDir(const char *from, const char *to)
2198
char bn[PATH_MAX], bo[PATH_MAX];
2200
if (!(dir = opendir(from)))
2202
while ((ent = readdir(dir))) {
2203
if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
2205
sprintf(bo, "%s/%s", from, ent->d_name);
2206
if (stat(bo, &st) || !S_ISREG(st.st_mode))
2208
sprintf(bn, "%s/%s", to, ent->d_name);
2209
copyPlainFile(bo, bn);
2216
upd_facedir(Entry *ce, Section *cs ATTR_UNUSED)
2218
char *oldpic, *newpic, *olddir;
2223
if (oldkdepfx) { /* Do we have a previous install? */
2224
/* This would be the prev install's default location */
2225
ASPrintf(&olddir, "%s/share/apps/kdm/faces", oldkdepfx);
2226
if (ce->active && strcmp(olddir, ce->value))
2227
/* Not default location, so don't touch the setting. */
2229
/* Default location, so absorb it. */
2231
/* Don't copy if old dir == new new. */
2232
if (!strcmp(olddir, def_FaceDir))
2237
if (mkdirp(def_FaceDir, 0755, "user face", True)) {
2238
const char *defpic = def_FaceDir "/.default.face.icon";
2239
const char *rootpic = def_FaceDir "/root.face.icon";
2240
if (oldkde && (!olddir || !copyDir(olddir, def_FaceDir)) &&
2241
oldver < 0x0201) /* This isn't exact - didn't inc version. */
2244
while ((pw = getpwent()))
2245
if (strcmp(pw->pw_name, "root")) {
2246
ASPrintf(&oldpic, "%s/share/apps/kdm/pics/users/%s.png",
2247
oldkdepfx, pw->pw_name);
2248
ASPrintf(&newpic, def_FaceDir "/%s.face.icon", pw->pw_name);
2249
rename(oldpic, newpic);
2254
ASPrintf(&oldpic, "%s/share/apps/kdm/pics/users/default.png", oldkdepfx);
2255
if (!rename(oldpic, defpic))
2257
ASPrintf(&oldpic, "%s/share/apps/kdm/pics/users/root.png", oldkdepfx);
2258
if (!rename(oldpic, rootpic))
2262
ASPrintf(&oldpic, "%s/default1.png", facesrc);
2263
copyPlainFile(oldpic, defpic);
2266
ASPrintf(&oldpic, "%s/root1.png", facesrc);
2267
copyPlainFile(oldpic, rootpic);
2273
upd_sessionsdirs(Entry *ce, Section *cs ATTR_UNUSED)
2277
char olddir[PATH_MAX];
2280
sprintf(olddir, "%s/share/apps/kdm/sessions", oldkdepfx);
2281
olen = strlen(oldkde);
2282
sl = splitList(ce->value);
2283
for (sp = sl; sp; sp = sp->next) {
2284
if (!strcmp(sp->str, olddir)) {
2285
sp->str = def_SessionsDirs;
2286
} else if (!memcmp(sp->str, oldkde, olen) &&
2287
!memcmp(sp->str + olen, "/kdm/", 5)) {
2289
sprintf(nd, "%s%s", newdir, sp->str + olen + 4);
2290
mkdirp(nd, 0755, "sessions", False);
2291
copyDir(sp->str, nd);
2292
ASPrintf((char **)&sp->str, KDMCONF "%s", sp->str + olen + 4);
2295
ce->value = joinList(sl);
2298
sprintf(nd, "%s/sessions", newdir);
2299
mkdirp(nd, 0755, "sessions", False);
2304
upd_preloader(Entry *ce, Section *cs ATTR_UNUSED)
2306
if (ce->written) { /* implies oldkde != 0 */
2308
ASPrintf(&oldpl, "%s/bin/preloadkde", oldkdepfx);
2309
if (!strcmp(ce->value, oldpl))
2310
ce->value = (char *)KDE_BINDIR "/preloadkde";
2307
2316
CONF_GEN_ENTRIES
2310
findSect( const char *name )
2319
findSect(const char *name)
2315
p = strrchr( name, '-' );
2318
for (i = 0; i < as(allSects); i++)
2319
if (!strcmp( allSects[i]->name, p ))
2321
fprintf( stderr, "Internal error: unknown section %s\n", name );
2324
p = strrchr(name, '-');
2327
for (i = 0; i < as(allSects); i++)
2328
if (!strcmp(allSects[i]->name, p))
2330
fprintf(stderr, "Internal error: unknown section %s\n", name);
2326
findEnt( Sect *sect, const char *key )
2335
findEnt(Sect *sect, const char *key)
2330
for (i = 0; i < sect->nents; i++)
2331
if (!strcmp( sect->ents[i].key, key ))
2332
return sect->ents + i;
2333
fprintf( stderr, "Internal error: unknown key %s in section %s\n",
2339
for (i = 0; i < sect->nents; i++)
2340
if (!strcmp(sect->ents[i].key, key))
2341
return sect->ents + i;
2342
fprintf(stderr, "Internal error: unknown key %s in section %s\n",
2578
2586
typedef struct KUpdEnt {
2579
const char *okey, *nsec, *nkey;
2580
void (*func)( const char *sect, char **value );
2587
const char *okey, *nsec, *nkey;
2588
void (*func)(const char *sect, char **value);
2583
2591
typedef struct KUpdSec {
2591
P_EnableChooser( const char *sect ATTR_UNUSED, char **value )
2599
P_EnableChooser(const char *sect ATTR_UNUSED, char **value)
2593
*value = (char *)(isTrue( *value ) ? "DefaultLocal" : "LocalOnly");
2601
*value = (char *)(isTrue(*value) ? "DefaultLocal" : "LocalOnly");
2598
P_UseLilo( const char *sect ATTR_UNUSED, char **value )
2606
P_UseLilo(const char *sect ATTR_UNUSED, char **value)
2600
*value = (char *)(isTrue( *value ) ? "Lilo" : "None");
2608
*value = (char *)(isTrue(*value) ? "Lilo" : "None");
2604
P_EchoMode( const char *sect ATTR_UNUSED, char **value )
2612
P_EchoMode(const char *sect ATTR_UNUSED, char **value)
2606
*value = (char *)(!strcmp( *value, "NoEcho" ) ? "false" : "true");
2614
*value = (char *)(!strcmp(*value, "NoEcho") ? "false" : "true");
2609
2617
CONF_GEN_KMERGE
2612
mergeKdmRcNewer( const char *path, int obsRet )
2620
mergeKdmRcNewer(const char *path, int obsRet)
2615
const char *cp, *sec, *key;
2616
RSection *rootsect, *cs;
2619
static char sname[64];
2623
const char *cp, *sec, *key;
2624
RSection *rootsect, *cs;
2627
static char sname[64];
2621
ASPrintf( &p, "%s/kdm/kdmrc", path );
2622
if (!(rootsect = readConfig( p ))) {
2626
for (cs = rootsect; cs; cs = cs->next)
2627
if (!strcmp( cs->name, "General" ))
2628
for (ce = cs->ents; ce; ce = ce->next)
2629
if (!strcmp( ce->key, "ConfigVersion" ))
2631
printf( "Information: ignoring pre-existing kdmrc %s from kde < 3.1\n", p );
2629
ASPrintf(&p, "%s/kdm/kdmrc", path);
2630
if (!(rootsect = readConfig(p))) {
2634
for (cs = rootsect; cs; cs = cs->next)
2635
if (!strcmp(cs->name, "General"))
2636
for (ce = cs->ents; ce; ce = ce->next)
2637
if (!strcmp(ce->key, "ConfigVersion"))
2639
printf("Information: ignoring pre-existing kdmrc %s from kde < 3.1\n", p);
2635
sscanf( ce->value, "%d.%d", &ma, &mi );
2636
oldver = (ma << 8) | mi;
2637
printf( "Information: reading pre-existing kdmrc %s (config version %d.%d)\n",
2641
for (cs = rootsect; cs; cs = cs->next) {
2642
cp = strrchr( cs->name, '-' );
2645
else if (cs->name[0] != 'X' || cs->name[1] != '-')
2647
for (i = 0; i < as(kupsects); i++)
2648
if (!strcmp( cp, kupsects[i].osec )) {
2649
for (ce = cs->ents; ce; ce = ce->next) {
2650
for (j = 0; j < kupsects[i].nents; j++)
2651
if (!strcmp( ce->key, kupsects[i].ents[j].okey )) {
2652
if (kupsects[i].ents[j].nsec == (char *)-1) {
2653
kupsects[i].ents[j].func( 0, &ce->value );
2656
if (!kupsects[i].ents[j].nsec)
2660
sprintf( sname, "%.*s-%s",
2661
(int)(cp - cs->name), cs->name,
2662
kupsects[i].ents[j].nsec );
2664
if (!kupsects[i].ents[j].nkey)
2667
key = kupsects[i].ents[j].nkey;
2668
if (kupsects[i].ents[j].func)
2669
kupsects[i].ents[j].func( sec, &ce->value );
2670
putFqVal( sec, key, ce->value );
2673
printf( "Information: dropping key %s from section [%s]\n",
2674
ce->key, cs->name );
2680
printf( "Information: dropping section [%s]\n", cs->name );
2684
applyDefs( kdmdefs_all, as(kdmdefs_all), path );
2643
sscanf(ce->value, "%d.%d", &ma, &mi);
2644
oldver = (ma << 8) | mi;
2645
printf("Information: reading pre-existing kdmrc %s (config version %d.%d)\n",
2649
for (cs = rootsect; cs; cs = cs->next) {
2650
cp = strrchr(cs->name, '-');
2653
else if (cs->name[0] != 'X' || cs->name[1] != '-')
2655
for (i = 0; i < as(kupsects); i++)
2656
if (!strcmp(cp, kupsects[i].osec)) {
2657
for (ce = cs->ents; ce; ce = ce->next) {
2658
for (j = 0; j < kupsects[i].nents; j++)
2659
if (!strcmp(ce->key, kupsects[i].ents[j].okey)) {
2660
if (kupsects[i].ents[j].nsec == (char *) - 1) {
2661
kupsects[i].ents[j].func(0, &ce->value);
2664
if (!kupsects[i].ents[j].nsec) {
2668
sprintf(sname, "%.*s-%s",
2669
(int)(cp - cs->name), cs->name,
2670
kupsects[i].ents[j].nsec);
2672
if (!kupsects[i].ents[j].nkey)
2675
key = kupsects[i].ents[j].nkey;
2676
if (kupsects[i].ents[j].func)
2677
kupsects[i].ents[j].func(sec, &ce->value);
2678
putFqVal(sec, key, ce->value);
2681
printf("Information: dropping key %s from section [%s]\n",
2689
printf("Information: dropping section [%s]\n", cs->name);
2694
applyDefs(kdmdefs_all, as(kdmdefs_all), path);
2690
2700
typedef struct XResEnt {
2692
const char *ksec, *kname;
2693
void (*func)( const char *sect, char **value );
2702
const char *ksec, *kname;
2703
void (*func)(const char *sect, char **value);
2697
handleXdmVal( const char *dpy, const char *key, char *value,
2698
const XResEnt *ents, int nents )
2702
char knameb[80], sname[80];
2704
for (i = 0; i < nents; i++)
2705
if (!strcmp( key, ents[i].xname ) ||
2706
(key[0] == toupper( ents[i].xname[0] ) &&
2707
!strcmp( key + 1, ents[i].xname + 1 )))
2709
if (ents[i].ksec == (char *)-1) {
2710
ents[i].func( 0, &value );
2713
sprintf( sname, ents[i].ksec, dpy );
2715
kname = ents[i].kname;
2718
sprintf( knameb, "%c%s",
2719
toupper( ents[i].xname[0] ), ents[i].xname + 1 );
2722
ents[i].func( sname, &value );
2723
putFqVal( sname, kname, value );
2729
P_list( const char *sect ATTR_UNUSED, char **value )
2734
for (st = *value, is = False, d = s = 0; st[s]; s++)
2735
if (st[s] == ' ' || st[s] == '\t') {
2747
P_authDir( const char *sect ATTR_UNUSED, char **value )
2751
l = strlen( *value );
2756
if ((*value)[l-1] == '/')
2758
if (!strncmp( *value, "/tmp/", 5 ) ||
2759
!strncmp( *value, "/var/tmp/", 9 ))
2761
printf( "Warning: Resetting inappropriate value %s for AuthDir to default\n",
2766
if ((l >= 4 && !strcmp( *value + l - 4, "/tmp" )) ||
2767
(l >= 6 && !strcmp( *value + l - 6, "/xauth" )) ||
2768
(l >= 8 && !strcmp( *value + l - 8, "/authdir" )) ||
2769
(l >= 10 && !strcmp( *value + l - 10, "/authfiles" )))
2771
ASPrintf( value, "%s/authdir", *value );
2775
P_openDelay( const char *sect, char **value )
2777
putFqVal( sect, "ServerTimeout", *value );
2781
P_noPassUsers( const char *sect, char **value ATTR_UNUSED )
2783
putFqVal( sect, "NoPassEnable", "true" );
2787
P_autoUser( const char *sect, char **value ATTR_UNUSED )
2789
putFqVal( sect, "AutoLoginEnable", "true" );
2707
handleXdmVal(const char *dpy, const char *key, char *value,
2708
const XResEnt *ents, int nents)
2712
char knameb[80], sname[80];
2714
for (i = 0; i < nents; i++)
2715
if (!strcmp(key, ents[i].xname) ||
2716
(key[0] == toupper(ents[i].xname[0]) &&
2717
!strcmp(key + 1, ents[i].xname + 1)))
2719
if (ents[i].ksec == (char *)-1) {
2720
ents[i].func(0, &value);
2723
sprintf(sname, ents[i].ksec, dpy);
2724
if (ents[i].kname) {
2725
kname = ents[i].kname;
2728
sprintf(knameb, "%c%s",
2729
toupper(ents[i].xname[0]), ents[i].xname + 1);
2732
ents[i].func(sname, &value);
2733
putFqVal(sname, kname, value);
2739
P_list(const char *sect ATTR_UNUSED, char **value)
2744
for (st = *value, is = False, d = s = 0; st[s]; s++)
2745
if (st[s] == ' ' || st[s] == '\t') {
2757
P_authDir(const char *sect ATTR_UNUSED, char **value)
2766
if ((*value)[l-1] == '/')
2768
if (!strncmp(*value, "/tmp/", 5) ||
2769
!strncmp(*value, "/var/tmp/", 9))
2771
printf("Warning: Resetting inappropriate value %s for AuthDir to default\n",
2776
if ((l >= 4 && !strcmp(*value + l - 4, "/tmp")) ||
2777
(l >= 6 && !strcmp(*value + l - 6, "/xauth")) ||
2778
(l >= 8 && !strcmp(*value + l - 8, "/authdir")) ||
2779
(l >= 10 && !strcmp(*value + l - 10, "/authfiles")))
2781
ASPrintf(value, "%s/authdir", *value);
2785
P_openDelay(const char *sect, char **value)
2787
putFqVal(sect, "ServerTimeout", *value);
2791
P_noPassUsers(const char *sect, char **value ATTR_UNUSED)
2793
putFqVal(sect, "NoPassEnable", "true");
2797
P_autoUser(const char *sect, char **value ATTR_UNUSED)
2799
putFqVal(sect, "AutoLoginEnable", "true");
2794
P_requestPort( const char *sect, char **value )
2804
P_requestPort(const char *sect, char **value)
2796
if (!strcmp( *value, "0" )) {
2798
putFqVal( sect, "Enable", "false" );
2800
putFqVal( sect, "Enable", "true" );
2806
if (!strcmp(*value, "0")) {
2808
putFqVal(sect, "Enable", "false");
2810
putFqVal(sect, "Enable", "true");
2804
2815
static int kdmrcmode = 0644;
2807
P_autoPass( const char *sect ATTR_UNUSED, char **value ATTR_UNUSED )
2818
P_autoPass(const char *sect ATTR_UNUSED, char **value ATTR_UNUSED)
2812
2823
CONF_GEN_XMERGE
3019
3029
" --no-in-notice\n"
3020
3030
" Do not put the notice about --in being used into the generated README.\n"
3024
if (!strcmp( argv[ap], "--no-old" )) {
3028
if (!strcmp( argv[ap], "--old-scripts" )) {
3032
if (!strcmp( argv[ap], "--no-old-scripts" )) {
3033
no_old_scripts = True;
3036
if (!strcmp( argv[ap], "--old-confs" )) {
3040
if (!strcmp( argv[ap], "--no-old-xdm" )) {
3044
if (!strcmp( argv[ap], "--no-old-kde" )) {
3048
if (!strcmp( argv[ap], "--no-backup" )) {
3052
if (!strcmp( argv[ap], "--no-in-notice" )) {
3053
no_in_notice = True;
3057
if (!strcmp( argv[ap], "--in" ))
3059
else if (!strcmp( argv[ap], "--old-xdm" ))
3061
else if (!strcmp( argv[ap], "--old-kde" ))
3063
else if (!strcmp( argv[ap], "--face-src" ))
3066
fprintf( stderr, "Unknown command line option '%s', try --help\n", argv[ap] );
3069
if (ap + 1 == argc || argv[ap + 1][0] == '-') {
3070
fprintf( stderr, "Missing argument to option '%s', try --help\n", argv[ap] );
3073
*where = argv[++ap];
3075
if (memcmp( newdir, KDMCONF, sizeof(KDMCONF) ))
3078
if (!mkdirp( newdir, 0755, "target", True ))
3081
makeDefaultConfig();
3085
if ((dir = opendir( newdir ))) {
3088
while ((ent = readdir( dir ))) {
3090
if (!strcmp( ent->d_name, "." ) || !strcmp( ent->d_name, ".." ))
3092
l = sprintf( bn, "%s/%s", newdir, ent->d_name ); /* cannot overflow (kernel would not allow the creation of a longer path) */
3093
if (!stat( bn, &st ) && !S_ISREG( st.st_mode ))
3095
if (no_backup || !memcmp( bn + l - 4, ".bak", 5 ))
3101
for (; bfl; bfl = bfl->next)
3102
displace( bfl->str );
3106
if (!mergeKdmRcNewer( oldkde, True ) && !mergeKdmRcOld( oldkde )) {
3108
"Cannot read pre-existing kdmrc at specified location\n" );
3111
} else if (!no_old_kde) {
3112
for (i = 0; i < as(oldkdes); i++) {
3113
if (i && !strcmp( oldkdes[0], oldkdes[i] ))
3115
if (mergeKdmRcNewer( oldkdes[i], 0 )) {
3116
oldkde = oldkdes[i];
3119
mergeKdmRcOld( oldkdes[i] ); /* only prints a message */
3034
if (!strcmp(argv[ap], "--no-old")) {
3038
if (!strcmp(argv[ap], "--old-scripts")) {
3042
if (!strcmp(argv[ap], "--no-old-scripts")) {
3043
no_old_scripts = True;
3046
if (!strcmp(argv[ap], "--old-confs")) {
3050
if (!strcmp(argv[ap], "--no-old-xdm")) {
3054
if (!strcmp(argv[ap], "--no-old-kde")) {
3058
if (!strcmp(argv[ap], "--no-backup")) {
3062
if (!strcmp(argv[ap], "--no-in-notice")) {
3063
no_in_notice = True;
3067
if (!strcmp(argv[ap], "--in")) {
3069
} else if (!strcmp(argv[ap], "--old-xdm")) {
3071
} else if (!strcmp(argv[ap], "--old-kde")) {
3073
} else if (!strcmp(argv[ap], "--face-src")) {
3076
fprintf(stderr, "Unknown command line option '%s', try --help\n", argv[ap]);
3079
if (ap + 1 == argc || argv[ap + 1][0] == '-') {
3080
fprintf(stderr, "Missing argument to option '%s', try --help\n", argv[ap]);
3083
*where = argv[++ap];
3085
if (memcmp(newdir, KDMCONF, sizeof(KDMCONF)))
3088
if (!mkdirp(newdir, 0755, "target", True))
3091
makeDefaultConfig();
3095
if ((dir = opendir(newdir))) {
3098
while ((ent = readdir(dir))) {
3100
if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
3102
l = sprintf(bn, "%s/%s", newdir, ent->d_name); /* cannot overflow (kernel would not allow the creation of a longer path) */
3103
if (!stat(bn, &st) && !S_ISREG(st.st_mode))
3105
if (no_backup || !memcmp(bn + l - 4, ".bak", 5))
3111
for (; bfl; bfl = bfl->next)
3116
if (!mergeKdmRcNewer(oldkde, True) && !mergeKdmRcOld(oldkde)) {
3118
"Cannot read pre-existing kdmrc at specified location\n");
3121
} else if (!no_old_kde) {
3122
for (i = 0; i < as(oldkdes); i++) {
3123
if (i && !strcmp(oldkdes[0], oldkdes[i]))
3125
if (mergeKdmRcNewer(oldkdes[i], 0)) {
3126
oldkde = oldkdes[i];
3129
mergeKdmRcOld(oldkdes[i]); /* only prints a message */
3123
3133
#define SHR_CONF "/share/config"
3124
int olen = strlen( oldkde );
3125
if (olen < (int)sizeof(SHR_CONF) ||
3126
memcmp( oldkde + olen - sizeof(SHR_CONF) + 1,
3127
SHR_CONF, sizeof(SHR_CONF) ))
3130
"Warning: --old-kde does not end with " SHR_CONF ". "
3131
"Might wreak havoc.\n" );
3134
ASPrintf( (char **)&oldkdepfx,
3135
"%.*s", olen - sizeof(SHR_CONF) + 1, oldkde );
3137
} else if (!no_old_xdm) {
3139
XrmQString = XrmPermStringToQuark( "String" );
3141
if (!mergeXdmCfg( oldxdm )) {
3143
"Cannot read xdm-config at specified location\n" );
3147
for (i = 0; i < as(oldxdms); i++)
3148
if (mergeXdmCfg( oldxdms[i] )) {
3149
oldxdm = oldxdms[i];
3155
* How to proceed with pre-existing scripts (which are named in the config):
3156
* - old_scripts set or some scripts in new target already => keep 'em
3157
* - no_old_scripts set or all scripts outside new target => pretend that
3158
* the old config did not reference them in the first place
3163
locals = foreigns = False;
3164
for (cs = config; cs; cs = cs->next)
3165
if (!strcmp( cs->spec->name, "-Core" )) {
3166
for (ce = cs->ents; ce; ce = ce->next)
3168
(!strcmp( ce->spec->key, "Setup" ) ||
3169
!strcmp( ce->spec->key, "Startup" ) ||
3170
!strcmp( ce->spec->key, "Reset" )))
3172
if (inNewDir( ce->value ))
3181
"Warning: both local and foreign scripts referenced. "
3182
"Will not touch any.\n" );
3183
mixed_scripts = True;
3186
for (cs = config; cs; cs = cs->next) {
3187
if (!strcmp( cs->spec->name, "Xdmcp" )) {
3188
for (ce = cs->ents; ce; ce = ce->next)
3189
if (!strcmp( ce->spec->key, "Willing" ))
3190
ce->active = ce->written = False;
3191
} else if (!strcmp( cs->spec->name, "-Core" )) {
3192
for (cep = &cs->ents; (ce = *cep); ) {
3194
(!strcmp( ce->spec->key, "Setup" ) ||
3195
!strcmp( ce->spec->key, "Startup" ) ||
3196
!strcmp( ce->spec->key, "Reset" ) ||
3197
!strcmp( ce->spec->key, "Session" )))
3199
if (!memcmp( cs->name, "X-*-", 4 ))
3200
ce->active = ce->written = False;
3134
int olen = strlen(oldkde);
3135
if (olen < (int)sizeof(SHR_CONF) ||
3136
memcmp(oldkde + olen - sizeof(SHR_CONF) + 1,
3137
SHR_CONF, sizeof(SHR_CONF)))
3141
"Warning: --old-kde does not end with " SHR_CONF ". "
3142
"Might wreak havoc.\n");
3146
ASPrintf((char **)&oldkdepfx,
3147
"%.*s", olen - sizeof(SHR_CONF) + 1, oldkde);
3149
} else if (!no_old_xdm) {
3151
XrmQString = XrmPermStringToQuark("String");
3153
if (!mergeXdmCfg(oldxdm)) {
3155
"Cannot read xdm-config at specified location\n");
3159
for (i = 0; i < as(oldxdms); i++)
3160
if (mergeXdmCfg(oldxdms[i])) {
3161
oldxdm = oldxdms[i];
3167
* How to proceed with pre-existing scripts (which are named in the config):
3168
* - old_scripts set or some scripts in new target already => keep 'em
3169
* - no_old_scripts set or all scripts outside new target => pretend that
3170
* the old config did not reference them in the first place
3175
locals = foreigns = False;
3176
for (cs = config; cs; cs = cs->next)
3177
if (!strcmp(cs->spec->name, "-Core")) {
3178
for (ce = cs->ents; ce; ce = ce->next)
3180
(!strcmp(ce->spec->key, "Setup") ||
3181
!strcmp(ce->spec->key, "Startup") ||
3182
!strcmp(ce->spec->key, "Reset")))
3184
if (inNewDir(ce->value))
3193
"Warning: both local and foreign scripts referenced. "
3194
"Will not touch any.\n");
3195
mixed_scripts = True;
3198
for (cs = config; cs; cs = cs->next) {
3199
if (!strcmp(cs->spec->name, "Xdmcp")) {
3200
for (ce = cs->ents; ce; ce = ce->next)
3201
if (!strcmp(ce->spec->key, "Willing"))
3202
ce->active = ce->written = False;
3203
} else if (!strcmp(cs->spec->name, "-Core")) {
3204
for (cep = &cs->ents; (ce = *cep);) {
3206
(!strcmp(ce->spec->key, "Setup") ||
3207
!strcmp(ce->spec->key, "Startup") ||
3208
!strcmp(ce->spec->key, "Reset") ||
3209
!strcmp(ce->spec->key, "Session")))
3211
if (!memcmp(cs->name, "X-*-", 4)) {
3212
ce->active = ce->written = False;
3214
3226
#ifdef __linux__
3215
if (!stat( "/etc/debian_version", &st )) { /* debian */
3217
defmaxuid = "29999";
3218
} else if (!stat( "/usr/portage", &st )) { /* gentoo */
3220
defmaxuid = "65000";
3221
} else if (!stat( "/etc/mandrake-release", &st )) { /* mandrake - check before redhat! */
3223
defmaxuid = "65000";
3224
} else if (!stat( "/etc/redhat-release", &st )) { /* redhat */
3226
defmaxuid = "65000";
3227
} else /* if (!stat( "/etc/SuSE-release", &st )) */ { /* suse */
3229
defmaxuid = "65000";
3227
if (!stat("/etc/debian_version", &st)) { /* debian */
3229
defmaxuid = "29999";
3230
} else if (!stat("/usr/portage", &st)) { /* gentoo */
3232
defmaxuid = "65000";
3233
} else if (!stat("/etc/mandrake-release", &st)) { /* mandrake - check before redhat! */
3235
defmaxuid = "65000";
3236
} else if (!stat("/etc/redhat-release", &st)) { /* redhat */
3238
defmaxuid = "65000";
3239
} else /* if (!stat("/etc/SuSE-release", &st)) */ { /* suse */
3241
defmaxuid = "65000";
3233
defmaxuid = "65000";
3245
defmaxuid = "65000";
3235
for (i = 0; i <= CONF_MAX_PRIO; i++)
3236
for (cs = config; cs; cs = cs->next)
3237
for (ce = cs->ents; ce; ce = ce->next)
3238
if (ce->spec->func && i == ce->spec->prio)
3239
ce->spec->func( ce, cs );
3240
f = createFile( "kdmrc", kdmrcmode );
3247
for (i = 0; i <= CONF_MAX_PRIO; i++)
3248
for (cs = config; cs; cs = cs->next)
3249
for (ce = cs->ents; ce; ce = ce->next)
3250
if (ce->spec->func && i == ce->spec->prio)
3251
ce->spec->func(ce, cs);
3252
f = createFile("kdmrc", kdmrcmode);
3244
f = createFile( "README", 0644 );
3246
"This automatically generated configuration consists of the following files:\n" );
3247
fprintf_( f, "- " KDMCONF "/kdmrc\n" );
3248
for (fp = aflist; fp; fp = fp->next)
3249
fprintf_( f, "- %s\n", fp->str );
3250
if (use_destdir && !no_in_notice)
3256
f = createFile("README", 0644);
3258
"This automatically generated configuration consists of the following files:\n");
3259
fprintf_(f, "- " KDMCONF "/kdmrc\n");
3260
for (fp = aflist; fp; fp = fp->next)
3261
fprintf_(f, "- %s\n", fp->str);
3262
if (use_destdir && !no_in_notice)
3252
3264
"All files destined for " KDMCONF " were actually saved in %s; "
3253
"this config will not be workable until moved in place.\n", newdir );
3254
if (uflist || eflist || cflist || lflist) {
3265
"this config will not be workable until moved in place.\n", newdir);
3266
if (uflist || eflist || cflist || lflist) {
3257
3269
"This config was derived from existing files. As the used algorithms are\n"
3258
"pretty dumb, it may be broken.\n" );
3261
"Information from these files was extracted:\n" );
3262
for (fp = uflist; fp; fp = fp->next)
3263
fprintf_( f, "- %s\n", fp->str );
3267
"These files were directly incorporated:\n" );
3268
for (fp = lflist; fp; fp = fp->next)
3269
fprintf_( f, "- %s\n", fp->str );
3273
"These files were copied verbatim:\n" );
3274
for (fp = cflist; fp; fp = fp->next)
3275
fprintf_( f, "- %s\n", fp->str );
3279
"These files were copied with modifications:\n" );
3280
for (fp = eflist; fp; fp = fp->next)
3281
fprintf_( f, "- %s\n", fp->str );
3283
if (!no_backup && !use_destdir)
3285
"Old files that would have been overwritten were renamed to <oldname>.bak.\n" );
3270
"pretty dumb, it may be broken.\n");
3273
"Information from these files was extracted:\n");
3274
for (fp = uflist; fp; fp = fp->next)
3275
fprintf_(f, "- %s\n", fp->str);
3279
"These files were directly incorporated:\n");
3280
for (fp = lflist; fp; fp = fp->next)
3281
fprintf_(f, "- %s\n", fp->str);
3285
"These files were copied verbatim:\n");
3286
for (fp = cflist; fp; fp = fp->next)
3287
fprintf_(f, "- %s\n", fp->str);
3291
"These files were copied with modifications:\n");
3292
for (fp = eflist; fp; fp = fp->next)
3293
fprintf_(f, "- %s\n", fp->str);
3295
if (!no_backup && !use_destdir)
3297
"Old files that would have been overwritten were renamed to <oldname>.bak.\n");
3288
3300
"\nTry 'genkdmconf --help' if you want to generate another configuration.\n"
3289
"\nYou may delete this README.\n" );
3301
"\nYou may delete this README.\n");