2 OpenChange MAPI torture suite implementation.
4 Send appointments to an Exchange server
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>
33 #define DATE_FORMAT "%Y-%m-%d %H:%M:%S"
37 bool torture_rpc_mapi_sendappointment(struct torture_context *torture)
40 enum MAPISTATUS retval;
41 struct dcerpc_pipe *p;
44 const char *appointment = lp_parm_string(torture->lp_ctx, NULL, "mapi", "appointment");
45 const char *body = lp_parm_string(torture->lp_ctx, NULL, "mapi", "body");
46 const char *location = lp_parm_string(torture->lp_ctx, NULL, "mapi", "location");
47 const char *start = lp_parm_string(torture->lp_ctx, NULL, "mapi", "start");
48 const char *end = lp_parm_string(torture->lp_ctx, NULL, "mapi", "end");
49 uint32_t busy_status = lp_parm_int(torture->lp_ctx, NULL, "mapi", "busystatus", 0);
50 uint32_t label = lp_parm_int(torture->lp_ctx, NULL, "mapi", "label", 0);
51 struct mapi_session *session;
53 mapi_object_t obj_store;
54 mapi_object_t obj_calendar;
55 mapi_object_t obj_message;
56 struct SPropValue props[CN_PROPS];
57 struct mapi_nameid *nameid;
58 struct SPropTagArray *SPropTagArray;
61 struct FILETIME *start_date;
62 struct FILETIME *end_date;
66 if (!appointment) return false;
67 if (busy_status > 3) return false;
68 if (!start || !end) return false;
71 mem_ctx = talloc_init("torture_rpc_mapi_sendappointment");
72 nt_status = torture_rpc_connection(torture, &p, &ndr_table_exchange_emsmdb);
73 if (!NT_STATUS_IS_OK(nt_status)) {
79 if ((session = torture_init_mapi(mem_ctx, torture->lp_ctx)) == NULL) return false;
82 mapi_object_init(&obj_store);
83 mapi_object_init(&obj_calendar);
85 /* session::OpenMsgStore */
86 retval = OpenMsgStore(session, &obj_store);
87 mapi_errstr("OpenMsgStore", GetLastError());
88 if (retval != MAPI_E_SUCCESS) return false;
90 retval = GetDefaultFolder(&obj_store, &id_calendar, olFolderCalendar);
91 mapi_errstr("GetDefaultFolder", GetLastError());
92 if (retval != MAPI_E_SUCCESS) return false;
94 /* We now open the calendar folder */
95 retval = OpenFolder(&obj_store, id_calendar, &obj_calendar);
96 mapi_errstr("OpenFolder", GetLastError());
97 if (retval != MAPI_E_SUCCESS) return false;
99 /* Operations on the calendar folder */
100 retval = CreateMessage(&obj_calendar, &obj_message);
101 mapi_errstr("CreateMessage", GetLastError());
102 if (retval != MAPI_E_SUCCESS) return false;
104 /* Build the list of named properties we want to set */
105 nameid = mapi_nameid_new(mem_ctx);
106 mapi_nameid_OOM_add(nameid, "Location", PSETID_Appointment);
107 mapi_nameid_OOM_add(nameid, "BusyStatus", PSETID_Appointment);
108 mapi_nameid_OOM_add(nameid, "ApptStateFlags", PSETID_Appointment);
109 mapi_nameid_OOM_add(nameid, "CommonStart", PSETID_Common);
110 mapi_nameid_OOM_add(nameid, "CommonEnd", PSETID_Common);
111 mapi_nameid_OOM_add(nameid, "Label", PSETID_Appointment);
112 mapi_nameid_OOM_add(nameid, "ReminderDelta", PSETID_Common);
114 /* GetIDsFromNames and map property types */
115 SPropTagArray = talloc_zero(mem_ctx, struct SPropTagArray);
116 retval = GetIDsFromNames(&obj_calendar, nameid->count,
117 nameid->nameid, 0, &SPropTagArray);
118 if (retval != MAPI_E_SUCCESS) return false;
119 mapi_nameid_SPropTagArray(nameid, SPropTagArray);
120 MAPIFreeBuffer(nameid);
122 if (!strptime(start, DATE_FORMAT, &tm)) {
123 printf("Invalid date format: yyyy-mm-dd hh:mm:ss (e.g.: 2007-09-17 10:00:00)\n");
126 unix_to_nt_time(&nt, mktime(&tm));
127 start_date = talloc(mem_ctx, struct FILETIME);
128 start_date->dwLowDateTime = (nt << 32) >> 32;
129 start_date->dwHighDateTime = (nt >> 32);
131 if (!strptime(end, DATE_FORMAT, &tm)) {
132 printf("Invalid date format: yyyy-mm-dd hh:mm:ss (e.g.:2007-09-17 18:30:00)\n");
135 unix_to_nt_time(&nt, mktime(&tm));
136 end_date = talloc(mem_ctx, struct FILETIME);
137 end_date->dwLowDateTime = (nt << 32) >> 32;
138 end_date->dwHighDateTime = (nt >> 32);
140 set_SPropValue_proptag(&props[0], PR_CONVERSATION_TOPIC,
141 (const void *) appointment);
142 set_SPropValue_proptag(&props[1], PR_NORMALIZED_SUBJECT,
143 (const void *) appointment);
144 set_SPropValue_proptag(&props[2], PR_START_DATE, (const void *) start_date);
145 set_SPropValue_proptag(&props[3], PR_END_DATE, (const void *) end_date);
146 set_SPropValue_proptag(&props[4], PR_MESSAGE_CLASS, (const void *)"IPM.Appointment");
148 set_SPropValue_proptag(&props[5], PR_MESSAGE_FLAGS, (const void *) &flag);
149 set_SPropValue_proptag(&props[6], SPropTagArray->aulPropTag[0], (const void *)(location?location:""));
150 set_SPropValue_proptag(&props[7], SPropTagArray->aulPropTag[1], (const void *) &busy_status);
151 flag= MEETING_STATUS_NONMEETING;
152 set_SPropValue_proptag(&props[8], SPropTagArray->aulPropTag[2], (const void *) &flag);
154 set_SPropValue_proptag(&props[9], SPropTagArray->aulPropTag[3], (const void *) start_date);
155 set_SPropValue_proptag(&props[10], SPropTagArray->aulPropTag[4], (const void *) end_date);
156 set_SPropValue_proptag(&props[11], SPropTagArray->aulPropTag[5], (const void *)&label);
158 set_SPropValue_proptag(&props[12], SPropTagArray->aulPropTag[6], (const void *)&flag);
159 set_SPropValue_proptag(&props[13], PR_BODY, (const void *)(body?body:""));
160 retval = SetProps(&obj_message, props, CN_PROPS);
161 mapi_errstr("SetProps", GetLastError());
162 MAPIFreeBuffer(SPropTagArray);
163 if (retval != MAPI_E_SUCCESS) return false;
166 retval = SaveChangesMessage(&obj_calendar, &obj_message, KeepOpenReadOnly);
167 mapi_errstr("SaveChangesMessage", GetLastError());
168 if (retval != MAPI_E_SUCCESS) return false;
171 mapi_object_release(&obj_calendar);
172 mapi_object_release(&obj_store);
177 talloc_free(mem_ctx);