~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to source3/libnet/libnet_join.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
#include "includes.h"
22
 
#include "libnet/libnet.h"
 
22
#include "ads.h"
 
23
#include "librpc/gen_ndr/ndr_libnet_join.h"
 
24
#include "libnet/libnet_join.h"
23
25
#include "libcli/auth/libcli_auth.h"
24
 
#include "../librpc/gen_ndr/cli_samr.h"
25
 
#include "../librpc/gen_ndr/cli_lsa.h"
 
26
#include "../librpc/gen_ndr/ndr_samr_c.h"
 
27
#include "rpc_client/init_samr.h"
 
28
#include "../librpc/gen_ndr/ndr_lsa_c.h"
 
29
#include "rpc_client/cli_lsarpc.h"
 
30
#include "../librpc/gen_ndr/ndr_netlogon.h"
 
31
#include "rpc_client/cli_netlogon.h"
 
32
#include "lib/smbconf/smbconf.h"
 
33
#include "lib/smbconf/smbconf_reg.h"
 
34
#include "../libds/common/flags.h"
 
35
#include "secrets.h"
 
36
#include "rpc_client/init_lsa.h"
 
37
#include "rpc_client/cli_pipe.h"
 
38
#include "../libcli/security/security.h"
 
39
#include "passdb.h"
 
40
#include "libsmb/libsmb.h"
26
41
 
27
42
/****************************************************************
28
43
****************************************************************/
89
104
        va_end(args);
90
105
}
91
106
 
92
 
#ifdef WITH_ADS
 
107
#ifdef HAVE_ADS
93
108
 
94
109
/****************************************************************
95
110
****************************************************************/
629
644
 
630
645
        return ADS_SUCCESS;
631
646
}
632
 
#endif /* WITH_ADS */
 
647
#endif /* HAVE_ADS */
633
648
 
634
649
/****************************************************************
635
650
 Store the machine password and domain SID
684
699
                                   NULL,
685
700
                                   pass,
686
701
                                   flags,
687
 
                                   Undefined, NULL);
 
702
                                   Undefined);
688
703
}
689
704
 
690
705
/****************************************************************
697
712
{
698
713
        struct rpc_pipe_client *pipe_hnd = NULL;
699
714
        struct policy_handle lsa_pol;
700
 
        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
 
715
        NTSTATUS status, result;
701
716
        union lsa_PolicyInformation *info = NULL;
 
717
        struct dcerpc_binding_handle *b;
702
718
 
703
719
        status = libnet_join_connect_dc_ipc(r->in.dc_name,
704
720
                                            r->in.admin_account,
717
733
                goto done;
718
734
        }
719
735
 
 
736
        b = pipe_hnd->binding_handle;
 
737
 
720
738
        status = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
721
739
                                        SEC_FLAG_MAXIMUM_ALLOWED, &lsa_pol);
722
740
        if (!NT_STATUS_IS_OK(status)) {
723
741
                goto done;
724
742
        }
725
743
 
726
 
        status = rpccli_lsa_QueryInfoPolicy2(pipe_hnd, mem_ctx,
 
744
        status = dcerpc_lsa_QueryInfoPolicy2(b, mem_ctx,
727
745
                                             &lsa_pol,
728
746
                                             LSA_POLICY_INFO_DNS,
729
 
                                             &info);
730
 
        if (NT_STATUS_IS_OK(status)) {
 
747
                                             &info,
 
748
                                             &result);
 
749
        if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(result)) {
731
750
                r->out.domain_is_ad = true;
732
751
                r->out.netbios_domain_name = info->dns.name.string;
733
752
                r->out.dns_domain_name = info->dns.dns_domain.string;
734
753
                r->out.forest_name = info->dns.dns_forest.string;
735
 
                r->out.domain_sid = sid_dup_talloc(mem_ctx, info->dns.sid);
 
754
                r->out.domain_sid = dom_sid_dup(mem_ctx, info->dns.sid);
736
755
                NT_STATUS_HAVE_NO_MEMORY(r->out.domain_sid);
737
756
        }
738
757
 
739
758
        if (!NT_STATUS_IS_OK(status)) {
740
 
                status = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
 
759
                status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
741
760
                                                    &lsa_pol,
742
761
                                                    LSA_POLICY_INFO_ACCOUNT_DOMAIN,
743
 
                                                    &info);
 
762
                                                    &info,
 
763
                                                    &result);
744
764
                if (!NT_STATUS_IS_OK(status)) {
745
765
                        goto done;
746
766
                }
 
767
                if (!NT_STATUS_IS_OK(result)) {
 
768
                        status = result;
 
769
                        goto done;
 
770
                }
747
771
 
748
772
                r->out.netbios_domain_name = info->account_domain.name.string;
749
 
                r->out.domain_sid = sid_dup_talloc(mem_ctx, info->account_domain.sid);
 
773
                r->out.domain_sid = dom_sid_dup(mem_ctx, info->account_domain.sid);
750
774
                NT_STATUS_HAVE_NO_MEMORY(r->out.domain_sid);
751
775
        }
752
776
 
753
 
        rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);
 
777
        dcerpc_lsa_Close(b, mem_ctx, &lsa_pol, &result);
754
778
        TALLOC_FREE(pipe_hnd);
755
779
 
756
780
 done:
817
841
{
818
842
        struct rpc_pipe_client *pipe_hnd = NULL;
819
843
        struct policy_handle sam_pol, domain_pol, user_pol;
820
 
        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
 
844
        NTSTATUS status = NT_STATUS_UNSUCCESSFUL, result;
821
845
        char *acct_name;
822
846
        struct lsa_String lsa_acct_name;
823
847
        uint32_t user_rid;
825
849
        struct samr_Ids user_rids;
826
850
        struct samr_Ids name_types;
827
851
        union samr_UserInfo user_info;
 
852
        struct dcerpc_binding_handle *b = NULL;
828
853
 
829
854
        struct samr_CryptPassword crypt_pwd;
830
855
        struct samr_CryptPasswordEx crypt_pwd_ex;
859
884
                goto done;
860
885
        }
861
886
 
862
 
        status = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
 
887
        b = pipe_hnd->binding_handle;
 
888
 
 
889
        status = dcerpc_samr_Connect2(b, mem_ctx,
863
890
                                      pipe_hnd->desthost,
864
891
                                      SAMR_ACCESS_ENUM_DOMAINS
865
892
                                      | SAMR_ACCESS_LOOKUP_DOMAIN,
866
 
                                      &sam_pol);
 
893
                                      &sam_pol,
 
894
                                      &result);
867
895
        if (!NT_STATUS_IS_OK(status)) {
868
896
                goto done;
869
897
        }
 
898
        if (!NT_STATUS_IS_OK(result)) {
 
899
                status = result;
 
900
                goto done;
 
901
        }
870
902
 
871
 
        status = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
 
903
        status = dcerpc_samr_OpenDomain(b, mem_ctx,
872
904
                                        &sam_pol,
873
905
                                        SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1
874
906
                                        | SAMR_DOMAIN_ACCESS_CREATE_USER
875
907
                                        | SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
876
908
                                        r->out.domain_sid,
877
 
                                        &domain_pol);
 
909
                                        &domain_pol,
 
910
                                        &result);
878
911
        if (!NT_STATUS_IS_OK(status)) {
879
912
                goto done;
880
913
        }
 
914
        if (!NT_STATUS_IS_OK(result)) {
 
915
                status = result;
 
916
                goto done;
 
917
        }
881
918
 
882
919
        /* Create domain user */
883
920
 
898
935
                DEBUG(10,("Creating account with desired access mask: %d\n",
899
936
                        access_desired));
900
937
 
901
 
                status = rpccli_samr_CreateUser2(pipe_hnd, mem_ctx,
 
938
                status = dcerpc_samr_CreateUser2(b, mem_ctx,
902
939
                                                 &domain_pol,
903
940
                                                 &lsa_acct_name,
904
941
                                                 acct_flags,
905
942
                                                 access_desired,
906
943
                                                 &user_pol,
907
944
                                                 &access_granted,
908
 
                                                 &user_rid);
 
945
                                                 &user_rid,
 
946
                                                 &result);
 
947
                if (!NT_STATUS_IS_OK(status)) {
 
948
                        goto done;
 
949
                }
 
950
 
 
951
                status = result;
909
952
                if (!NT_STATUS_IS_OK(status) &&
910
953
                    !NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) {
911
954
 
935
978
                /* We *must* do this.... don't ask... */
936
979
 
937
980
                if (NT_STATUS_IS_OK(status)) {
938
 
                        rpccli_samr_Close(pipe_hnd, mem_ctx, &user_pol);
 
981
                        dcerpc_samr_Close(b, mem_ctx, &user_pol, &result);
939
982
                }
940
983
        }
941
984
 
942
 
        status = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
 
985
        status = dcerpc_samr_LookupNames(b, mem_ctx,
943
986
                                         &domain_pol,
944
987
                                         1,
945
988
                                         &lsa_acct_name,
946
989
                                         &user_rids,
947
 
                                         &name_types);
 
990
                                         &name_types,
 
991
                                         &result);
948
992
        if (!NT_STATUS_IS_OK(status)) {
949
993
                goto done;
950
994
        }
 
995
        if (!NT_STATUS_IS_OK(result)) {
 
996
                status = result;
 
997
                goto done;
 
998
        }
951
999
 
952
1000
        if (name_types.ids[0] != SID_NAME_USER) {
953
1001
                DEBUG(0,("%s is not a user account (type=%d)\n",
960
1008
 
961
1009
        /* Open handle on user */
962
1010
 
963
 
        status = rpccli_samr_OpenUser(pipe_hnd, mem_ctx,
 
1011
        status = dcerpc_samr_OpenUser(b, mem_ctx,
964
1012
                                      &domain_pol,
965
1013
                                      SEC_FLAG_MAXIMUM_ALLOWED,
966
1014
                                      user_rid,
967
 
                                      &user_pol);
 
1015
                                      &user_pol,
 
1016
                                      &result);
968
1017
        if (!NT_STATUS_IS_OK(status)) {
969
1018
                goto done;
970
1019
        }
 
1020
        if (!NT_STATUS_IS_OK(result)) {
 
1021
                status = result;
 
1022
                goto done;
 
1023
        }
971
1024
 
972
1025
        /* Fill in the additional account flags now */
973
1026
 
974
1027
        acct_flags |= ACB_PWNOEXP;
975
 
        if (r->out.domain_is_ad) {
976
 
#if !defined(ENCTYPE_ARCFOUR_HMAC)
977
 
                acct_flags |= ACB_USE_DES_KEY_ONLY;
978
 
#endif
979
 
                ;;
980
 
        }
981
1028
 
982
1029
        /* Set account flags on machine account */
983
1030
        ZERO_STRUCT(user_info.info16);
984
1031
        user_info.info16.acct_flags = acct_flags;
985
1032
 
986
 
        status = rpccli_samr_SetUserInfo(pipe_hnd, mem_ctx,
 
1033
        status = dcerpc_samr_SetUserInfo(b, mem_ctx,
987
1034
                                         &user_pol,
988
1035
                                         16,
989
 
                                         &user_info);
990
 
 
 
1036
                                         &user_info,
 
1037
                                         &result);
991
1038
        if (!NT_STATUS_IS_OK(status)) {
992
 
 
993
 
                rpccli_samr_DeleteUser(pipe_hnd, mem_ctx,
994
 
                                       &user_pol);
 
1039
                dcerpc_samr_DeleteUser(b, mem_ctx,
 
1040
                                       &user_pol,
 
1041
                                       &result);
 
1042
 
 
1043
                libnet_join_set_error_string(mem_ctx, r,
 
1044
                        "Failed to set account flags for machine account (%s)\n",
 
1045
                        nt_errstr(status));
 
1046
                goto done;
 
1047
        }
 
1048
 
 
1049
        if (!NT_STATUS_IS_OK(result)) {
 
1050
                status = result;
 
1051
 
 
1052
                dcerpc_samr_DeleteUser(b, mem_ctx,
 
1053
                                       &user_pol,
 
1054
                                       &result);
995
1055
 
996
1056
                libnet_join_set_error_string(mem_ctx, r,
997
1057
                        "Failed to set account flags for machine account (%s)\n",
1008
1068
        user_info.info26.password = crypt_pwd_ex;
1009
1069
        user_info.info26.password_expired = PASS_DONT_CHANGE_AT_NEXT_LOGON;
1010
1070
 
1011
 
        status = rpccli_samr_SetUserInfo2(pipe_hnd, mem_ctx,
 
1071
        status = dcerpc_samr_SetUserInfo2(b, mem_ctx,
1012
1072
                                          &user_pol,
1013
1073
                                          26,
1014
 
                                          &user_info);
 
1074
                                          &user_info,
 
1075
                                          &result);
1015
1076
 
1016
 
        if (NT_STATUS_EQUAL(status, NT_STATUS(DCERPC_FAULT_INVALID_TAG))) {
 
1077
        if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_ENUM_VALUE_OUT_OF_RANGE)) {
1017
1078
 
1018
1079
                /* retry with level 24 */
1019
1080
 
1024
1085
                user_info.info24.password = crypt_pwd;
1025
1086
                user_info.info24.password_expired = PASS_DONT_CHANGE_AT_NEXT_LOGON;
1026
1087
 
1027
 
                status = rpccli_samr_SetUserInfo2(pipe_hnd, mem_ctx,
 
1088
                status = dcerpc_samr_SetUserInfo2(b, mem_ctx,
1028
1089
                                                  &user_pol,
1029
1090
                                                  24,
1030
 
                                                  &user_info);
 
1091
                                                  &user_info,
 
1092
                                                  &result);
1031
1093
        }
1032
1094
 
1033
1095
        if (!NT_STATUS_IS_OK(status)) {
1034
1096
 
1035
 
                rpccli_samr_DeleteUser(pipe_hnd, mem_ctx,
1036
 
                                       &user_pol);
 
1097
                dcerpc_samr_DeleteUser(b, mem_ctx,
 
1098
                                       &user_pol,
 
1099
                                       &result);
 
1100
 
 
1101
                libnet_join_set_error_string(mem_ctx, r,
 
1102
                        "Failed to set password for machine account (%s)\n",
 
1103
                        nt_errstr(status));
 
1104
                goto done;
 
1105
        }
 
1106
        if (!NT_STATUS_IS_OK(result)) {
 
1107
                status = result;
 
1108
 
 
1109
                dcerpc_samr_DeleteUser(b, mem_ctx,
 
1110
                                       &user_pol,
 
1111
                                       &result);
1037
1112
 
1038
1113
                libnet_join_set_error_string(mem_ctx, r,
1039
1114
                        "Failed to set password for machine account (%s)\n",
1049
1124
        }
1050
1125
 
1051
1126
        if (is_valid_policy_hnd(&sam_pol)) {
1052
 
                rpccli_samr_Close(pipe_hnd, mem_ctx, &sam_pol);
 
1127
                dcerpc_samr_Close(b, mem_ctx, &sam_pol, &result);
1053
1128
        }
1054
1129
        if (is_valid_policy_hnd(&domain_pol)) {
1055
 
                rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_pol);
 
1130
                dcerpc_samr_Close(b, mem_ctx, &domain_pol, &result);
1056
1131
        }
1057
1132
        if (is_valid_policy_hnd(&user_pol)) {
1058
 
                rpccli_samr_Close(pipe_hnd, mem_ctx, &user_pol);
 
1133
                dcerpc_samr_Close(b, mem_ctx, &user_pol, &result);
1059
1134
        }
1060
1135
        TALLOC_FREE(pipe_hnd);
1061
1136
 
1104
1179
                                     NULL,
1105
1180
                                     machine_password,
1106
1181
                                     0,
1107
 
                                     Undefined, NULL);
 
1182
                                     Undefined);
1108
1183
        free(machine_account);
1109
1184
        free(machine_password);
1110
1185
 
1117
1192
                                             NULL,
1118
1193
                                             "",
1119
1194
                                             0,
1120
 
                                             Undefined, NULL);
 
1195
                                             Undefined);
1121
1196
        }
1122
1197
 
1123
1198
        if (!NT_STATUS_IS_OK(status)) {
1209
1284
        struct cli_state *cli = NULL;
1210
1285
        struct rpc_pipe_client *pipe_hnd = NULL;
1211
1286
        struct policy_handle sam_pol, domain_pol, user_pol;
1212
 
        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
 
1287
        NTSTATUS status = NT_STATUS_UNSUCCESSFUL, result;
1213
1288
        char *acct_name;
1214
1289
        uint32_t user_rid;
1215
1290
        struct lsa_String lsa_acct_name;
1216
1291
        struct samr_Ids user_rids;
1217
1292
        struct samr_Ids name_types;
1218
1293
        union samr_UserInfo *info = NULL;
 
1294
        struct dcerpc_binding_handle *b = NULL;
1219
1295
 
1220
1296
        ZERO_STRUCT(sam_pol);
1221
1297
        ZERO_STRUCT(domain_pol);
1240
1316
                goto done;
1241
1317
        }
1242
1318
 
1243
 
        status = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
 
1319
        b = pipe_hnd->binding_handle;
 
1320
 
 
1321
        status = dcerpc_samr_Connect2(b, mem_ctx,
1244
1322
                                      pipe_hnd->desthost,
1245
1323
                                      SEC_FLAG_MAXIMUM_ALLOWED,
1246
 
                                      &sam_pol);
 
1324
                                      &sam_pol,
 
1325
                                      &result);
1247
1326
        if (!NT_STATUS_IS_OK(status)) {
1248
1327
                goto done;
1249
1328
        }
 
1329
        if (!NT_STATUS_IS_OK(result)) {
 
1330
                status = result;
 
1331
                goto done;
 
1332
        }
1250
1333
 
1251
 
        status = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
 
1334
        status = dcerpc_samr_OpenDomain(b, mem_ctx,
1252
1335
                                        &sam_pol,
1253
1336
                                        SEC_FLAG_MAXIMUM_ALLOWED,
1254
1337
                                        r->in.domain_sid,
1255
 
                                        &domain_pol);
 
1338
                                        &domain_pol,
 
1339
                                        &result);
1256
1340
        if (!NT_STATUS_IS_OK(status)) {
1257
1341
                goto done;
1258
1342
        }
 
1343
        if (!NT_STATUS_IS_OK(result)) {
 
1344
                status = result;
 
1345
                goto done;
 
1346
        }
1259
1347
 
1260
1348
        /* Create domain user */
1261
1349
 
1264
1352
 
1265
1353
        init_lsa_String(&lsa_acct_name, acct_name);
1266
1354
 
1267
 
        status = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
 
1355
        status = dcerpc_samr_LookupNames(b, mem_ctx,
1268
1356
                                         &domain_pol,
1269
1357
                                         1,
1270
1358
                                         &lsa_acct_name,
1271
1359
                                         &user_rids,
1272
 
                                         &name_types);
 
1360
                                         &name_types,
 
1361
                                         &result);
1273
1362
 
1274
1363
        if (!NT_STATUS_IS_OK(status)) {
1275
1364
                goto done;
1276
1365
        }
 
1366
        if (!NT_STATUS_IS_OK(result)) {
 
1367
                status = result;
 
1368
                goto done;
 
1369
        }
1277
1370
 
1278
1371
        if (name_types.ids[0] != SID_NAME_USER) {
1279
1372
                DEBUG(0, ("%s is not a user account (type=%d)\n", acct_name,
1286
1379
 
1287
1380
        /* Open handle on user */
1288
1381
 
1289
 
        status = rpccli_samr_OpenUser(pipe_hnd, mem_ctx,
 
1382
        status = dcerpc_samr_OpenUser(b, mem_ctx,
1290
1383
                                      &domain_pol,
1291
1384
                                      SEC_FLAG_MAXIMUM_ALLOWED,
1292
1385
                                      user_rid,
1293
 
                                      &user_pol);
 
1386
                                      &user_pol,
 
1387
                                      &result);
1294
1388
        if (!NT_STATUS_IS_OK(status)) {
1295
1389
                goto done;
1296
1390
        }
 
1391
        if (!NT_STATUS_IS_OK(result)) {
 
1392
                status = result;
 
1393
                goto done;
 
1394
        }
1297
1395
 
1298
1396
        /* Get user info */
1299
1397
 
1300
 
        status = rpccli_samr_QueryUserInfo(pipe_hnd, mem_ctx,
 
1398
        status = dcerpc_samr_QueryUserInfo(b, mem_ctx,
1301
1399
                                           &user_pol,
1302
1400
                                           16,
1303
 
                                           &info);
 
1401
                                           &info,
 
1402
                                           &result);
1304
1403
        if (!NT_STATUS_IS_OK(status)) {
1305
 
                rpccli_samr_Close(pipe_hnd, mem_ctx, &user_pol);
 
1404
                dcerpc_samr_Close(b, mem_ctx, &user_pol, &result);
 
1405
                goto done;
 
1406
        }
 
1407
        if (!NT_STATUS_IS_OK(result)) {
 
1408
                status = result;
 
1409
                dcerpc_samr_Close(b, mem_ctx, &user_pol, &result);
1306
1410
                goto done;
1307
1411
        }
1308
1412
 
1310
1414
 
1311
1415
        info->info16.acct_flags |= ACB_DISABLED;
1312
1416
 
1313
 
        status = rpccli_samr_SetUserInfo(pipe_hnd, mem_ctx,
 
1417
        status = dcerpc_samr_SetUserInfo(b, mem_ctx,
1314
1418
                                         &user_pol,
1315
1419
                                         16,
1316
 
                                         info);
1317
 
 
1318
 
        rpccli_samr_Close(pipe_hnd, mem_ctx, &user_pol);
 
1420
                                         info,
 
1421
                                         &result);
 
1422
        if (!NT_STATUS_IS_OK(status)) {
 
1423
                dcerpc_samr_Close(b, mem_ctx, &user_pol, &result);
 
1424
                goto done;
 
1425
        }
 
1426
        if (!NT_STATUS_IS_OK(result)) {
 
1427
                status = result;
 
1428
                dcerpc_samr_Close(b, mem_ctx, &user_pol, &result);
 
1429
                goto done;
 
1430
        }
 
1431
        status = result;
 
1432
        dcerpc_samr_Close(b, mem_ctx, &user_pol, &result);
1319
1433
 
1320
1434
done:
1321
 
        if (pipe_hnd) {
 
1435
        if (pipe_hnd && b) {
1322
1436
                if (is_valid_policy_hnd(&domain_pol)) {
1323
 
                        rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_pol);
 
1437
                        dcerpc_samr_Close(b, mem_ctx, &domain_pol, &result);
1324
1438
                }
1325
1439
                if (is_valid_policy_hnd(&sam_pol)) {
1326
 
                        rpccli_samr_Close(pipe_hnd, mem_ctx, &sam_pol);
 
1440
                        dcerpc_samr_Close(b, mem_ctx, &sam_pol, &result);
1327
1441
                }
1328
1442
                TALLOC_FREE(pipe_hnd);
1329
1443
        }
1340
1454
 
1341
1455
static WERROR do_join_modify_vals_config(struct libnet_JoinCtx *r)
1342
1456
{
1343
 
        WERROR werr;
 
1457
        WERROR werr = WERR_OK;
 
1458
        sbcErr err;
1344
1459
        struct smbconf_ctx *ctx;
1345
1460
 
1346
 
        werr = smbconf_init_reg(r, &ctx, NULL);
1347
 
        if (!W_ERROR_IS_OK(werr)) {
 
1461
        err = smbconf_init_reg(r, &ctx, NULL);
 
1462
        if (!SBC_ERROR_IS_OK(err)) {
 
1463
                werr = WERR_NO_SUCH_SERVICE;
1348
1464
                goto done;
1349
1465
        }
1350
1466
 
1351
1467
        if (!(r->in.join_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE)) {
1352
1468
 
1353
 
                werr = smbconf_set_global_parameter(ctx, "security", "user");
1354
 
                W_ERROR_NOT_OK_GOTO_DONE(werr);
 
1469
                err = smbconf_set_global_parameter(ctx, "security", "user");
 
1470
                if (!SBC_ERROR_IS_OK(err)) {
 
1471
                        werr = WERR_NO_SUCH_SERVICE;
 
1472
                        goto done;
 
1473
                }
1355
1474
 
1356
 
                werr = smbconf_set_global_parameter(ctx, "workgroup",
1357
 
                                                    r->in.domain_name);
 
1475
                err = smbconf_set_global_parameter(ctx, "workgroup",
 
1476
                                                   r->in.domain_name);
 
1477
                if (!SBC_ERROR_IS_OK(err)) {
 
1478
                        werr = WERR_NO_SUCH_SERVICE;
 
1479
                        goto done;
 
1480
                }
1358
1481
 
1359
1482
                smbconf_delete_global_parameter(ctx, "realm");
1360
1483
                goto done;
1361
1484
        }
1362
1485
 
1363
 
        werr = smbconf_set_global_parameter(ctx, "security", "domain");
1364
 
        W_ERROR_NOT_OK_GOTO_DONE(werr);
 
1486
        err = smbconf_set_global_parameter(ctx, "security", "domain");
 
1487
        if (!SBC_ERROR_IS_OK(err)) {
 
1488
                werr = WERR_NO_SUCH_SERVICE;
 
1489
                goto done;
 
1490
        }
1365
1491
 
1366
 
        werr = smbconf_set_global_parameter(ctx, "workgroup",
1367
 
                                            r->out.netbios_domain_name);
1368
 
        W_ERROR_NOT_OK_GOTO_DONE(werr);
 
1492
        err = smbconf_set_global_parameter(ctx, "workgroup",
 
1493
                                           r->out.netbios_domain_name);
 
1494
        if (!SBC_ERROR_IS_OK(err)) {
 
1495
                werr = WERR_NO_SUCH_SERVICE;
 
1496
                goto done;
 
1497
        }
1369
1498
 
1370
1499
        if (r->out.domain_is_ad) {
1371
 
                werr = smbconf_set_global_parameter(ctx, "security", "ads");
1372
 
                W_ERROR_NOT_OK_GOTO_DONE(werr);
 
1500
                err = smbconf_set_global_parameter(ctx, "security", "ads");
 
1501
                if (!SBC_ERROR_IS_OK(err)) {
 
1502
                        werr = WERR_NO_SUCH_SERVICE;
 
1503
                        goto done;
 
1504
                }
1373
1505
 
1374
 
                werr = smbconf_set_global_parameter(ctx, "realm",
1375
 
                                                    r->out.dns_domain_name);
1376
 
                W_ERROR_NOT_OK_GOTO_DONE(werr);
 
1506
                err = smbconf_set_global_parameter(ctx, "realm",
 
1507
                                                   r->out.dns_domain_name);
 
1508
                if (!SBC_ERROR_IS_OK(err)) {
 
1509
                        werr = WERR_NO_SUCH_SERVICE;
 
1510
                        goto done;
 
1511
                }
1377
1512
        }
1378
1513
 
1379
1514
 done:
1387
1522
static WERROR do_unjoin_modify_vals_config(struct libnet_UnjoinCtx *r)
1388
1523
{
1389
1524
        WERROR werr = WERR_OK;
 
1525
        sbcErr err;
1390
1526
        struct smbconf_ctx *ctx;
1391
1527
 
1392
 
        werr = smbconf_init_reg(r, &ctx, NULL);
1393
 
        if (!W_ERROR_IS_OK(werr)) {
 
1528
        err = smbconf_init_reg(r, &ctx, NULL);
 
1529
        if (!SBC_ERROR_IS_OK(err)) {
 
1530
                werr = WERR_NO_SUCH_SERVICE;
1394
1531
                goto done;
1395
1532
        }
1396
1533
 
1397
1534
        if (r->in.unjoin_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE) {
1398
1535
 
1399
 
                werr = smbconf_set_global_parameter(ctx, "security", "user");
1400
 
                W_ERROR_NOT_OK_GOTO_DONE(werr);
 
1536
                err = smbconf_set_global_parameter(ctx, "security", "user");
 
1537
                if (!SBC_ERROR_IS_OK(err)) {
 
1538
                        werr = WERR_NO_SUCH_SERVICE;
 
1539
                        goto done;
 
1540
                }
1401
1541
 
1402
 
                werr = smbconf_delete_global_parameter(ctx, "workgroup");
1403
 
                W_ERROR_NOT_OK_GOTO_DONE(werr);
 
1542
                err = smbconf_delete_global_parameter(ctx, "workgroup");
 
1543
                if (!SBC_ERROR_IS_OK(err)) {
 
1544
                        werr = WERR_NO_SUCH_SERVICE;
 
1545
                        goto done;
 
1546
                }
1404
1547
 
1405
1548
                smbconf_delete_global_parameter(ctx, "realm");
1406
1549
        }
1598
1741
                saf_join_store(r->out.dns_domain_name, r->in.dc_name);
1599
1742
        }
1600
1743
 
1601
 
#ifdef WITH_ADS
 
1744
#ifdef HAVE_ADS
1602
1745
        if (r->out.domain_is_ad &&
1603
1746
            !(r->in.join_flags & WKSSVC_JOIN_FLAGS_JOIN_UNSECURE)) {
1604
1747
                ADS_STATUS ads_status;
1608
1751
                        return WERR_GENERAL_FAILURE;
1609
1752
                }
1610
1753
        }
1611
 
#endif /* WITH_ADS */
 
1754
#endif /* HAVE_ADS */
1612
1755
 
1613
1756
        libnet_join_add_dom_rids_to_builtins(r->out.domain_sid);
1614
1757
 
1620
1763
 
1621
1764
static int libnet_destroy_JoinCtx(struct libnet_JoinCtx *r)
1622
1765
{
1623
 
        const char *krb5_cc_env = NULL;
1624
 
 
1625
1766
        if (r->in.ads) {
1626
1767
                ads_destroy(&r->in.ads);
1627
1768
        }
1628
1769
 
1629
 
        krb5_cc_env = getenv(KRB5_ENV_CCNAME);
1630
 
        if (krb5_cc_env && StrCaseCmp(krb5_cc_env, "MEMORY:libnetjoin")) {
1631
 
                unsetenv(KRB5_ENV_CCNAME);
1632
 
        }
1633
 
 
1634
1770
        return 0;
1635
1771
}
1636
1772
 
1639
1775
 
1640
1776
static int libnet_destroy_UnjoinCtx(struct libnet_UnjoinCtx *r)
1641
1777
{
1642
 
        const char *krb5_cc_env = NULL;
1643
 
 
1644
1778
        if (r->in.ads) {
1645
1779
                ads_destroy(&r->in.ads);
1646
1780
        }
1647
1781
 
1648
 
        krb5_cc_env = getenv(KRB5_ENV_CCNAME);
1649
 
        if (krb5_cc_env && StrCaseCmp(krb5_cc_env, "MEMORY:libnetjoin")) {
1650
 
                unsetenv(KRB5_ENV_CCNAME);
1651
 
        }
1652
 
 
1653
1782
        return 0;
1654
1783
}
1655
1784
 
1660
1789
                           struct libnet_JoinCtx **r)
1661
1790
{
1662
1791
        struct libnet_JoinCtx *ctx;
1663
 
        const char *krb5_cc_env = NULL;
1664
1792
 
1665
1793
        ctx = talloc_zero(mem_ctx, struct libnet_JoinCtx);
1666
1794
        if (!ctx) {
1672
1800
        ctx->in.machine_name = talloc_strdup(mem_ctx, global_myname());
1673
1801
        W_ERROR_HAVE_NO_MEMORY(ctx->in.machine_name);
1674
1802
 
1675
 
        krb5_cc_env = getenv(KRB5_ENV_CCNAME);
1676
 
        if (!krb5_cc_env || (strlen(krb5_cc_env) == 0)) {
1677
 
                krb5_cc_env = talloc_strdup(mem_ctx, "MEMORY:libnetjoin");
1678
 
                W_ERROR_HAVE_NO_MEMORY(krb5_cc_env);
1679
 
                setenv(KRB5_ENV_CCNAME, krb5_cc_env, 1);
1680
 
        }
1681
 
 
1682
1803
        ctx->in.secure_channel_type = SEC_CHAN_WKSTA;
1683
1804
 
1684
1805
        *r = ctx;
1693
1814
                             struct libnet_UnjoinCtx **r)
1694
1815
{
1695
1816
        struct libnet_UnjoinCtx *ctx;
1696
 
        const char *krb5_cc_env = NULL;
1697
1817
 
1698
1818
        ctx = talloc_zero(mem_ctx, struct libnet_UnjoinCtx);
1699
1819
        if (!ctx) {
1705
1825
        ctx->in.machine_name = talloc_strdup(mem_ctx, global_myname());
1706
1826
        W_ERROR_HAVE_NO_MEMORY(ctx->in.machine_name);
1707
1827
 
1708
 
        krb5_cc_env = getenv(KRB5_ENV_CCNAME);
1709
 
        if (!krb5_cc_env || (strlen(krb5_cc_env) == 0)) {
1710
 
                krb5_cc_env = talloc_strdup(mem_ctx, "MEMORY:libnetjoin");
1711
 
                W_ERROR_HAVE_NO_MEMORY(krb5_cc_env);
1712
 
                setenv(KRB5_ENV_CCNAME, krb5_cc_env, 1);
1713
 
        }
1714
 
 
1715
1828
        *r = ctx;
1716
1829
 
1717
1830
        return WERR_OK;
1816
1929
        NTSTATUS status;
1817
1930
        WERROR werr;
1818
1931
        struct cli_state *cli = NULL;
1819
 
#ifdef WITH_ADS
 
1932
#ifdef HAVE_ADS
1820
1933
        ADS_STATUS ads_status;
1821
 
#endif /* WITH_ADS */
 
1934
#endif /* HAVE_ADS */
1822
1935
 
1823
1936
        if (!r->in.dc_name) {
1824
1937
                struct netr_DsRGetDCNameInfo *info;
1859
1972
                goto done;
1860
1973
        }
1861
1974
 
1862
 
#ifdef WITH_ADS
 
1975
#ifdef HAVE_ADS
 
1976
 
 
1977
        create_local_private_krb5_conf_for_domain(
 
1978
                r->out.dns_domain_name, r->out.netbios_domain_name,
 
1979
                NULL, &cli->dest_ss, cli->desthost);
 
1980
 
1863
1981
        if (r->out.domain_is_ad && r->in.account_ou &&
1864
1982
            !(r->in.join_flags & WKSSVC_JOIN_FLAGS_JOIN_UNSECURE)) {
1865
1983
 
1879
1997
 
1880
1998
                r->in.join_flags &= ~WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE;
1881
1999
        }
1882
 
#endif /* WITH_ADS */
 
2000
#endif /* HAVE_ADS */
1883
2001
 
1884
2002
        if ((r->in.join_flags & WKSSVC_JOIN_FLAGS_JOIN_UNSECURE) &&
1885
2003
            (r->in.join_flags & WKSSVC_JOIN_FLAGS_MACHINE_PWD_PASSED)) {
1954
2072
                LIBNET_JOIN_IN_DUMP_CTX(mem_ctx, r);
1955
2073
        }
1956
2074
 
 
2075
        ZERO_STRUCT(r->out);
 
2076
 
1957
2077
        werr = libnet_join_pre_processing(mem_ctx, r);
1958
2078
        if (!W_ERROR_IS_OK(werr)) {
1959
2079
                goto done;
2002
2122
                                "Unable to fetch domain sid: are we joined?");
2003
2123
                        return WERR_SETUP_NOT_JOINED;
2004
2124
                }
2005
 
                r->in.domain_sid = sid_dup_talloc(mem_ctx, &sid);
 
2125
                r->in.domain_sid = dom_sid_dup(mem_ctx, &sid);
2006
2126
                W_ERROR_HAVE_NO_MEMORY(r->in.domain_sid);
2007
2127
        }
2008
2128
 
2037
2157
                W_ERROR_HAVE_NO_MEMORY(r->in.dc_name);
2038
2158
        }
2039
2159
 
2040
 
#ifdef WITH_ADS
 
2160
#ifdef HAVE_ADS
2041
2161
        /* for net ads leave, try to delete the account.  If it works, 
2042
2162
           no sense in disabling.  If it fails, we can still try to 
2043
2163
           disable it. jmcd */
2044
 
           
 
2164
 
2045
2165
        if (r->in.delete_machine_account) {
2046
2166
                ADS_STATUS ads_status;
2047
2167
                ads_status = libnet_unjoin_connect_ads(mem_ctx, r);
2064
2184
                        return WERR_OK;
2065
2185
                }
2066
2186
        }
2067
 
#endif /* WITH_ADS */
 
2187
#endif /* HAVE_ADS */
2068
2188
 
2069
2189
        /* The WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE flag really means 
2070
2190
           "disable".  */
2079
2199
                        }
2080
2200
                        return ntstatus_to_werror(status);
2081
2201
                }
2082
 
                
 
2202
 
2083
2203
                r->out.disabled_machine_account = true;
2084
2204
        }
2085
2205