|
0
|
1 |
// Copyright (C) 2000 Bruce Guenter <bruceg@em.ca>
|
|
|
2 |
//
|
|
|
3 |
// This program is free software; you can redistribute it and/or modify
|
|
|
4 |
// it under the terms of the GNU General Public License as published by
|
|
|
5 |
// the Free Software Foundation; either version 2 of the License, or
|
|
|
6 |
// (at your option) any later version.
|
|
|
7 |
//
|
|
|
8 |
// This program is distributed in the hope that it will be useful,
|
|
|
9 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
10 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
11 |
// GNU General Public License for more details.
|
|
|
12 |
//
|
|
|
13 |
// You should have received a copy of the GNU General Public License
|
|
|
14 |
// along with this program; if not, write to the Free Software
|
|
|
15 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
16 |
|
|
|
17 |
#include <config.h>
|
|
|
18 |
#include <ctype.h>
|
|
|
19 |
#include <string.h>
|
|
|
20 |
#include "vpwentry.h"
|
|
|
21 |
#include "vdomain/vdomain.h"
|
|
|
22 |
#include "misc/strtou.h"
|
|
|
23 |
|
|
|
24 |
static const char* from_uint(const char* ptr, unsigned& uint)
|
|
|
25 |
{
|
|
|
26 |
const char* tmp;
|
|
|
27 |
uint = strtou(ptr, &tmp);
|
|
|
28 |
return (*tmp == 0) ? ++tmp : 0;
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
const char* vpwentry::decode_flags(const char* ptr, const char* end)
|
|
|
32 |
{
|
|
|
33 |
while(ptr < end) {
|
|
|
34 |
unsigned flag = *(unsigned char*)ptr++;
|
|
|
35 |
if(!flag)
|
|
|
36 |
return ptr;
|
|
|
37 |
if(ptr >= end)
|
|
|
38 |
return 0;
|
|
|
39 |
bool value = *(unsigned char*)ptr++;
|
|
|
40 |
switch(flag) {
|
|
2
|
41 |
case vdomain::ATTR_HAS_MAILBOX:
|
|
|
42 |
has_mailbox = value;
|
|
|
43 |
break;
|
|
0
|
44 |
case vdomain::ATTR_MAILBOX_ENABLED:
|
|
|
45 |
is_mailbox_enabled = value;
|
|
|
46 |
break;
|
|
|
47 |
default:
|
|
|
48 |
return 0;
|
|
|
49 |
}
|
|
|
50 |
}
|
|
|
51 |
return 0;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
const char* vpwentry::decode_base(const char* ptr, const char* end)
|
|
|
55 |
{
|
|
|
56 |
pass = ptr;
|
|
|
57 |
ptr += pass.length() + 1;
|
|
|
58 |
if(ptr >= end) return 0;
|
|
|
59 |
|
|
2
|
60 |
directory = ptr;
|
|
|
61 |
if(!directory)
|
|
|
62 |
has_mailbox = false;
|
|
|
63 |
ptr += directory.length() + 1;
|
|
0
|
64 |
if(ptr >= end) return 0;
|
|
|
65 |
|
|
|
66 |
const char* start = ptr;
|
|
|
67 |
while(ptr < end && *ptr != 0)
|
|
|
68 |
ptr += strlen(ptr) + 1;
|
|
|
69 |
if(ptr == start)
|
|
|
70 |
forwards = "";
|
|
|
71 |
else
|
|
|
72 |
forwards = mystring(start, ptr-start-1);
|
|
|
73 |
if(ptr++ >= end) return 0;
|
|
|
74 |
|
|
|
75 |
personal = ptr;
|
|
|
76 |
ptr += personal.length() + 1;
|
|
|
77 |
if(ptr >= end) return 0;
|
|
|
78 |
|
|
|
79 |
return ptr;
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
const char* vpwentry::decode_values(const char* ptr, const char* end)
|
|
|
83 |
{
|
|
|
84 |
if((ptr = from_uint(ptr, hardquota)) == 0 || ptr >= end) return 0;
|
|
|
85 |
if((ptr = from_uint(ptr, softquota)) == 0 || ptr >= end) return 0;
|
|
|
86 |
if((ptr = from_uint(ptr, msgsize)) == 0 || ptr >= end) return 0;
|
|
|
87 |
if((ptr = from_uint(ptr, msgcount)) == 0 || ptr >= end) return 0;
|
|
|
88 |
if((ptr = from_uint(ptr, ctime)) == 0 || ptr >= end) return 0;
|
|
|
89 |
if((ptr = from_uint(ptr, expiry)) == 0 || ptr > end) return 0;
|
|
|
90 |
return ptr;
|
|
|
91 |
}
|