~zulcss/ubuntu/lucid/likewise-open/likewise-open-sru

« back to all changes in this revision

Viewing changes to domainjoin/libdomainjoin/src/djkrb5conf.c

  • Committer: Bazaar Package Importer
  • Author(s): Rick Clark
  • Date: 2008-08-27 08:56:20 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080827085620-5q0f58b9qtog9myq
Tags: 4.1.0.2956-0ubuntu1
* missing-likewise-logo.diff: removed
* fixed copyright notice
* updated Standards-Version to 3.8.0
* removed path from command in prerm
* removed stop in S runlevel

Show diffs side-by-side

added added

removed removed

Lines of Context:
666
666
    CENTERROR ceError = CENTERROR_SUCCESS;
667
667
    Krb5Entry *created = NULL;
668
668
    ssize_t existingIndex = FindNodeIndex(parent, 0, name);
669
 
    DJ_LOG_VERBOSE("Settting krb5 name value '%s' to '%s' ", name, value);
 
669
    DJ_LOG_VERBOSE("Setting krb5 name value '%s' to '%s' ", name, value);
670
670
    GCE(ceError = CreateValueNode(parent, GetEntryDepth(parent) + 1, name,
671
671
                value, &created));
672
672
    GCE(ceError = DeleteChildNode(parent, name, NULL));
1183
1183
        GCE(ceError = ReadKrb5File(rootPrefix, "/etc/krb5.conf", conf));
1184
1184
    }
1185
1185
 
1186
 
    if(*modified)
 
1186
    if(modified)
1187
1187
        *modified = _modified;
1188
1188
 
1189
1189
cleanup:
1286
1286
    BOOLEAN same;
1287
1287
    BOOLEAN islink;
1288
1288
 
 
1289
    if(rootPrefix == NULL)
 
1290
        rootPrefix = "";
 
1291
 
1289
1292
    GCE(ceError = CTAllocateStringPrintf(&tempName, "%s%s.new", rootPrefix, filename));
1290
1293
    GCE(ceError = CTAllocateStringPrintf(&finalName, "%s%s", rootPrefix, filename));
1291
1294
 
1337
1340
    return ceError;
1338
1341
}
1339
1342
 
1340
 
CENTERROR
 
1343
void
1341
1344
DJCopyKrb5ToRootDir(
1342
1345
        const char *srcPrefix,
1343
 
        const char *destPrefix
 
1346
        const char *destPrefix,
 
1347
        LWException **exc
1344
1348
        )
1345
1349
{
1346
 
    CENTERROR ceError = CENTERROR_SUCCESS;
1347
1350
    PSTR srcPath = NULL;
1348
1351
    PSTR destPath = NULL;
1349
1352
    BOOLEAN exists;
1354
1357
        destPrefix = "";
1355
1358
 
1356
1359
    CT_SAFE_FREE_STRING(srcPath);
1357
 
    GCE(ceError = CTAllocateStringPrintf(&srcPath, "%s/etc", srcPrefix));
1358
 
    GCE(ceError = CTCheckDirectoryExists(srcPath, &exists));
1359
 
    if(exists)
1360
 
    {
1361
 
        CT_SAFE_FREE_STRING(destPath);
1362
 
        GCE(ceError = CTAllocateStringPrintf(&destPath, "%s/etc", destPrefix));
1363
 
        GCE(ceError = CTCreateDirectory(destPath, 0700));
1364
 
    }
1365
 
 
1366
 
    CT_SAFE_FREE_STRING(srcPath);
1367
 
    GCE(ceError = CTAllocateStringPrintf(&srcPath, "%s/etc/krb5", srcPrefix));
1368
 
    GCE(ceError = CTCheckDirectoryExists(srcPath, &exists));
1369
 
    if(exists)
1370
 
    {
1371
 
        CT_SAFE_FREE_STRING(destPath);
1372
 
        GCE(ceError = CTAllocateStringPrintf(&destPath, "%s/etc/krb5", destPrefix));
1373
 
        GCE(ceError = CTCreateDirectory(destPath, 0700));
1374
 
    }
1375
 
 
1376
 
    CT_SAFE_FREE_STRING(srcPath);
1377
 
    GCE(ceError = CTAllocateStringPrintf(&srcPath, "%s/etc/krb5/krb5.conf", srcPrefix));
1378
 
    GCE(ceError = CTCheckFileOrLinkExists(srcPath, &exists));
1379
 
    if(exists)
1380
 
    {
1381
 
        CT_SAFE_FREE_STRING(destPath);
1382
 
        GCE(ceError = CTAllocateStringPrintf(&destPath, "%s/etc/krb5/krb5.conf", destPrefix));
1383
 
        GCE(ceError = CTCopyFileWithOriginalPerms(srcPath, destPath));
1384
 
    }
1385
 
 
1386
 
    CT_SAFE_FREE_STRING(srcPath);
1387
 
    GCE(ceError = CTAllocateStringPrintf(&srcPath, "%s/etc/krb5.conf", srcPrefix));
1388
 
    GCE(ceError = CTCheckFileOrLinkExists(srcPath, &exists));
1389
 
    if(exists)
1390
 
    {
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));
 
1362
    if(exists)
 
1363
    {
 
1364
        CT_SAFE_FREE_STRING(destPath);
 
1365
        LW_CLEANUP_CTERR(exc, CTAllocateStringPrintf(&destPath, "%s/etc", destPrefix));
 
1366
        LW_CLEANUP_CTERR(exc, CTCreateDirectory(destPath, 0700));
 
1367
    }
 
1368
 
 
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));
 
1372
    if(exists)
 
1373
    {
 
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));
 
1377
    }
 
1378
 
 
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));
 
1382
    if(exists)
 
1383
    {
 
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));
 
1387
    }
 
1388
 
 
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));
 
1392
    if(exists)
 
1393
    {
 
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));
1397
1400
    }
1398
1401
 
1399
1402
cleanup:
1400
1403
    CT_SAFE_FREE_STRING(srcPath);
1401
1404
    CT_SAFE_FREE_STRING(destPath);
1402
 
    return ceError;
1403
1405
}
1404
1406
 
1405
1407
static QueryResult QueryKrb5(const JoinProcessOptions *options, LWException **exc)
1412
1414
    Krb5Entry conf;
1413
1415
    Krb5Entry *libdefaults;
1414
1416
    Krb5Entry *default_realm;
 
1417
    CENTERROR ceError;
1415
1418
 
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)
 
1424
    {
 
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.");
 
1426
        goto cleanup;
 
1427
    }
 
1428
    else
 
1429
        LW_CLEANUP_CTERR(exc, ceError);
1420
1430
    if(modified)
1421
1431
    {
1422
1432
        if(options->joiningDomain)
1506
1516
    BOOLEAN modified;
1507
1517
 
1508
1518
    LW_CLEANUP_CTERR(exc, CTCreateTempDirectory(&tempDir));
1509
 
    LW_CLEANUP_CTERR(exc, DJCopyKrb5ToRootDir(NULL, tempDir));
 
1519
    LW_TRY(exc, DJCopyKrb5ToRootDir(NULL, tempDir, &LW_EXC));
1510
1520
 
1511
1521
    if(options->shortDomainName != NULL)
1512
1522
        LW_CLEANUP_CTERR(exc, CTStrdup(options->shortDomainName, &shortName));
1565
1575
}
1566
1576
 
1567
1577
const JoinModule DJKrb5Module = { TRUE, "krb5", "configure krb5.conf", QueryKrb5, DoKrb5, GetKrb5Description };
 
1578
 
 
1579
static QueryResult QueryOrDoKeytab(const JoinProcessOptions *options, PSTR *description, BOOLEAN makeChanges, LWException **exc)
 
1580
{
 
1581
    QueryResult result = FullyConfigured;
 
1582
    Krb5Entry *libdefaults;
 
1583
    Krb5Entry *default_keytab_name;
 
1584
    BOOLEAN exists;
 
1585
    CENTERROR ceError;
 
1586
    PSTR tempDir = NULL;
 
1587
    PSTR currentTarget = NULL;
 
1588
    Krb5Entry conf;
 
1589
    PSTR trueLocation;
 
1590
 
 
1591
    if(description)
 
1592
        *description = NULL;
 
1593
 
 
1594
    memset(&conf, 0, sizeof(conf));
 
1595
 
 
1596
    if(!options->joiningDomain)
 
1597
        goto nochanges;
 
1598
 
 
1599
    if(!makeChanges)
 
1600
    {
 
1601
        LW_CLEANUP_CTERR(exc, CTCreateTempDirectory(&tempDir));
 
1602
        LW_TRY(exc, DJCopyKrb5ToRootDir(NULL, tempDir, &LW_EXC));
 
1603
    }
 
1604
 
 
1605
    ceError = ReadKrb5Configuration(tempDir, &conf, NULL);
 
1606
    if(ceError == CENTERROR_DOMAINJOIN_INVALID_FORMAT)
 
1607
    {
 
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.");
 
1609
        goto cleanup;
 
1610
    }
 
1611
    else
 
1612
        LW_CLEANUP_CTERR(exc, ceError);
 
1613
 
 
1614
    libdefaults = GetFirstNode(&conf, "libdefaults");
 
1615
    if(libdefaults == NULL)
 
1616
    {
 
1617
        goto nochanges;
 
1618
    }
 
1619
 
 
1620
    default_keytab_name = GetFirstNode(libdefaults, "default_keytab_name");
 
1621
    if(default_keytab_name == NULL)
 
1622
        goto nochanges;
 
1623
 
 
1624
    if(default_keytab_name->value.value == NULL)
 
1625
    {
 
1626
        LW_CLEANUP_CTERR(exc, CENTERROR_DOMAINJOIN_INVALID_FORMAT);
 
1627
    }
 
1628
 
 
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:");
 
1634
 
 
1635
    if(!strcmp(trueLocation, "/etc/krb5.keytab"))
 
1636
    {
 
1637
        //It's already pointing where we want
 
1638
        goto nochanges;
 
1639
    }
 
1640
 
 
1641
    LW_CLEANUP_CTERR(exc, CTCheckFileOrLinkExists(trueLocation, &exists));
 
1642
    if(!exists)
 
1643
    {
 
1644
        if(description)
 
1645
        {
 
1646
            LW_CLEANUP_CTERR(exc, CTAllocateStringPrintf(
 
1647
                    description,
 
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",
 
1650
                    trueLocation));
 
1651
        }
 
1652
        if(makeChanges)
 
1653
        {
 
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));
 
1658
        }
 
1659
        else
 
1660
        {
 
1661
            result = NotConfigured;
 
1662
        }
 
1663
        goto cleanup;
 
1664
    }
 
1665
 
 
1666
    ceError = CTGetSymLinkTarget("/etc/krb5.keytab", &currentTarget);
 
1667
    if(CENTERROR_IS_OK(ceError) && !strcmp(currentTarget, trueLocation))
 
1668
    {
 
1669
        //Already points to the right place
 
1670
        goto nochanges;
 
1671
    }
 
1672
    else if(ceError == CTMapSystemError(EINVAL) || ceError == CENTERROR_SUCCESS)
 
1673
    {
 
1674
        // The file already exists and isn't a symlink (EINVAL) or it exists
 
1675
        // and is a symlink (0).
 
1676
        if(description)
 
1677
        {
 
1678
            LW_CLEANUP_CTERR(exc, CTAllocateStringPrintf(
 
1679
                    description,
 
1680
                    "Delete either %s or %s.\n"
 
1681
                    "\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,
 
1684
                    trueLocation,
 
1685
                    "/etc/krb5.keytab",
 
1686
                    "/etc/krb5.keytab", trueLocation));
 
1687
        }
 
1688
        if(makeChanges)
 
1689
        {
 
1690
            LW_CLEANUP_CTERR(exc, CENTERROR_INVALID_OPERATION);
 
1691
        }
 
1692
        else
 
1693
        {
 
1694
            result = CannotConfigure;
 
1695
        }
 
1696
        ceError = CENTERROR_SUCCESS;
 
1697
    }
 
1698
    else if(ceError == CTMapSystemError(ENOENT))
 
1699
    {
 
1700
        //We can make the symlink
 
1701
        if(description)
 
1702
        {
 
1703
            LW_CLEANUP_CTERR(exc, CTAllocateStringPrintf(
 
1704
                    description,
 
1705
                    "Create a symlink at %s that points to %s\n",
 
1706
                    "/etc/krb5.keytab", trueLocation));
 
1707
        }
 
1708
        if(makeChanges)
 
1709
        {
 
1710
            LW_CLEANUP_CTERR(exc, CTCreateSymLink(trueLocation,
 
1711
                        "/etc/krb5.keytab"));
 
1712
        }
 
1713
        else
 
1714
        {
 
1715
            result = NotConfigured;
 
1716
        }
 
1717
        ceError = CENTERROR_SUCCESS;
 
1718
    }
 
1719
    LW_CLEANUP_CTERR(exc, ceError);
 
1720
 
 
1721
cleanup:
 
1722
    if(tempDir != NULL)
 
1723
    {
 
1724
        CTRemoveDirectory(tempDir);
 
1725
        CT_SAFE_FREE_STRING(tempDir);
 
1726
    }
 
1727
    FreeKrb5EntryContents(&conf);
 
1728
    return result;
 
1729
 
 
1730
nochanges:
 
1731
    if(description)
 
1732
    {
 
1733
        LW_CLEANUP_CTERR(exc, CTStrdup("Fully configured", description));
 
1734
    }
 
1735
    goto cleanup;
 
1736
}
 
1737
 
 
1738
static QueryResult QueryKeytab(const JoinProcessOptions *options, LWException **exc)
 
1739
{
 
1740
    return QueryOrDoKeytab(options, NULL, FALSE, exc);
 
1741
}
 
1742
 
 
1743
static void DoKeytab(JoinProcessOptions *options, LWException **exc)
 
1744
{
 
1745
    QueryOrDoKeytab(options, NULL, TRUE, exc);
 
1746
}
 
1747
 
 
1748
static PSTR GetKeytabDescription(const JoinProcessOptions *options, LWException **exc)
 
1749
{
 
1750
    PSTR description = NULL;
 
1751
    QueryOrDoKeytab(options, &description, FALSE, exc);
 
1752
    return description;
 
1753
}
 
1754
 
 
1755
const JoinModule DJKeytabModule = { TRUE, "keytab", "initialize kerberos keytab", QueryKeytab, DoKeytab, GetKeytabDescription };