if (ret != LDB_SUCCESS) return MAPI_E_NOT_FOUND;
/* profile not found */
- if (!res->count) return MAPI_E_NOT_FOUND;
+ if (!res->count) {
+ talloc_free(res);
+ return MAPI_E_NOT_FOUND;
+ }
+
/* more than one profile */
- if (res->count > 1) return MAPI_E_COLLISION;
+ if (res->count > 1) {
+ talloc_free(res);
+ return MAPI_E_COLLISION;
+ }
/* fills in profile with query result */
msg = res->msgs[0];
- profile->username = ldb_msg_find_attr_as_string(msg, "username", NULL);
- profile->password = password ? password : ldb_msg_find_attr_as_string(msg, "password", NULL);
- profile->workstation = ldb_msg_find_attr_as_string(msg, "workstation", NULL);
- profile->realm = ldb_msg_find_attr_as_string(msg, "realm", NULL);
- profile->domain = ldb_msg_find_attr_as_string(msg, "domain", NULL);
- profile->mailbox = ldb_msg_find_attr_as_string(msg, "EmailAddress", NULL);
- profile->homemdb = ldb_msg_find_attr_as_string(msg, "HomeMDB", NULL);
- profile->localaddr = ldb_msg_find_attr_as_string(msg, "localaddress", NULL);
- profile->server = ldb_msg_find_attr_as_string(msg, "binding", NULL);
+ profile->username = talloc_steal(profile, ldb_msg_find_attr_as_string(msg, "username", NULL));
+ profile->password = password ? password : talloc_steal(profile, ldb_msg_find_attr_as_string(msg, "password", NULL));
+ profile->workstation = talloc_steal(profile, ldb_msg_find_attr_as_string(msg, "workstation", NULL));
+ profile->realm = talloc_steal(profile, ldb_msg_find_attr_as_string(msg, "realm", NULL));
+ profile->domain = talloc_steal(profile, ldb_msg_find_attr_as_string(msg, "domain", NULL));
+ profile->mailbox = talloc_steal(profile, ldb_msg_find_attr_as_string(msg, "EmailAddress", NULL));
+ profile->homemdb = talloc_steal(profile, ldb_msg_find_attr_as_string(msg, "HomeMDB", NULL));
+ profile->localaddr = talloc_steal(profile, ldb_msg_find_attr_as_string(msg, "localaddress", NULL));
+ profile->server = talloc_steal(profile, ldb_msg_find_attr_as_string(msg, "binding", NULL));
profile->seal = ldb_msg_find_attr_as_bool(msg, "seal", false);
- profile->org = ldb_msg_find_attr_as_string(msg, "Organization", NULL);
- profile->ou = ldb_msg_find_attr_as_string(msg, "OrganizationUnit", NULL);
+ profile->org = talloc_steal(profile, ldb_msg_find_attr_as_string(msg, "Organization", NULL));
+ profile->ou = talloc_steal(profile, ldb_msg_find_attr_as_string(msg, "OrganizationUnit", NULL));
profile->codepage = ldb_msg_find_attr_as_int(msg, "codepage", 0);
profile->language = ldb_msg_find_attr_as_int(msg, "language", 0);
profile->method = ldb_msg_find_attr_as_int(msg, "method", 0);
profile->exchange_version = ldb_msg_find_attr_as_int(msg, "exchange_version", 0);
- profile->kerberos = ldb_msg_find_attr_as_string(msg, "kerberos", NULL);
+ profile->kerberos = talloc_steal(profile, ldb_msg_find_attr_as_string(msg, "kerberos", NULL));
+
+ talloc_free(res);
return MAPI_E_SUCCESS;
}
\return MAPI_E_SUCCESS on success, otherwise MAPI error.
- \note Developers may also call GetLastError() to retrieve the last
+ \note profile must be talloced because it used as talloc subcontext for
+ data members.
+ Developers may also call GetLastError() to retrieve the last
MAPI error code. Possible MAPI error codes are:
- MAPI_E_NOT_ENOUGH_RESOURCES: ldb subsystem initialization failed
- MAPI_E_NOT_FOUND: the profile was not found in the profile
char *username_src = NULL;
char *ProxyAddress = NULL;
char *oldEmailAddress = NULL;
- struct mapi_profile profile;
+ struct mapi_profile *profile;
char **attr_tmp = NULL;
char *tmp = NULL;
char *attr;
OPENCHANGE_RETVAL_IF(!profile_dst, MAPI_E_INVALID_PARAMETER, NULL);
OPENCHANGE_RETVAL_IF(!username, MAPI_E_INVALID_PARAMETER, NULL);
+ mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "DuplicateProfile");
+ profile = talloc(mem_ctx, struct mapi_profile);
+
/* Step 1. Copy the profile */
retval = CopyProfile(mapi_ctx, profile_src, profile_dst);
OPENCHANGE_RETVAL_IF(retval, retval, NULL);
/* retrieve username, EmailAddress and ProxyAddress */
- retval = OpenProfile(mapi_ctx, &profile, profile_src, NULL);
+ retval = OpenProfile(mapi_ctx, profile, profile_src, NULL);
OPENCHANGE_RETVAL_IF(retval, MAPI_E_NOT_FOUND, NULL);
- mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "DuplicateProfile");
- retval = GetProfileAttr(&profile, "username", &count, &attr_tmp);
+ retval = GetProfileAttr(profile, "username", &count, &attr_tmp);
OPENCHANGE_RETVAL_IF(retval || !count, MAPI_E_NOT_FOUND, mem_ctx);
username_src = talloc_strdup(mem_ctx, attr_tmp[0]);
talloc_free(attr_tmp[0]);
- retval = GetProfileAttr(&profile, "EmailAddress", &count, &attr_tmp);
+ retval = GetProfileAttr(profile, "EmailAddress", &count, &attr_tmp);
OPENCHANGE_RETVAL_IF(retval, MAPI_E_NOT_FOUND, mem_ctx);
oldEmailAddress = talloc_strdup(mem_ctx, attr_tmp[0]);
talloc_free(attr_tmp[0]);
- retval = GetProfileAttr(&profile, "ProxyAddress", &count, &attr_tmp);
+ retval = GetProfileAttr(profile, "ProxyAddress", &count, &attr_tmp);
OPENCHANGE_RETVAL_IF(retval, MAPI_E_NOT_FOUND, mem_ctx);
ProxyAddress = talloc_strdup(mem_ctx, attr_tmp[0]);
talloc_free(attr_tmp[0]);
char *password;
struct mapi_session *session = NULL;
- retval = GetProfileAttr(&profile, "password", &count, &attr_tmp);
+ retval = GetProfileAttr(profile, "password", &count, &attr_tmp);
OPENCHANGE_RETVAL_IF(retval || !count, MAPI_E_NOT_FOUND, mem_ctx);
password = talloc_strdup(mem_ctx, attr_tmp[0]);
talloc_free(attr_tmp[0]);
mapi_profile_modify_string_attr(mapi_ctx, profile_dst, "DisplayName", username);
mapi_profile_modify_string_attr(mapi_ctx, profile_dst, "Account", username);
+ talloc_free(profile);
talloc_free(mem_ctx);
return MAPI_E_SUCCESS;
{
TALLOC_CTX *mem_ctx;
enum MAPISTATUS retval;
- struct mapi_profile profile;
+ struct mapi_profile *profile;
char *profname;
char *exchange_version = NULL;
mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "mapiprofile_dump");
+ profile = talloc(mem_ctx, struct mapi_profile);
if (!opt_profname) {
if ((retval = GetDefaultProfile(mapi_ctx, &profname)) != MAPI_E_SUCCESS) {
profname = talloc_strdup(mem_ctx, (const char *)opt_profname);
}
- retval = OpenProfile(mapi_ctx, &profile, profname, NULL);
+ retval = OpenProfile(mapi_ctx, profile, profname, NULL);
talloc_free(profname);
if (retval && (retval != MAPI_E_INVALID_PARAMETER)) {
exit (1);
}
- switch (profile.exchange_version) {
+ switch (profile->exchange_version) {
case 0x0:
exchange_version = talloc_strdup(mem_ctx, "exchange 2000");
break;
goto end;
}
- printf("Profile: %s\n", profile.profname);
+ printf("Profile: %s\n", profile->profname);
printf("\texchange server == %s\n", exchange_version);
- printf("\tencryption == %s\n", (profile.seal == true) ? "yes" : "no");
- printf("\tusername == %s\n", profile.username);
- printf("\tpassword == %s\n", profile.password);
- printf("\tmailbox == %s\n", profile.mailbox);
- printf("\tworkstation == %s\n", profile.workstation);
- printf("\tdomain == %s\n", profile.domain);
- printf("\tserver == %s\n", profile.server);
+ printf("\tencryption == %s\n", (profile->seal == true) ? "yes" : "no");
+ printf("\tusername == %s\n", profile->username);
+ printf("\tpassword == %s\n", profile->password);
+ printf("\tmailbox == %s\n", profile->mailbox);
+ printf("\tworkstation == %s\n", profile->workstation);
+ printf("\tdomain == %s\n", profile->domain);
+ printf("\tserver == %s\n", profile->server);
end:
talloc_free(mem_ctx);
{
TALLOC_CTX *mem_ctx;
enum MAPISTATUS retval;
- struct mapi_profile profile;
+ struct mapi_profile *profile;
char *profname = NULL;
char **value = NULL;
unsigned int count = 0;
unsigned int i;
mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "mapiprofile_attribute");
+ profile = talloc(mem_ctx, struct mapi_profile);
if (!opt_profname) {
if ((retval = GetDefaultProfile(mapi_ctx, &profname)) != MAPI_E_SUCCESS) {
profname = talloc_strdup(mem_ctx, (const char *)opt_profname);
}
- retval = OpenProfile(mapi_ctx, &profile, profname, NULL);
+ retval = OpenProfile(mapi_ctx, profile, profname, NULL);
if (retval && (retval != MAPI_E_INVALID_PARAMETER)) {
mapi_errstr("OpenProfile", retval);
talloc_free(profname);
exit (1);
}
- if ((retval = GetProfileAttr(&profile, attribute, &count, &value))) {
+ if ((retval = GetProfileAttr(profile, attribute, &count, &value))) {
mapi_errstr("ProfileGetAttr", retval);
talloc_free(profname);
talloc_free(mem_ctx);