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

« back to all changes in this revision

Viewing changes to domainjoin/libdomainjoin/src/djauthinfo.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:
32
32
#include "ctstrutils.h"
33
33
#include <glob.h>
34
34
 
 
35
#define NO_TIME_SYNC_FILE "/etc/likewise-notimesync"
 
36
 
35
37
#if !defined(__LWI_MACOSX__)
36
38
extern char** environ;
37
39
#endif
181
183
    PSTR pszUserName,
182
184
    PSTR pszPassword,
183
185
    PSTR pszOU,
 
186
    BOOLEAN bDoNotSyncTime,
184
187
    PSTR* ppszWorkgroupName)
185
188
{
186
189
    CENTERROR ceError = CENTERROR_SUCCESS;
256
259
    if (gdjLogInfo.dwLogLevel >= LOG_LEVEL_VERBOSE)
257
260
        nArgs++;
258
261
 
 
262
    if (bDoNotSyncTime)
 
263
    {
 
264
        nArgs++;
 
265
    }
 
266
 
259
267
    ceError = CTAllocateMemory(sizeof(PSTR)*nArgs, (PVOID*)&ppszArgs);
260
268
    BAIL_ON_CENTERIS_ERROR(ceError);
261
269
 
300
308
       BAIL_ON_CENTERIS_ERROR(ceError);
301
309
    }
302
310
 
 
311
    if (bDoNotSyncTime)
 
312
    {
 
313
        ceError = CTAllocateString("notimesync", nextArg++);
 
314
        BAIL_ON_CENTERIS_ERROR(ceError);
 
315
    }
303
316
 
304
317
    ceError = BuildJoinEnvironment(krb5ConfPath, pszPassword, &ppszEnv, &nVars);
305
318
    BAIL_ON_CENTERIS_ERROR(ceError);
519
532
 
520
533
CENTERROR
521
534
PrepareForJoinOrLeaveDomain(
522
 
    PSTR    pszWorkgroupName,
523
 
    BOOLEAN bIsDomain
 
535
    PCSTR    pszWorkgroupName,
 
536
    BOOLEAN  bIsDomain
524
537
    )
525
538
{
526
539
    CENTERROR ceError = CENTERROR_SUCCESS;
598
611
CENTERROR
599
612
CanonicalizeOrganizationalUnit(
600
613
    PSTR* pszCanonicalizedOrganizationalUnit,
601
 
    PSTR pszOrganizationalUnit,
602
 
    PSTR pszDomainName
 
614
    PCSTR pszOrganizationalUnit,
 
615
    PCSTR pszDomainName
603
616
    )
604
617
{
605
618
    CENTERROR ceError = CENTERROR_SUCCESS;
778
791
    PSTR lwiauthdPath = NULL;
779
792
    PSTR krb5Path = NULL;
780
793
    ModuleState *state = DJGetModuleStateByName(options, "join");
 
794
    BOOLEAN bNoTimeSyncFileExists = FALSE;
781
795
 
782
796
    if (options->ouName)
783
797
    {
792
806
    CT_SAFE_FREE_STRING(lwiauthdPath);
793
807
    LW_CLEANUP_CTERR(exc, CTAllocateStringPrintf(&lwiauthdPath, "%s/etc/samba/lwiauthd.conf", tempDir));
794
808
    LW_CLEANUP_CTERR(exc, CTCopyFileWithOriginalPerms("/etc/samba/lwiauthd.conf", lwiauthdPath));
795
 
    LW_CLEANUP_CTERR(exc, DJCopyKrb5ToRootDir(NULL, tempDir));
 
809
    LW_TRY(exc, DJCopyKrb5ToRootDir(NULL, tempDir, &LW_EXC));
796
810
 
797
811
    LW_CLEANUP_CTERR(exc, DJInitSmbConfig(tempDir));
798
812
    LW_CLEANUP_CTERR(exc, SetWorkgroup(tempDir, "WORKGROUP"));
816
830
    LW_CLEANUP_CTERR(exc, DJSetSambaValue(tempDir, "security", "ads"));
817
831
    LW_CLEANUP_CTERR(exc, DJSetSambaValue(tempDir, "use kerberos keytab", "yes"));
818
832
 
 
833
    LW_CLEANUP_CTERR(exc, CTCheckFileExists(NO_TIME_SYNC_FILE, &bNoTimeSyncFileExists));
 
834
 
 
835
    if (options->disableTimeSync && !bNoTimeSyncFileExists)
 
836
    {
 
837
        /* Create no time sync file */
 
838
        FILE* noTimeSyncFile = NULL;
 
839
 
 
840
        LW_CLEANUP_CTERR(exc, CTOpenFile(NO_TIME_SYNC_FILE, "w", &noTimeSyncFile));
 
841
 
 
842
        CTCloseFile(noTimeSyncFile);
 
843
    }
 
844
    else if (!options->disableTimeSync && bNoTimeSyncFileExists)
 
845
    {
 
846
        /* Remove no time sync file */
 
847
        LW_CLEANUP_CTERR(exc, CTRemoveFile(NO_TIME_SYNC_FILE));
 
848
    }
 
849
 
819
850
    DJ_LOG_INFO("Executing domain join.");
820
851
    CT_SAFE_FREE_STRING(options->shortDomainName);
821
852
    LW_CLEANUP_CTERR(exc, DJExecDomainJoin(tempDir, options->domainName,
822
853
                               options->username,
823
854
                               options->password,
824
855
                               pszCanonicalizedOU,
 
856
                               options->disableTimeSync,
825
857
                               &options->shortDomainName));
826
858
 
827
859
    //Indicate that the join was successful incase QueryDoJoin is called later
953
985
        state->moduleData = (void *)2;
954
986
        if(IsNullOrEmptyString(options->password))
955
987
        {
956
 
            LW_RAISE_EX(exc, CENTERROR_INVALID_PASSWORD, "Unable to delete computer account", "The computer account does not have sufficient permissions to remove itself. Please either provide an administrator's username and password, or the username and password of the account originally used to join the computer to AD.");
 
988
            LW_RAISE_EX(exc, CENTERROR_INVALID_PASSWORD, "Unable to disable computer account", "The computer account does not have sufficient permissions to disable itself. Please either provide an administrator's username and password, or the username and password of the account originally used to join the computer to AD.");
957
989
            goto cleanup;
958
990
        }
959
991
        else
960
992
        {
961
 
            LW_RAISE_EX(exc, CENTERROR_COMMAND_FAILED, "Unable to delete computer account", "Removing the computer account failed. Review the above output for more information.");
 
993
            LW_RAISE_EX(exc, CENTERROR_COMMAND_FAILED, "Unable to disable computer account", "Disabling the computer account failed. Review the above output for more information.");
962
994
            goto cleanup;
963
995
        }
964
996
    }
991
1023
    PSTR readValue = NULL;
992
1024
    PSTR upperDomain = NULL;
993
1025
    CENTERROR ceError;
 
1026
    BOOLEAN bGpagentdExists = FALSE;    
994
1027
 
995
1028
    if(!options->joiningDomain)
996
1029
    {
1041
1074
        goto cleanup;
1042
1075
    CT_SAFE_FREE_STRING(readValue);
1043
1076
 
 
1077
    /*
 
1078
     * Need to determine between an Enterprise and Open install.
 
1079
     */
 
1080
 
 
1081
    LW_CLEANUP_CTERR(exc, CTCheckFileExists(PREFIXDIR "/sbin/centeris-gpagentd", 
 
1082
                                            &bGpagentdExists));
 
1083
 
 
1084
    LW_CLEANUP_CTERR(exc, DJGetSambaValue("idmap config default:backend",  &readValue));
 
1085
    if (bGpagentdExists) {
 
1086
        if (strcmp(readValue, "lwidentity") != 0)
 
1087
            goto cleanup;
 
1088
    } else {
 
1089
        if (strcmp(readValue, "lwopen") != 0)
 
1090
            goto cleanup;
 
1091
    }
 
1092
    CT_SAFE_FREE_STRING(readValue);
 
1093
    
 
1094
    LW_CLEANUP_CTERR(exc, DJGetSambaValue("winbind nss info", &readValue));
 
1095
    if (bGpagentdExists) {
 
1096
        if (strcmp(readValue, "lwidentity") != 0)
 
1097
            goto cleanup;
 
1098
    } else {
 
1099
        if (strcmp(readValue, "lwopen") != 0)
 
1100
            goto cleanup;
 
1101
    }
 
1102
    CT_SAFE_FREE_STRING(readValue);
 
1103
 
1044
1104
    result = FullyConfigured;
1045
1105
 
1046
1106
cleanup:
1051
1111
 
1052
1112
static void DoLwiConf(JoinProcessOptions *options, LWException **exc)
1053
1113
{
 
1114
    BOOLEAN bGpagentdExists = FALSE;
 
1115
    DistroInfo distro;
 
1116
 
 
1117
    memset(&distro, 0, sizeof(distro));
 
1118
    
1054
1119
    LW_CLEANUP_CTERR(exc, DJInitSmbConfig(NULL));
1055
1120
    if(options->joiningDomain)
1056
1121
    {
1058
1123
        LW_CLEANUP_CTERR(exc, SetWorkgroup(NULL, options->shortDomainName));
1059
1124
        LW_CLEANUP_CTERR(exc, DJSetSambaValue(NULL, "security", "ads"));
1060
1125
        LW_CLEANUP_CTERR(exc, DJSetSambaValue(NULL, "use kerberos keytab", "yes"));
 
1126
 
 
1127
        LW_CLEANUP_CTERR(exc, DJGetDistroInfo(NULL, &distro));
 
1128
 
 
1129
        switch (distro.os) {
 
1130
        case OS_SUNOS:
 
1131
                LW_CLEANUP_CTERR(exc, DJSetSambaValue(NULL, 
 
1132
                                                      "template homedir",
 
1133
                                                      "/export/home/local/%D/%U"));
 
1134
                LW_CLEANUP_CTERR(exc, DJSetSambaValue(NULL, 
 
1135
                                                      "template shell",
 
1136
                                                      "/bin/ksh"));
 
1137
                break;
 
1138
        case OS_DARWIN:
 
1139
                LW_CLEANUP_CTERR(exc, DJSetSambaValue(NULL, 
 
1140
                                                      "template homedir",
 
1141
                                                      "/Users/%D/%U"));
 
1142
                LW_CLEANUP_CTERR(exc, DJSetSambaValue(NULL, 
 
1143
                                                      "template shell",
 
1144
                                                      "/bin/bash"));
 
1145
                break;
 
1146
        default:
 
1147
                LW_CLEANUP_CTERR(exc, DJSetSambaValue(NULL, 
 
1148
                                                      "template homedir",
 
1149
                                                      "/home/local/%D/%U"));
 
1150
                LW_CLEANUP_CTERR(exc, DJSetSambaValue(NULL, 
 
1151
                                                      "template shell",
 
1152
                                                      "/bin/bash"));
 
1153
        }
 
1154
 
 
1155
        /*
 
1156
         * Need to determine between an Enterprise and Open install.
 
1157
         */
 
1158
 
 
1159
        LW_CLEANUP_CTERR(exc, CTCheckFileExists(PREFIXDIR "/sbin/centeris-gpagentd", 
 
1160
                                                &bGpagentdExists));
 
1161
 
 
1162
        if (bGpagentdExists) {
 
1163
                /* Likewise Enterprise */
 
1164
                LW_CLEANUP_CTERR(exc, DJSetSambaValue(NULL, 
 
1165
                                                      "idmap config default:backend", 
 
1166
                                                      "lwidentity"));
 
1167
                LW_CLEANUP_CTERR(exc, DJSetSambaValue(NULL, 
 
1168
                                                      "winbind nss info", 
 
1169
                                                      "lwidentity"));
 
1170
        } else {
 
1171
                /* Likewise Open */
 
1172
                LW_CLEANUP_CTERR(exc, DJSetSambaValue(NULL, 
 
1173
                                                      "idmap config default:backend", 
 
1174
                                                      "lwopen"));
 
1175
                LW_CLEANUP_CTERR(exc, DJSetSambaValue(NULL, 
 
1176
                                                      "winbind nss info", 
 
1177
                                                      "lwopen"));
 
1178
        }
1061
1179
    }
1062
1180
    else
1063
1181
    {
1079
1197
"realm=<dns domain name>\n"
1080
1198
"security=ads\n"
1081
1199
"use kerberos keytab=ads\n"
 
1200
"idmap default config:backend=<lwidentity | lwopen>\n"
 
1201
"winbind nss info = <lwidentity | lwopen>\n"
1082
1202
                , &ret));
1083
1203
    }
1084
1204
    else
1097
1217
 
1098
1218
CENTERROR
1099
1219
JoinDomain(
1100
 
    PSTR pszDomainName,
1101
 
    PSTR pszUserName,
1102
 
    PSTR pszPassword,
1103
 
    PSTR pszOU,
 
1220
    PCSTR pszDomainName,
 
1221
    PCSTR pszUserName,
 
1222
    PCSTR pszPassword,
 
1223
    PCSTR pszOU,
1104
1224
    BOOLEAN bDoNotChangeHosts
1105
1225
    )
1106
1226
{
 
1227
    return JoinDomainEx(pszDomainName, pszUserName, pszPassword, pszOU,
 
1228
                        bDoNotChangeHosts, FALSE);
 
1229
}
 
1230
 
 
1231
CENTERROR
 
1232
JoinDomainEx(
 
1233
    PSTR pszDomainName,
 
1234
    PSTR pszUserName,
 
1235
    PSTR pszPassword,
 
1236
    PSTR pszOU,
 
1237
    BOOLEAN bDoNotChangeHosts,
 
1238
    BOOLEAN bDoNotSyncTime
 
1239
    )
 
1240
{
1107
1241
    CENTERROR ceError = CENTERROR_SUCCESS;
1108
1242
    CENTERROR ceError2 = CENTERROR_SUCCESS;
1109
1243
    PSTR pszComputerName = NULL;
1112
1246
    PSTR pszOriginalWorkgroupName = NULL;
1113
1247
    BOOLEAN bIsValid = FALSE;
1114
1248
    PSTR pszCanonicalizedOU = NULL;
 
1249
    BOOLEAN bNoTimeSyncFileExists = FALSE;
1115
1250
 
1116
1251
    if (geteuid() != 0) {
1117
1252
       ceError = CENTERROR_DOMAINJOIN_NON_ROOT_USER;
1153
1288
 
1154
1289
    }
1155
1290
 
 
1291
    ceError = CTCheckFileExists(NO_TIME_SYNC_FILE, &bNoTimeSyncFileExists);
 
1292
    BAIL_ON_CENTERIS_ERROR(ceError);
 
1293
 
 
1294
    if (bDoNotSyncTime && !bNoTimeSyncFileExists)
 
1295
    {
 
1296
        /* Create no time sync file */
 
1297
        FILE* noTimeSyncFile = NULL;
 
1298
 
 
1299
        ceError = CTOpenFile(NO_TIME_SYNC_FILE, "w", &noTimeSyncFile);
 
1300
        BAIL_ON_CENTERIS_ERROR(ceError);
 
1301
 
 
1302
        CTCloseFile(noTimeSyncFile);
 
1303
    }
 
1304
    else if (!bDoNotSyncTime && bNoTimeSyncFileExists)
 
1305
    {
 
1306
        /* Remove no time sync file */
 
1307
        ceError = CTRemoveFile(NO_TIME_SYNC_FILE);
 
1308
        BAIL_ON_CENTERIS_ERROR(ceError);
 
1309
    }
 
1310
 
1156
1311
    /*
1157
1312
     * Make sure that the hostname is fully and properly
1158
1313
     * configured in the OS
1207
1362
                               pszUserName,
1208
1363
                               pszPassword,
1209
1364
                               pszCanonicalizedOU,
 
1365
                               bDoNotSyncTime,
1210
1366
                               &pszWorkgroupName);
1211
1367
    BAIL_ON_CENTERIS_ERROR(ceError);
1212
1368
 
1445
1601
    return ceError;
1446
1602
}
1447
1603
 
1448
 
CENTERROR
1449
 
DJGetComputerDN(PSTR *dn)
 
1604
void
 
1605
DJGetComputerDN(PSTR *dn, LWException **exc)
1450
1606
{
1451
 
    CENTERROR ceError = CENTERROR_SUCCESS;
1452
1607
    PSTR sedPath = NULL;
 
1608
    PSTR errors = NULL;
1453
1609
 
1454
1610
    *dn = NULL;
1455
 
    GCE(ceError = CTFindSed(&sedPath));
1456
 
    ceError = CTShell("%prefix/bin/lwinet ads status -P 2>/dev/null | %sedPath -n %sedExpression >%dn",
 
1611
    LW_CLEANUP_CTERR(exc, CTFindSed(&sedPath));
 
1612
    LW_CLEANUP_CTERR(exc, CTShell("%prefix/bin/lwinet ads status -P 2>%errors | %sedPath -n %sedExpression >%dn",
1457
1613
            CTSHELL_STRING(prefix, PREFIXDIR),
1458
1614
            CTSHELL_STRING(sedPath, sedPath),
1459
1615
            CTSHELL_STRING(sedExpression, "s/^distinguishedName:[ \t]*\\(.*\\)$/\\1/p"),
1460
 
            CTSHELL_BUFFER(dn, dn));
1461
 
    GCE(ceError);
 
1616
            CTSHELL_BUFFER(dn, dn),
 
1617
            CTSHELL_BUFFER(errors, &errors)
 
1618
            ));
1462
1619
    CTStripWhitespace(*dn);
1463
 
    if(*dn == NULL)
 
1620
    if(*dn == NULL || **dn == NULL)
1464
1621
    {
1465
 
        CT_SAFE_FREE_STRING(*dn);
1466
 
        GCE(ceError = CENTERROR_COMMAND_FAILED);
 
1622
        LW_RAISE_EX(exc, CENTERROR_COMMAND_FAILED, "Unable to get distinguished name", "The computer's distinguished name could not be queried. Here is the output from 'lwinet ads status -P':\n%s", errors);
 
1623
        goto cleanup;
1467
1624
    }
1468
1625
 
1469
1626
cleanup:
1470
1627
    CT_SAFE_FREE_STRING(sedPath);
1471
 
    return ceError;
 
1628
    CT_SAFE_FREE_STRING(errors);
1472
1629
}
1473
1630
 
1474
1631
CENTERROR