~ubuntu-branches/debian/sid/openchange/sid

« back to all changes in this revision

Viewing changes to libmapi/IProfAdmin.c

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2012-04-12 20:07:57 UTC
  • mfrom: (11 sid)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20120412200757-k933d9trljmxj1l4
Tags: 1:1.0-4
* openchangeserver: Add dependency on openchangeproxy.
* Rebuild against newer version of Samba 4.
* Use dpkg-buildflags.
* Migrate to Git, update Vcs-Git header.
* Switch to debhelper 9.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
        struct ldb_message      *msg;
49
49
        const char * const      attrs[] = { "*", NULL };
50
50
 
 
51
        memset(profile, 0, sizeof(struct mapi_profile));
51
52
        /* fills in profile name */
52
53
        profile->profname = talloc_strdup(mem_ctx, profname);
53
54
        if (!profile->profname) return MAPI_E_NOT_ENOUGH_RESOURCES;
381
382
        OPENCHANGE_RETVAL_IF(!profile, MAPI_E_BAD_VALUE, NULL);
382
383
        OPENCHANGE_RETVAL_IF(!value, MAPI_E_INVALID_PARAMETER, NULL);
383
384
 
384
 
        mem_ctx = talloc_named(NULL, 0, "mapi_profile_add_string_attr");
 
385
        mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "mapi_profile_add_string_attr");
385
386
        ldb_ctx = mapi_ctx->ldb_ctx;
386
387
 
387
388
        /* Retrieve the profile from the database */
441
442
        OPENCHANGE_RETVAL_IF(!profname, MAPI_E_BAD_VALUE, NULL);
442
443
 
443
444
        ldb_ctx = mapi_ctx->ldb_ctx;
444
 
        mem_ctx = talloc_named(NULL, 0, "mapi_profile_modify_string_attr");
 
445
        mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "mapi_profile_modify_string_attr");
445
446
 
446
447
        /* Retrieve the profile from the database */
447
448
        ret = ldb_search(ldb_ctx, mem_ctx, &res, ldb_get_default_basedn(ldb_ctx), scope, attrs, "(cn=%s)(cn=Profiles)", profname);
505
506
        OPENCHANGE_RETVAL_IF(!profname, MAPI_E_BAD_VALUE, NULL);
506
507
 
507
508
        ldb_ctx = mapi_ctx->ldb_ctx;
508
 
        mem_ctx = talloc_named(NULL, 0, "mapi_profile_delete_string_attr");
 
509
        mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "mapi_profile_delete_string_attr");
509
510
 
510
511
        /* Retrieve the profile from the database */
511
512
        ret = ldb_search(ldb_ctx, mem_ctx, &res, ldb_get_default_basedn(ldb_ctx), scope, attrs, "(cn=%s)(cn=Profiles)", profname);
612
613
        FILE                    *f;
613
614
        struct tevent_context   *ev;
614
615
 
615
 
        OPENCHANGE_RETVAL_IF(!profiledb, MAPI_E_CALL_FAILED, NULL);
616
 
        OPENCHANGE_RETVAL_IF(!ldif_path, MAPI_E_CALL_FAILED, NULL);
 
616
        OPENCHANGE_RETVAL_IF(!profiledb, MAPI_E_INVALID_PARAMETER, NULL);
 
617
        OPENCHANGE_RETVAL_IF(!ldif_path, MAPI_E_INVALID_PARAMETER, NULL);
617
618
 
618
619
        mem_ctx = talloc_named(NULL, 0, "CreateProfileStore");
619
620
 
712
713
        retval = ldb_load_profile(mem_ctx, mapi_ctx->ldb_ctx, profile, profname, password);
713
714
 
714
715
        OPENCHANGE_RETVAL_IF(retval, retval, NULL);
 
716
        profile->mapi_ctx = mapi_ctx;
715
717
 
716
 
        return MAPI_E_SUCCESS;  
 
718
        return MAPI_E_SUCCESS;
717
719
}
718
720
 
719
721
/**
748
750
        OPENCHANGE_RETVAL_IF(!mapi_ctx->session, MAPI_E_NOT_INITIALIZED, NULL);
749
751
        OPENCHANGE_RETVAL_IF(!profile, MAPI_E_INVALID_PARAMETER, NULL);
750
752
 
751
 
        mem_ctx = (TALLOC_CTX *) mapi_ctx->session;
 
753
        mem_ctx = mapi_ctx->mem_ctx;
752
754
 
753
755
        profile->credentials = cli_credentials_init(mem_ctx);
754
756
        OPENCHANGE_RETVAL_IF(!profile->credentials, MAPI_E_NOT_ENOUGH_RESOURCES, NULL);
861
863
        OPENCHANGE_RETVAL_IF(!mapi_ctx, MAPI_E_NOT_INITIALIZED, NULL);
862
864
        OPENCHANGE_RETVAL_IF(!mapi_ctx->ldb_ctx, MAPI_E_NOT_INITIALIZED, NULL);
863
865
 
864
 
        mem_ctx = talloc_named(NULL, 0, "CreateProfile");
 
866
        mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "CreateProfile");
865
867
        retval = ldb_create_profile(mem_ctx, mapi_ctx->ldb_ctx, profile);
866
868
        OPENCHANGE_RETVAL_IF(retval, retval, mem_ctx);
867
869
 
903
905
        OPENCHANGE_RETVAL_IF(!mapi_ctx, MAPI_E_NOT_INITIALIZED, NULL);
904
906
        OPENCHANGE_RETVAL_IF(!mapi_ctx->ldb_ctx, MAPI_E_NOT_INITIALIZED, NULL);
905
907
 
906
 
        mem_ctx = talloc_named(NULL, 0, "DeleteProfile");
 
908
        mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "DeleteProfile");
907
909
        retval = ldb_delete_profile(mem_ctx, mapi_ctx->ldb_ctx, profile);
908
910
        OPENCHANGE_RETVAL_IF(retval, retval, mem_ctx);
909
911
        talloc_free(mem_ctx);
944
946
        OPENCHANGE_RETVAL_IF(!profile || !old_password || 
945
947
                             !password, MAPI_E_INVALID_PARAMETER, NULL);
946
948
 
947
 
        mem_ctx = talloc_named(NULL, 0, "ChangeProfilePassword");
 
949
        mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "ChangeProfilePassword");
948
950
 
949
951
        retval = ldb_test_password(mapi_ctx, mem_ctx, profile, password);
950
952
        OPENCHANGE_RETVAL_IF(retval, retval, mem_ctx);
977
979
        OPENCHANGE_RETVAL_IF(!profile_src, MAPI_E_INVALID_PARAMETER, NULL);
978
980
        OPENCHANGE_RETVAL_IF(!profile_dst, MAPI_E_INVALID_PARAMETER, NULL);
979
981
 
980
 
        mem_ctx = talloc_named(NULL, 0, "CopyProfile");
 
982
        mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "CopyProfile");
981
983
 
982
984
        retval = ldb_copy_profile(mem_ctx, mapi_ctx->ldb_ctx, profile_src, profile_dst);
983
985
        OPENCHANGE_RETVAL_IF(retval, retval, mem_ctx);
986
988
        return retval;
987
989
}
988
990
 
 
991
static bool set_profile_attribute(struct mapi_context *mapi_ctx,
 
992
                                  const char *profname,
 
993
                                  struct SRowSet rowset,
 
994
                                  uint32_t index,
 
995
                                  uint32_t property,
 
996
                                  const char *attr);
989
997
 
990
998
/**
991
999
   \details Duplicate an existing profile.
1012
1020
        TALLOC_CTX              *mem_ctx;
1013
1021
        enum MAPISTATUS         retval;
1014
1022
        char                    *username_src = NULL;
1015
 
        char                    *EmailAddress = NULL;
1016
1023
        char                    *ProxyAddress = NULL;
 
1024
        char                    *oldEmailAddress = NULL;
1017
1025
        struct mapi_profile     profile;
1018
1026
        char                    **attr_tmp = NULL;
1019
1027
        char                    *tmp = NULL;
1034
1042
        retval = OpenProfile(mapi_ctx, &profile, profile_src, NULL);
1035
1043
        OPENCHANGE_RETVAL_IF(retval, MAPI_E_NOT_FOUND, NULL);
1036
1044
 
1037
 
        mem_ctx = talloc_named(NULL, 0, "DuplicateProfile");
 
1045
        mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "DuplicateProfile");
1038
1046
 
1039
1047
        retval = GetProfileAttr(&profile, "username", &count, &attr_tmp);
1040
1048
        OPENCHANGE_RETVAL_IF(retval || !count, MAPI_E_NOT_FOUND, mem_ctx);
1042
1050
        talloc_free(attr_tmp[0]);
1043
1051
 
1044
1052
        retval = GetProfileAttr(&profile, "EmailAddress", &count, &attr_tmp);
1045
 
        OPENCHANGE_RETVAL_IF(retval || !count, MAPI_E_NOT_FOUND, mem_ctx);
1046
 
        EmailAddress = talloc_strdup(mem_ctx, attr_tmp[0]);
 
1053
        OPENCHANGE_RETVAL_IF(retval, MAPI_E_NOT_FOUND, mem_ctx);
 
1054
        oldEmailAddress = talloc_strdup(mem_ctx, attr_tmp[0]);
1047
1055
        talloc_free(attr_tmp[0]);
1048
1056
 
1049
1057
        retval = GetProfileAttr(&profile, "ProxyAddress", &count, &attr_tmp);
1053
1061
 
1054
1062
        /* Change EmailAddress */
1055
1063
        {
1056
 
                int     i;
1057
 
 
1058
 
                tmp = NULL;
1059
 
                for (i = strlen(EmailAddress); i > 0; i--) {
1060
 
                        if (EmailAddress[i] == '=') {
1061
 
                                tmp = talloc_strndup(mem_ctx, EmailAddress, i + 1);
1062
 
                                break;
1063
 
                        }
1064
 
                }
1065
 
                OPENCHANGE_RETVAL_IF(!tmp, MAPI_E_INVALID_PARAMETER, mem_ctx);
1066
 
 
1067
 
                attr = talloc_asprintf(mem_ctx, "%s%s", tmp, username);
1068
 
                talloc_free(tmp);
1069
 
                mapi_profile_modify_string_attr(mapi_ctx, profile_dst, "EmailAddress", attr);
1070
 
                talloc_free(attr);
 
1064
                enum MAPISTATUS                 retval;
 
1065
                struct nspi_context             *nspi;
 
1066
                struct SPropTagArray            *SPropTagArray = NULL;
 
1067
                struct SRowSet                  *SRowSet;
 
1068
                struct Restriction_r            Filter;
 
1069
                struct SPropValue               *lpProp = NULL;
 
1070
                struct PropertyTagArray_r       *MIds = NULL;
 
1071
                uint32_t                        index = 0;
 
1072
                char                            *password;
 
1073
                struct mapi_session     *session = NULL;
 
1074
 
 
1075
                retval = GetProfileAttr(&profile, "password", &count, &attr_tmp);
 
1076
                OPENCHANGE_RETVAL_IF(retval || !count, MAPI_E_NOT_FOUND, mem_ctx);
 
1077
                password = talloc_strdup(mem_ctx, attr_tmp[0]);
 
1078
                talloc_free(attr_tmp[0]);
 
1079
 
 
1080
                retval = MapiLogonProvider(mapi_ctx, &session, profile_dst, password, PROVIDER_ID_NSPI);
 
1081
                if (retval != MAPI_E_SUCCESS) {
 
1082
                        mapi_errstr("DuplicateProfile", GetLastError());
 
1083
                        return retval;
 
1084
                }
 
1085
                mapi_ctx = session->mapi_ctx;
 
1086
 
 
1087
                OPENCHANGE_RETVAL_IF(!session, MAPI_E_NOT_INITIALIZED, NULL);
 
1088
                OPENCHANGE_RETVAL_IF(!session->nspi->ctx, MAPI_E_END_OF_SESSION, NULL);
 
1089
                OPENCHANGE_RETVAL_IF(!session->mapi_ctx, MAPI_E_NOT_INITIALIZED, NULL);
 
1090
 
 
1091
                mem_ctx = talloc_named(NULL, 0, "ProcessNetworkProfile");
 
1092
                nspi = (struct nspi_context *) session->nspi->ctx;
 
1093
                index = 0;
 
1094
 
 
1095
                SRowSet = talloc_zero(mem_ctx, struct SRowSet);
 
1096
                retval = nspi_GetSpecialTable(nspi, mem_ctx, 0x0, &SRowSet);
 
1097
                MAPIFreeBuffer(SRowSet);
 
1098
                OPENCHANGE_RETVAL_IF(retval, retval, mem_ctx);
 
1099
 
 
1100
                SPropTagArray = set_SPropTagArray(mem_ctx, 0x1,
 
1101
                                                PR_EMAIL_ADDRESS
 
1102
                                                );
 
1103
 
 
1104
                /* Retrieve the username to match */
 
1105
                if (!username) {
 
1106
                        username = cli_credentials_get_username(nspi->cred);
 
1107
                        OPENCHANGE_RETVAL_IF(!username, MAPI_E_INVALID_PARAMETER, mem_ctx);
 
1108
                }
 
1109
 
 
1110
                /* Build the restriction we want for NspiGetMatches */
 
1111
                lpProp = talloc_zero(mem_ctx, struct SPropValue);
 
1112
                lpProp->ulPropTag = PR_ANR_UNICODE;
 
1113
                lpProp->dwAlignPad = 0;
 
1114
                lpProp->value.lpszW = username;
 
1115
 
 
1116
                Filter.rt = (enum RestrictionType_r)RES_PROPERTY;
 
1117
                Filter.res.resProperty.relop = RES_PROPERTY;
 
1118
                Filter.res.resProperty.ulPropTag = PR_ANR_UNICODE;
 
1119
                Filter.res.resProperty.lpProp = lpProp;
 
1120
 
 
1121
                SRowSet = talloc_zero(mem_ctx, struct SRowSet);
 
1122
                MIds = talloc_zero(mem_ctx, struct PropertyTagArray_r);
 
1123
                retval = nspi_GetMatches(nspi, mem_ctx, SPropTagArray, &Filter, 5000, &SRowSet, &MIds);
 
1124
                MAPIFreeBuffer(SPropTagArray);
 
1125
                MAPIFreeBuffer(lpProp);
 
1126
                if (retval != MAPI_E_SUCCESS) {
 
1127
                        MAPIFreeBuffer(MIds);
 
1128
                        MAPIFreeBuffer(SRowSet);
 
1129
                        talloc_free(mem_ctx);
 
1130
                        return retval;
 
1131
                }
 
1132
 
 
1133
                /* if there's no match */
 
1134
                OPENCHANGE_RETVAL_IF(!SRowSet, MAPI_E_NOT_FOUND, mem_ctx);
 
1135
                OPENCHANGE_RETVAL_IF(!SRowSet->cRows, MAPI_E_NOT_FOUND, mem_ctx);
 
1136
                OPENCHANGE_RETVAL_IF(!MIds, MAPI_E_NOT_FOUND, mem_ctx);
 
1137
                MAPIFreeBuffer(MIds);
 
1138
 
 
1139
                set_profile_attribute(mapi_ctx, profile_dst, *SRowSet, index, PR_EMAIL_ADDRESS, "EmailAddress");
 
1140
                mapi_profile_delete_string_attr(mapi_ctx, profile_dst, "EmailAddress", oldEmailAddress);
 
1141
                MAPIFreeBuffer(SRowSet);
1071
1142
        }
1072
1143
 
1073
1144
        /* Change ProxyAddress */
1196
1267
        OPENCHANGE_RETVAL_IF(!mapi_ctx->ldb_ctx, MAPI_E_NOT_INITIALIZED, NULL);
1197
1268
        OPENCHANGE_RETVAL_IF(!profname, MAPI_E_INVALID_PARAMETER, NULL);
1198
1269
 
1199
 
        mem_ctx = talloc_named(NULL, 0, "SetDefaultProfile");
 
1270
        mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "SetDefaultProfile");
1200
1271
 
1201
1272
        /* open profile */
1202
1273
        retval = ldb_load_profile(mem_ctx, mapi_ctx->ldb_ctx, &profile, profname, NULL);
1299
1370
        OPENCHANGE_RETVAL_IF(!mapi_ctx, MAPI_E_NOT_INITIALIZED, NULL);
1300
1371
 
1301
1372
        ldb_ctx = mapi_ctx->ldb_ctx;
1302
 
        mem_ctx = talloc_autofree_context();
 
1373
        mem_ctx = mapi_ctx->mem_ctx;
1303
1374
 
1304
1375
        basedn = ldb_dn_new(ldb_ctx, ldb_ctx, "CN=Profiles");
1305
1376
        ret = ldb_search(ldb_ctx, mem_ctx, &res, basedn, scope, attrs, "(cn=*)");
1448
1519
        basedn = ldb_dn_new(ldb_ctx, ldb_ctx, "CN=Profiles");
1449
1520
 
1450
1521
        ret = ldb_search(ldb_ctx, mem_ctx, &res, basedn, LDB_SCOPE_SUBTREE, attrs, "(CN=%s)", profile->profname);
1451
 
        OPENCHANGE_RETVAL_IF(ret != LDB_SUCCESS, MAPI_E_NOT_FOUND, NULL);
1452
 
        OPENCHANGE_RETVAL_IF(!res->count, MAPI_E_NOT_FOUND, NULL);
 
1522
        OPENCHANGE_RETVAL_IF(ret != LDB_SUCCESS, MAPI_E_NOT_FOUND, res);
 
1523
        OPENCHANGE_RETVAL_IF(!res->count, MAPI_E_NOT_FOUND, res);
1453
1524
 
1454
1525
        msg = res->msgs[0];
1455
1526
        ldb_element = ldb_msg_find_element(msg, attribute);
1456
 
        OPENCHANGE_RETVAL_IF(!ldb_element, MAPI_E_NOT_FOUND, NULL);
 
1527
        OPENCHANGE_RETVAL_IF(!ldb_element, MAPI_E_NOT_FOUND, res);
1457
1528
 
1458
1529
        val.data = (uint8_t *)talloc_strdup(mem_ctx, value);
1459
1530
        val.length = strlen(value);
1460
 
        OPENCHANGE_RETVAL_IF(!ldb_msg_find_val(ldb_element, &val), MAPI_E_NOT_FOUND, NULL);
 
1531
        OPENCHANGE_RETVAL_IF(!ldb_msg_find_val(ldb_element, &val), MAPI_E_NOT_FOUND, res);
1461
1532
 
 
1533
        talloc_free(res);
1462
1534
        return MAPI_E_SUCCESS;
1463
1535
}
1464
1536
 
1587
1659
 
1588
1660
        mapi_ctx = session->mapi_ctx;
1589
1661
 
1590
 
        mem_ctx = talloc_named(NULL, 0, "ProcessNetworkProfile");
 
1662
        mem_ctx = talloc_named(session, 0, "ProcessNetworkProfile");
1591
1663
        nspi = (struct nspi_context *) session->nspi->ctx;
1592
1664
        profname = session->profile->profname;
1593
1665
        index = 0;
1631
1703
 
1632
1704
        SRowSet = talloc_zero(mem_ctx, struct SRowSet);
1633
1705
        MIds = talloc_zero(mem_ctx, struct PropertyTagArray_r);
1634
 
        retval = nspi_GetMatches(nspi, mem_ctx, SPropTagArray, &Filter, &SRowSet, &MIds);
 
1706
        retval = nspi_GetMatches(nspi, mem_ctx, SPropTagArray, &Filter, 5000, &SRowSet, &MIds);
1635
1707
        MAPIFreeBuffer(SPropTagArray);
1636
1708
        MAPIFreeBuffer(lpProp);
1637
1709
        if (retval != MAPI_E_SUCCESS) {