1354
1357
destPrefix = "";
1356
1359
CT_SAFE_FREE_STRING(srcPath);
1357
GCE(ceError = CTAllocateStringPrintf(&srcPath, "%s/etc", srcPrefix));
1358
GCE(ceError = CTCheckDirectoryExists(srcPath, &exists));
1361
CT_SAFE_FREE_STRING(destPath);
1362
GCE(ceError = CTAllocateStringPrintf(&destPath, "%s/etc", destPrefix));
1363
GCE(ceError = CTCreateDirectory(destPath, 0700));
1366
CT_SAFE_FREE_STRING(srcPath);
1367
GCE(ceError = CTAllocateStringPrintf(&srcPath, "%s/etc/krb5", srcPrefix));
1368
GCE(ceError = CTCheckDirectoryExists(srcPath, &exists));
1371
CT_SAFE_FREE_STRING(destPath);
1372
GCE(ceError = CTAllocateStringPrintf(&destPath, "%s/etc/krb5", destPrefix));
1373
GCE(ceError = CTCreateDirectory(destPath, 0700));
1376
CT_SAFE_FREE_STRING(srcPath);
1377
GCE(ceError = CTAllocateStringPrintf(&srcPath, "%s/etc/krb5/krb5.conf", srcPrefix));
1378
GCE(ceError = CTCheckFileOrLinkExists(srcPath, &exists));
1381
CT_SAFE_FREE_STRING(destPath);
1382
GCE(ceError = CTAllocateStringPrintf(&destPath, "%s/etc/krb5/krb5.conf", destPrefix));
1383
GCE(ceError = CTCopyFileWithOriginalPerms(srcPath, destPath));
1386
CT_SAFE_FREE_STRING(srcPath);
1387
GCE(ceError = CTAllocateStringPrintf(&srcPath, "%s/etc/krb5.conf", srcPrefix));
1388
GCE(ceError = CTCheckFileOrLinkExists(srcPath, &exists));
1391
CT_SAFE_FREE_STRING(destPath);
1392
GCE(ceError = CTAllocateStringPrintf(&destPath, "%s/etc", destPrefix));
1393
GCE(ceError = CTCreateDirectory(destPath, 0700));
1394
CT_SAFE_FREE_STRING(destPath);
1395
GCE(ceError = CTAllocateStringPrintf(&destPath, "%s/etc/krb5.conf", destPrefix));
1396
GCE(ceError = CTCopyFileWithOriginalPerms(srcPath, destPath));
1360
LW_CLEANUP_CTERR(exc, CTAllocateStringPrintf(&srcPath, "%s/etc", srcPrefix));
1361
LW_CLEANUP_CTERR(exc, CTCheckDirectoryExists(srcPath, &exists));
1364
CT_SAFE_FREE_STRING(destPath);
1365
LW_CLEANUP_CTERR(exc, CTAllocateStringPrintf(&destPath, "%s/etc", destPrefix));
1366
LW_CLEANUP_CTERR(exc, CTCreateDirectory(destPath, 0700));
1369
CT_SAFE_FREE_STRING(srcPath);
1370
LW_CLEANUP_CTERR(exc, CTAllocateStringPrintf(&srcPath, "%s/etc/krb5", srcPrefix));
1371
LW_CLEANUP_CTERR(exc, CTCheckDirectoryExists(srcPath, &exists));
1374
CT_SAFE_FREE_STRING(destPath);
1375
LW_CLEANUP_CTERR(exc, CTAllocateStringPrintf(&destPath, "%s/etc/krb5", destPrefix));
1376
LW_CLEANUP_CTERR(exc, CTCreateDirectory(destPath, 0700));
1379
CT_SAFE_FREE_STRING(srcPath);
1380
LW_CLEANUP_CTERR(exc, CTAllocateStringPrintf(&srcPath, "%s/etc/krb5/krb5.conf", srcPrefix));
1381
LW_CLEANUP_CTERR(exc, CTCheckFileOrLinkExists(srcPath, &exists));
1384
CT_SAFE_FREE_STRING(destPath);
1385
LW_CLEANUP_CTERR(exc, CTAllocateStringPrintf(&destPath, "%s/etc/krb5/krb5.conf", destPrefix));
1386
LW_CLEANUP_CTERR(exc, CTCopyFileWithOriginalPerms(srcPath, destPath));
1389
CT_SAFE_FREE_STRING(srcPath);
1390
LW_CLEANUP_CTERR(exc, CTAllocateStringPrintf(&srcPath, "%s/etc/krb5.conf", srcPrefix));
1391
LW_CLEANUP_CTERR(exc, CTCheckFileOrLinkExists(srcPath, &exists));
1394
CT_SAFE_FREE_STRING(destPath);
1395
LW_CLEANUP_CTERR(exc, CTAllocateStringPrintf(&destPath, "%s/etc", destPrefix));
1396
LW_CLEANUP_CTERR(exc, CTCreateDirectory(destPath, 0700));
1397
CT_SAFE_FREE_STRING(destPath);
1398
LW_CLEANUP_CTERR(exc, CTAllocateStringPrintf(&destPath, "%s/etc/krb5.conf", destPrefix));
1399
LW_CLEANUP_CTERR(exc, CTCopyFileWithOriginalPerms(srcPath, destPath));
1400
1403
CT_SAFE_FREE_STRING(srcPath);
1401
1404
CT_SAFE_FREE_STRING(destPath);
1405
1407
static QueryResult QueryKrb5(const JoinProcessOptions *options, LWException **exc)
1412
1414
Krb5Entry conf;
1413
1415
Krb5Entry *libdefaults;
1414
1416
Krb5Entry *default_realm;
1416
1419
memset(&conf, 0, sizeof(conf));
1417
1420
LW_CLEANUP_CTERR(exc, CTCreateTempDirectory(&tempDir));
1418
LW_CLEANUP_CTERR(exc, DJCopyKrb5ToRootDir(NULL, tempDir));
1419
LW_CLEANUP_CTERR(exc, ReadKrb5Configuration(tempDir, &conf, &modified));
1421
LW_TRY(exc, DJCopyKrb5ToRootDir(NULL, tempDir, &LW_EXC));
1422
ceError = ReadKrb5Configuration(tempDir, &conf, &modified);
1423
if(ceError == CENTERROR_DOMAINJOIN_INVALID_FORMAT)
1425
LW_RAISE_EX(exc, ceError, "Unable to parse krb5.conf", "The krb5.conf file on your system (located in either /etc/krb5.conf or /etc/krb5/krb5.conf) could not be parsed. Please send the file to Likewise technical support.");
1429
LW_CLEANUP_CTERR(exc, ceError);
1422
1432
if(options->joiningDomain)
1567
1577
const JoinModule DJKrb5Module = { TRUE, "krb5", "configure krb5.conf", QueryKrb5, DoKrb5, GetKrb5Description };
1579
static QueryResult QueryOrDoKeytab(const JoinProcessOptions *options, PSTR *description, BOOLEAN makeChanges, LWException **exc)
1581
QueryResult result = FullyConfigured;
1582
Krb5Entry *libdefaults;
1583
Krb5Entry *default_keytab_name;
1586
PSTR tempDir = NULL;
1587
PSTR currentTarget = NULL;
1592
*description = NULL;
1594
memset(&conf, 0, sizeof(conf));
1596
if(!options->joiningDomain)
1601
LW_CLEANUP_CTERR(exc, CTCreateTempDirectory(&tempDir));
1602
LW_TRY(exc, DJCopyKrb5ToRootDir(NULL, tempDir, &LW_EXC));
1605
ceError = ReadKrb5Configuration(tempDir, &conf, NULL);
1606
if(ceError == CENTERROR_DOMAINJOIN_INVALID_FORMAT)
1608
LW_RAISE_EX(exc, ceError, "Unable to parse krb5.conf", "The krb5.conf file on your system (located in either /etc/krb5.conf or /etc/krb5/krb5.conf) could not be parsed. Please send the file to Likewise technical support.");
1612
LW_CLEANUP_CTERR(exc, ceError);
1614
libdefaults = GetFirstNode(&conf, "libdefaults");
1615
if(libdefaults == NULL)
1620
default_keytab_name = GetFirstNode(libdefaults, "default_keytab_name");
1621
if(default_keytab_name == NULL)
1624
if(default_keytab_name->value.value == NULL)
1626
LW_CLEANUP_CTERR(exc, CENTERROR_DOMAINJOIN_INVALID_FORMAT);
1629
trueLocation = default_keytab_name->value.value;
1630
if(CTStrStartsWith(trueLocation, "FILE:"))
1631
trueLocation += strlen("FILE:");
1632
else if(CTStrStartsWith(trueLocation, "WRFILE:"))
1633
trueLocation += strlen("WRFILE:");
1635
if(!strcmp(trueLocation, "/etc/krb5.keytab"))
1637
//It's already pointing where we want
1641
LW_CLEANUP_CTERR(exc, CTCheckFileOrLinkExists(trueLocation, &exists));
1646
LW_CLEANUP_CTERR(exc, CTAllocateStringPrintf(
1648
"Change the default_keytab_name setting in krb5.conf from '%s' to '%s' because the file '%s' does not exist.",
1649
default_keytab_name->value.value, "/etc/krb5.keytab",
1654
LW_CLEANUP_CTERR(exc, SetNodeValue(libdefaults,
1655
"default_keytab_name", "/etc/krb5.keytab"));
1656
LW_CLEANUP_CTERR(exc, WriteKrb5Configuration(tempDir,
1657
"/etc/krb5.conf", &conf, NULL));
1661
result = NotConfigured;
1666
ceError = CTGetSymLinkTarget("/etc/krb5.keytab", ¤tTarget);
1667
if(CENTERROR_IS_OK(ceError) && !strcmp(currentTarget, trueLocation))
1669
//Already points to the right place
1672
else if(ceError == CTMapSystemError(EINVAL) || ceError == CENTERROR_SUCCESS)
1674
// The file already exists and isn't a symlink (EINVAL) or it exists
1675
// and is a symlink (0).
1678
LW_CLEANUP_CTERR(exc, CTAllocateStringPrintf(
1680
"Delete either %s or %s.\n"
1682
"Both of these are locations for kerberos keytabs. Your krb5.conf file points to %s, but a legacy application is most likely using %s. After one of the files is deleted and this program is re-run, a symlink will be created from %s to %s so that the keytabs stay synchronized.\n",
1683
"/etc/krb5.keytab", trueLocation,
1686
"/etc/krb5.keytab", trueLocation));
1690
LW_CLEANUP_CTERR(exc, CENTERROR_INVALID_OPERATION);
1694
result = CannotConfigure;
1696
ceError = CENTERROR_SUCCESS;
1698
else if(ceError == CTMapSystemError(ENOENT))
1700
//We can make the symlink
1703
LW_CLEANUP_CTERR(exc, CTAllocateStringPrintf(
1705
"Create a symlink at %s that points to %s\n",
1706
"/etc/krb5.keytab", trueLocation));
1710
LW_CLEANUP_CTERR(exc, CTCreateSymLink(trueLocation,
1711
"/etc/krb5.keytab"));
1715
result = NotConfigured;
1717
ceError = CENTERROR_SUCCESS;
1719
LW_CLEANUP_CTERR(exc, ceError);
1724
CTRemoveDirectory(tempDir);
1725
CT_SAFE_FREE_STRING(tempDir);
1727
FreeKrb5EntryContents(&conf);
1733
LW_CLEANUP_CTERR(exc, CTStrdup("Fully configured", description));
1738
static QueryResult QueryKeytab(const JoinProcessOptions *options, LWException **exc)
1740
return QueryOrDoKeytab(options, NULL, FALSE, exc);
1743
static void DoKeytab(JoinProcessOptions *options, LWException **exc)
1745
QueryOrDoKeytab(options, NULL, TRUE, exc);
1748
static PSTR GetKeytabDescription(const JoinProcessOptions *options, LWException **exc)
1750
PSTR description = NULL;
1751
QueryOrDoKeytab(options, &description, FALSE, exc);
1755
const JoinModule DJKeytabModule = { TRUE, "keytab", "initialize kerberos keytab", QueryKeytab, DoKeytab, GetKeytabDescription };