1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
|
--- mstore/mstore.c.orig Mon Mar 27 06:07:12 2000
+++ mstore/mstore.c Tue Dec 11 08:56:58 2001
@@ -1,4 +1,4 @@
-/* $Id: mstore.c,v 1.11 2000/03/27 04:07:12 zircote Exp $ */
+/* $Id: mstore.c,v 1.21 2001/05/07 17:37:10 chuck Exp $ */
#include <stdlib.h>
#include <string.h>
@@ -6,26 +6,33 @@
#include <pwd.h>
#include <unistd.h>
#include <crypt.h>
+
+#ifdef USE_PAM
+#include <security/pam_appl.h>
+#endif /* USE_PAM */
+
#include "mcal.h"
#include "mstore.h"
#include "icap/icaproutines.h"
-
#define MSTORE_VER "0.5"
#define DATA_T struct mstore_data
#define DATA ((DATA_T*) stream->data)
-
+/* mpasswd path define */
+#ifndef MPASSWD_PATH
+#define MPASSWD_PATH "/etc/mpasswd"
+#endif
static void mstore_freestream(CALSTREAM *stream);
static bool mstore_validuser(const char *username,const char *password);
-static bool mstore_userexists(const char *username);
static bool mstore_valid(const CALADDR *addr);
static CALSTREAM* mstore_open( CALSTREAM *stream,
const CALADDR *addr, long options);
static CALSTREAM* mstore_close(CALSTREAM *stream, long options);
static bool mstore_ping(CALSTREAM *stream);
+static bool mstore_create (CALSTREAM *stream, const char *calendar);
static bool mstore_search_range( CALSTREAM *stream,
const datetime_t *start,
const datetime_t *end);
@@ -44,12 +51,18 @@
unsigned long id);
static bool mstore_store( CALSTREAM *stream,
const CALEVENT *modified_event);
+static bool mstore_delete( CALSTREAM *stream,
+ char *calendar);
+static bool mstore_rename( CALSTREAM *stream,
+ char *src,char *dest);
+
CALDRIVER mstore_driver =
{
mstore_valid,
mstore_open,
mstore_close,
mstore_ping,
+ mstore_create,
mstore_search_range,
mstore_search_alarm,
mstore_fetch,
@@ -57,6 +70,8 @@
mstore_remove,
mstore_snooze,
mstore_store,
+ mstore_delete,
+ mstore_rename
};
@@ -88,13 +103,98 @@
}
+#ifdef USE_PAM
+
+/* PAM support stuff goes here */
+
+static pam_handle_t *pamh = NULL;
+static char *PAM_username;
+static char *PAM_password;
+
+#define COPY_STRING(s) (s) ? strdup(s) : NULL
+
+static int PAM_conv (int num_msg,
+ const struct pam_message **msg,
+ struct pam_response **resp,
+ void *appdata_ptr)
+{
+ struct pam_response *reply;
+ int count;
+
+ if (num_msg < 1)
+ return PAM_CONV_ERR;
+
+ reply = (struct pam_response *)
+ calloc (num_msg, sizeof(struct pam_response));
+
+ if (!reply)
+ return PAM_CONV_ERR;
+
+ for (count=0; count<num_msg; count++) {
+ char *string = NULL;
+
+ switch (msg[count]->msg_style) {
+ case PAM_PROMPT_ECHO_ON:
+ if (!(string = COPY_STRING(PAM_username)))
+ goto pam_fail_conv;
+ break;
+ case PAM_PROMPT_ECHO_OFF:
+ if (!(string = COPY_STRING(PAM_password)))
+ goto pam_fail_conv;
+ break;
+ case PAM_TEXT_INFO:
+#ifdef PAM_BINARY_PROMPT
+ case PAM_BINARY_PROMPT:
+#endif /* PAM_BINARY_PROMPT */
+ /* ignore it */
+ break;
+ case PAM_ERROR_MSG:
+ default:
+ goto pam_fail_conv;
+ } /* end switch msg[count]->msg_style */
+
+ if (string) {
+ reply[count].resp_retcode = 0;
+ reply[count].resp = string;
+ string = NULL;
+ } /* end if string */
+
+ } // end for count
+
+ *resp = reply;
+ return PAM_SUCCESS;
+
+pam_fail_conv:
+ for(count=0; count<num_msg; count++) {
+ if (!reply[count].resp)
+ continue;
+ switch (msg[count]->msg_style) {
+ case PAM_PROMPT_ECHO_ON:
+ case PAM_PROMPT_ECHO_OFF:
+ free(reply[count].resp);
+ break;
+ } /* end switch msg[count]->msg_style */
+ } /* end for count */
+
+ free(reply);
+ return PAM_CONV_ERR;
+} /* end function static int PAM_conv (...) */
+
+static struct pam_conv PAM_conversation = {
+ &PAM_conv,
+ NULL
+};
+
+#endif /* USE_PAM */
+
bool
mstore_validuser(const char *username,const char *password)
{
+#ifndef USE_PAM
FILE *mpasswd;
char line[1000];
char *musername,*mpassword;
- mpasswd=fopen("/etc/mpasswd","r");
+ mpasswd=fopen(MPASSWD_PATH,"r");
if(!mpasswd)
{
printf("Error! couldn't open mpasswd file!\n");
@@ -123,36 +223,31 @@
}
fclose(mpasswd);
return false;
-}
-
-
-bool
-mstore_userexists(const char *username)
-{
- FILE *mpasswd;
- char line[1000];
- char *musername,*mpassword;
- mpasswd=fopen("/etc/mpasswd","r");
- if(!mpasswd)
- {
- printf("Error! couldn't open mpasswd file!\n");
- exit(1);
- }
- while(fgets(line,900,mpasswd))
- {
- if(line[strlen(line)-1]=='\n') line[strlen(line)-1]=0x00;
- musername=line;
- mpassword=strchr(line,':');
- *mpassword=0x00;
- mpassword++;
- if(!strcmp(username,musername))
- {
- fclose(mpasswd);
- return true;
- }
- }
- fclose(mpasswd);
- return false;
+#else
+ /* PAM authentication */
+ int PAM_error;
+
+ PAM_error = pam_start("mstore", username, &PAM_conversation, &pamh);
+ if (PAM_error != PAM_SUCCESS)
+ goto login_err;
+ pam_set_item(pamh, PAM_TTY, "mstore");
+ pam_set_item(pamh, PAM_RHOST, "localhost");
+ PAM_error = pam_authenticate(pamh, 0);
+ if (PAM_error != PAM_SUCCESS)
+ if (PAM_error == PAM_MAXTRIES)
+ goto login_err;
+#ifndef PAM_CRED_ESTABLISH
+#define PAM_CRED_ESTABLISH PAM_ESTABLISH_CRED
+#endif /* PAM_CRED_ESTABLISH */
+ PAM_error = pam_setcred(pamh, PAM_CRED_ESTABLISH);
+ if (PAM_error != PAM_SUCCESS)
+ goto login_err;
+
+login_err:
+ pam_end(pamh, PAM_error);
+ pamh = NULL;
+ return false;
+#endif /* ! USE_PAM */
}
@@ -161,8 +256,6 @@
{
if (!addr->proto || strcasecmp(addr->proto, "mstore"))
return false;
- if (addr->user && !mstore_userexists(addr->user))
- return false;
return true;
}
@@ -197,10 +290,18 @@
}
cc_login(&username, &password);
- if (username == NULL)
+ if (username == NULL) {
+ #ifdef DEBUG
+ printf("\nNULL username\n");
+ #endif
goto fail;
- if (!mstore_validuser(username,password))
+ }
+ if (!mstore_validuser(username,password)) {
+ #ifdef DEBUG
+ printf("\n!mstore_validuser(%s,%s)\n",username,password);
+ #endif
goto fail;
+ }
}
if (!reopen) {
@@ -212,13 +313,23 @@
if (options & CAL_LOGIN) {
/* Copy login_userbuf, folder. */
- if ((DATA->login_userbuf = strdup(username)) == NULL)
+ if ((DATA->login_userbuf = strdup(username)) == NULL) {
+ #ifdef DEBUG
+ printf("\ncouldn't get login_userbuf (%s)\n",
+ username);
+ #endif
goto fail;
+ }
}
- if ((DATA->folder = strdup(addr->folder)) == NULL)
+ if ((DATA->folder = strdup(addr->folder)) == NULL) {
+ #ifdef DEBUG
+ printf("\ncouldn't get folder (%s)\n",
+ addr->folder);
+ #endif
goto fail;
+ }
/* Set up folder_user */
if(addr->host)
@@ -229,8 +340,13 @@
DATA->login_user=DATA->login_userbuf;
if (addr->user) {
/* Copy and split folder_userbuf */
- if ((DATA->folder_userbuf = strdup(addr->user)) == NULL)
+ if ((DATA->folder_userbuf = strdup(addr->user)) == NULL) {
+#ifdef DEBUG
+ printf("\ncouldn't get folder_userbuf (%s)\n",
+ addr->user);
+#endif
goto fail;
+ }
/* Check for identical folder/login users. */
DATA->folder_user=DATA->folder_userbuf;
if ( !strcmp(DATA->login_user, DATA->folder_user))
@@ -246,7 +362,6 @@
DATA->folder_user = DATA->login_user;
}
-
return stream;
fail:
mstore_freestream(stream);
@@ -270,6 +385,36 @@
}
+bool
+mstore_create(CALSTREAM *stream, const char *calendar)
+{
+ FILE *calfile;
+ char userpath[1000];
+
+ /*
+ if (!(stream = mstore_open (stream, (const CALADDR *)calendar, 0))) {
+ #ifdef DEBUG
+ printf("Error! couldn't open calendar stream!\n");
+ #endif
+ return false;
+ }
+ */
+ snprintf(userpath, 900, "%s/%s", DATA->base_path, calendar);
+ #ifdef DEBUG
+ printf("attempting fopen on calendar file '%s'\n", userpath);
+ #endif
+ calfile = fopen (userpath, "w");
+ if (!calfile) {
+ #ifdef DEBUG
+ printf("Error! couldn't create calendar file!\n");
+ #endif
+ return false;
+ }
+ fclose (calfile);
+ return true;
+}
+
+
CALEVENT *read_event(FILE *calfile)
{
char line[100];
@@ -277,7 +422,8 @@
int size;
CALEVENT *event;
- fgets(line, sizeof(line), calfile);
+ if (fgets(line, sizeof(line), calfile) == NULL)
+ return NULL;
if (sscanf(line, "%d", &size) != 1)
return NULL;
buf = malloc(size + 2);
@@ -334,17 +480,18 @@
datetime_t _end = DT_INIT;
FILE *calfile;
char userpath[1000];
- snprintf(userpath,900,"%s/%s",DATA->base_path,DATA->folder_user);
- calfile=fopen (userpath,"a+");
- if(!calfile)
- {
+
+ snprintf(userpath, 900, "%s/%s", DATA->base_path, DATA->folder_user);
+ calfile = fopen (userpath, "a+");
+ if(!calfile) {
printf("Error! couldn't open calendar file!\n");
exit(1);
- }
+ }
rewind(calfile);
if (start) {
if (!dt_hasdate(start))
+//LM:should this be _start = NULL? and again below for end?
start = NULL;
else {
dt_setdate(&_start,
@@ -358,7 +505,7 @@
dt_setdate(&_end, end->year, end->mon, end->mday);
}
- while((event=read_event(calfile))) {
+ while((event = read_event(calfile))) {
datetime_t clamp = DT_INIT;
if (!start)
@@ -385,28 +532,24 @@
bool
mstore_search_alarm(CALSTREAM *stream, const datetime_t *when)
{
- datetime_t start;
- datetime_t end;
- long alarm = 0;
- unsigned long id = 0;
CALEVENT *event;
FILE *calfile;
char userpath[1000];
- snprintf(userpath,900,"%s/%s",DATA->base_path,DATA->folder_user);
- calfile=fopen (userpath,"a+");
- if(!calfile)
- {
+ snprintf(userpath, 900, "%s/%s", DATA->base_path, DATA->folder_user);
+ calfile=fopen (userpath, "a+");
+ if(!calfile) {
printf("Error! couldn't open calendar file!\n");
exit(1);
- }
+ }
rewind(calfile);
- while((event=read_event(calfile))) {
- if (dt_roll_time(&(event->start), 0, -alarm, 0) &&
- dt_compare(&(event->start),&start)<=0 &&
- dt_compare(&end,&(event->end)) <=0)
+ while ((event = read_event(calfile))) {
+ if (event->alarm &&
+ dt_roll_time(&(event->start), 0, -(event->alarm), 0) &&
+ dt_compare(&(event->start), when) <= 0 &&
+ dt_compare(when, &(event->end)) <=0)
{
- cc_searched(id);
+ cc_searched(event->id);
}
calevent_free(event);
}
@@ -422,13 +565,12 @@
FILE *calfile;
char userpath[1000];
- snprintf(userpath,900,"%s/%s",DATA->base_path,DATA->folder_user);
- calfile=fopen (userpath,"a+");
- if(!calfile)
- {
+ snprintf(userpath, 900, "%s/%s", DATA->base_path, DATA->folder_user);
+ calfile = fopen (userpath,"a+");
+ if(!calfile) {
printf("Error! couldn't open calendar file!\n");
exit(1);
- }
+ }
rewind(calfile);
while((event=read_event(calfile))) {
if(event->id==id) {
@@ -459,8 +601,11 @@
if (strcasecmp(addr->folder, "INBOX"))
return false;
+ /* comment this out so that we can share calendars
if (DATA->folder_userbuf)
return false;
+ */
+
if (!dt_hasdate(&event->start))
return false;
@@ -609,3 +754,15 @@
return true;
}
+
+bool
+mstore_delete(CALSTREAM *stream, char *calendar)
+{
+ return true;
+}
+
+bool
+mstore_rename(CALSTREAM *stream, char *src,char *dest)
+{
+ return true;
+}
|