2 OpenChange MAPI torture suite implementation.
6 Copyright (C) Julien Kerihuel 2007.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <libmapi/libmapi.h>
23 #include <gen_ndr/ndr_exchange.h>
25 #include <credentials.h>
26 #include <torture/mapi_torture.h>
28 #include <torture/torture_proto.h>
29 #include <samba/popt.h>
31 bool torture_rpc_mapi_permissions(struct torture_context *torture)
34 enum MAPISTATUS retval;
35 struct dcerpc_pipe *p;
37 struct mapi_session *session;
38 mapi_object_t obj_store;
39 mapi_object_t obj_inbox;
40 mapi_object_t obj_table;
42 struct SRowSet SRowSet;
43 struct SPropTagArray *proptags;
45 const char *operation = lp_parm_string(torture->lp_ctx, NULL, "mapi", "operation");
46 const char *role = lp_parm_string(torture->lp_ctx, NULL, "mapi", "role");
48 const char *username = lp_parm_string(torture->lp_ctx, NULL, "mapi", "username");
51 mem_ctx = talloc_init("torture_rpc_mapi_permissions");
52 ntstatus = torture_rpc_connection(torture, &p, &ndr_table_exchange_emsmdb);
53 if (!NT_STATUS_IS_OK(ntstatus)) {
59 if ((session = torture_init_mapi(mem_ctx, torture->lp_ctx)) == NULL) return false;
61 mapi_object_init(&obj_store);
62 retval = OpenMsgStore(session, &obj_store);
63 mapi_errstr("OpenMsgStore", GetLastError());
64 if (retval != MAPI_E_SUCCESS) return false;
66 /* Retrieve the default inbox folder id */
67 retval = GetDefaultFolder(&obj_store, &id_inbox, olFolderInbox);
68 mapi_errstr("GetDefaultFolder", GetLastError());
69 if (retval != MAPI_E_SUCCESS) return false;
71 mapi_object_init(&obj_inbox);
72 retval = OpenFolder(&obj_store, id_inbox, &obj_inbox);
73 mapi_errstr("OpenFolder", GetLastError());
74 if (retval != MAPI_E_SUCCESS) return false;
76 if (!strncasecmp(operation, "add", strlen(operation))) {
77 permission = get_permission_from_name(role);
78 retval = AddUserPermission(&obj_inbox, username, permission);
79 mapi_errstr("AddUserPermission", GetLastError());
80 if (retval != MAPI_E_SUCCESS) return false;
82 if (!strncasecmp(operation, "modify", strlen(operation))) {
83 permission = get_permission_from_name(role);
84 retval = ModifyUserPermission(&obj_inbox, username, permission);
85 mapi_errstr("ModifyUserPermission", GetLastError());
86 if (retval != MAPI_E_SUCCESS) return false;
88 if (!strncasecmp(operation, "remove", strlen(operation))) {
89 retval = RemoveUserPermission(&obj_inbox, username);
90 mapi_errstr("RemoveUserPermission", GetLastError());
91 if (retval != MAPI_E_SUCCESS) return false;
93 if (!strncasecmp(operation, "list", strlen(operation))) {
94 mapi_object_init(&obj_table);
95 retval = GetTable(&obj_inbox, &obj_table);
96 mapi_errstr("GetTable", GetLastError());
97 if (retval != MAPI_E_SUCCESS) return false;
99 proptags = set_SPropTagArray(mem_ctx, 4,
104 retval = SetColumns(&obj_table, proptags);
105 mapi_errstr("SetColumns", GetLastError());
106 MAPIFreeBuffer(proptags);
107 if (retval != MAPI_E_SUCCESS) return false;
109 retval = QueryRows(&obj_table, 0x32, TBL_ADVANCE, &SRowSet);
110 mapi_errstr("QueryRows", GetLastError());
111 if (retval != MAPI_E_SUCCESS) return false;
113 for (i = 0; i < SRowSet.cRows; i++) {
114 struct SPropValue *lpProp;
116 lpProp = get_SPropValue_SRow(&(SRowSet.aRow[i]), PR_MEMBER_NAME);
117 printf(" %-25s: %s\n", "Username", lpProp->value.lpszA ? lpProp->value.lpszA : "Default");
118 lpProp = get_SPropValue_SRow(&(SRowSet.aRow[i]), PR_MEMBER_RIGHTS);
119 ndr_print_debug((ndr_print_fn_t)ndr_print_ACLRIGHTS, "Rights", (void *)lpProp->value.l);
123 mapi_object_release(&obj_table);
125 mapi_object_release(&obj_inbox);
126 mapi_object_release(&obj_store);
129 talloc_free(mem_ctx);