-
Notifications
You must be signed in to change notification settings - Fork 0
/
Autre.c
332 lines (287 loc) · 6.95 KB
/
Autre.c
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
/*
============================================================================
Name : Autre.c
Author : Xynium
Version :
Copyright : FM4PN JPLathuile
Description : Annexe po wl2k
* from Paclink
============================================================================
*/
#include "Autre.h"
#include <gtk/gtk.h>
// Retrouve le texte du sujet.
// Le nom sous lequel est envoyé le fichier devient le sujet c bizzare
// la reponse est limité a 30char
char * FindSujet(const char *FName)
{
int iCpc;
int iOut;
FILE *fp;
int c;
if ((fp = fopen(FName, "rb")) == NULL) {
return NULL;
}
iCpc=0;iOut=0;
slgnbuffer[29]=0;
while ((c = fgetc(fp)) != EOF) {
slgnbuffer[iCpc++] = c;
if ((c=='\n')||(c=='\r') || (iCpc>28)) {
if (iOut==1){
slgnbuffer[--iCpc]=0;
fclose(fp);
return slgnbuffer;
}
iCpc=0;
}
if (strncmp(slgnbuffer,"Subject: ",9)==0){
iCpc = 0; iOut=1;
}
}
fclose(fp);
return NULL;
}
void compute_secure_login_response(char *challenge, char *response, char *password)
{
char *hash_input;
unsigned char hash_sig[16];
unsigned int m, n;
int i, pr;
char pr_str[20];
m = strlen(challenge) + strlen(password);
n = m + sizeof(sl_salt);
hash_input = (char*)malloc(n);
strcpy(hash_input, challenge);
strcat(hash_input, password);
strupper(hash_input);
memcpy(hash_input+m, sl_salt, sizeof(sl_salt));
md5_buffer(hash_input, n, hash_sig);
free(hash_input);
pr = hash_sig[3] & 0x3f;
for (i=2; i>=0; i--)
pr = (pr << 8) | hash_sig[i];
sprintf(pr_str, "%08d", pr);
n = strlen(pr_str);
if (n > 8)
strcpy(response, pr_str+(n-8));
else
strcpy(response, pr_str);
}
char *strupper(char *s)
{
unsigned char *cp;
if (s == NULL) {
return NULL;
}
for (cp = (unsigned char *) s; *cp; cp++) {
if (islower(*cp)) {
*cp = toupper(*cp);
}
}
return s;
}
struct qzbuffer * buffer_readfile(const char *path)
{
FILE *fp;
int c;
struct qzbuffer *buf;
if ((fp = fopen(path, "rb")) == NULL) {
return NULL;
}
if ((buf = buffer_new()) == NULL) {
fclose(fp);
return NULL;
}
while ((c = fgetc(fp)) != EOF) {
if (buffer_addchar(buf, c) == -1) {
fclose(fp);
buffer_free(buf);
return NULL;
}
}
if (fclose(fp) != 0) {
buffer_free(buf);
return NULL;
}
return buf;
}
struct qzbuffer * buffer_new(void)
{
struct qzbuffer *b;
if ((b = malloc(sizeof(struct qzbuffer))) == NULL) {
return NULL;
}
b->alen = 1;
b->dlen = 0;
b->i = 0;
if ((b->data = malloc(b->alen * sizeof(unsigned char))) == NULL) {
return NULL;
}
return b;
}
int buffer_addchar(struct qzbuffer *b, int c)
{
unsigned char *d;
unsigned long newlen;
if (b->dlen == b->alen) {
newlen = b->alen * 2;
if ((d = realloc(b->data, newlen * sizeof(unsigned char))) == NULL) {
return -1;
}
b->data = d;
b->alen = newlen;
}
b->data[b->dlen++] = (unsigned char) c;
return 0;
}
void buffer_free(struct qzbuffer *b)
{
if (b->data) {
free(b->data);
}
free(b);
}
void buffer_rewind(struct qzbuffer *b)
{
b->i = 0;
}
int buffer_iterchar(struct qzbuffer *b)
{
if (b->i >= b->dlen) {
return EOF;
}
return b->data[b->i++];
}
/*
* envoie le fichier compressé
* dans le cas ou la demande se fait a partir d'un offset offst est non nul
*
*/
int putcompressed(char *titre,long int offst, struct qzbuffer *buf, int *fp)
{
int len;
char title[81];
unsigned char offset[7];
int cksum = 0;
unsigned char *cp;
long rem;
unsigned char msglen;
sprintf(title,"%s",titre);
snprintf((char *) offset, sizeof(offset), "%lu", offst);
len = strlen((const char *) title) + strlen((const char *) offset) + 2;
sprintf(slgnbuffer, "%c%c%s%c%s%c", CHRSOH, len, title, CHRNUL, offset, CHRNUL);
if (send (*fp, slgnbuffer,len+2,MSG_MORE) == -1) return -1; // Send header
rem = (long)buf->dlen;
cp = buf->data;
if (rem < 6) return -2;
cp += offst;
rem -= (long)offst;
if (rem < 0) return -3;
while (rem > 0) {
if (rem > 250) msglen = 250;
else msglen = (unsigned char)rem;
sprintf(slgnbuffer, "%c%c", CHRSTX, msglen) ;
if (send (*fp, slgnbuffer, 2,MSG_MORE) == -1) return -4;
len=0;
while (msglen--) {
cksum = (cksum + *cp) % 256;
slgnbuffer[len++]=*cp++;
rem--;
}
if (send (*fp, slgnbuffer, len,MSG_MORE) == -1) return -5;
}
cksum = -cksum & 0xff; // Send checksum
sprintf(slgnbuffer, "%c%c", CHREOT, cksum) ;
if (send (*fp, slgnbuffer,2,0) == -1) return -6;
return 0;
}
int buffer_writefile(const char *path, struct qzbuffer *buf)
{
FILE *fp;
int c;
if ((fp = fopen(path, "wb")) == NULL) {
return -1;
}
buffer_rewind(buf);
while ((c = buffer_iterchar(buf)) != EOF) {
if (fputc(c, fp) == EOF) {
fclose(fp);
return -1;
}
}
if (fclose(fp) != 0) {
return -1;
}
return 0;
}
// Parse la phrase FC po retrouver la longeur
//et met le nom dans s
int FCLongParse(char *s)
{
gchar ** gsaPart;
int iR;
gsaPart= g_strsplit (s," ",7);
iR= atoi(gsaPart[4]);
strcpy(s,gsaPart[2]);
g_strfreev (gsaPart);
return iR;
}
//Retrouve les preferances
int LitConfig(void)
{
int iq,ir,is,pos;
char sTmpp[20];
FILE *fp;
char c;
char buffer[MAXBUFFLON];
sprintf(buffer,"%s/PNMail/PNMail.conf",getenv("HOME")) ;
if ((fp = fopen(buffer, "r")) == NULL) {
return -1;
}
do { // read all lines in file
pos = 0;
do{ // read one line
c = fgetc(fp);
if(c != EOF) buffer[pos++] = (char)c;
if(pos >= MAXBUFFLON - 1) { // ierreur lecture trop longue
break;
}
}while(c != EOF && c != '\n');
buffer[--pos] = 0;// line is now in buffer
iq=0;
for (ir=0; ir <strlen(buffer);ir++)
{
switch (iq){
case 0: sTmpp[ir]=buffer[ir]; // charge la phrase
if (sTmpp[ir]==':') {
sTmpp[ir-1]=0;
if (strcmp(sTmpp,"CallAdress")==0) iq=1;
if (strcmp(sTmpp,"PassWord")==0) iq=2;
if (strcmp(sTmpp,"Locator")==0) iq=3;
is=0;
}
break;
case 1: sMycall[is++]=buffer[ir]; // charge la phrase
if (buffer[ir]=='@') {
sMycall[--is]=0;
iq=0;
}
break;
case 2: password[is++]=buffer[ir]; // charge la phrase
if (buffer[ir+1]==0) {
password[is]=0;
iq=0;
}
break;
case 3: locator[is++]=buffer[ir]; // charge la phrase
if (buffer[ir+1]==0) {
locator[is]=0;
iq=0;
}
break;
}
}
} while(c != EOF);
fclose(fp);
return 0;
}