Merge from vendor branch TNF:
[pkgsrcv2.git] / www / lynx / patches.v6 / patch-ab
1 $NetBSD: patch-ab,v 1.1 2000/01/15 17:44:20 hubertf Exp $
2
3 diff -x *.orig -urN ./WWW/Library/Implementation/HTAAFile.c /usr/pkgsrc/www/lynx/work.unpatched/lynx2-8-2/WWW/Library/Implementation/HTAAFile.c
4 --- ./WWW/Library/Implementation/HTAAFile.c     Thu Jan  1 01:00:00 1970
5 +++ /usr/pkgsrc/www/lynx/work.unpatched/lynx2-8-2/WWW/Library/Implementation/HTAAFile.c Sat Jan 15 07:57:17 2000
6 @@ -0,0 +1,203 @@
7 +/* MODULE                                                      HTAAFile.c
8 +**             FILE ROUTINES FOR AUTHENTICATION
9 +**             (PASSWD AND GROUP FILES) AND
10 +**             ACCESS CONTROL LIST (.www_acl)
11 +** AUTHORS:
12 +**     AL      Ari Luotonen    luotonen@dxcern.cern.ch
13 +**
14 +** HISTORY:
15 +**
16 +**
17 +** BUGS:
18 +**
19 +**
20 +*/
21 +
22 +#include <HTUtils.h>
23 +
24 +#include <HTAAUtil.h>          /* Common utilities used in AA */
25 +#include <HTAAFile.h>          /* Implemented here */
26 +
27 +#include <LYLeaks.h>
28 +
29 +#define SPACE                  ' '
30 +#define TAB                    '\t'
31 +
32 +
33 +
34 +/* PUBLIC                                              HTAAFile_nextRec()
35 +**             GO TO THE BEGINNING OF THE NEXT RECORD
36 +** ON ENTRY:
37 +**     fp      is the file from which records are read from.
38 +**
39 +** ON EXIT:
40 +**     returns nothing. File read pointer is located at the beginning
41 +**             of the next record. Handles continuation lines
42 +**             (lines ending in comma indicate a following
43 +**             continuation line).
44 +**
45 +*/
46 +PUBLIC void HTAAFile_nextRec ARGS1(FILE *, fp)
47 +{
48 +    int ch = getc(fp);
49 +    int last = (char)0;
50 +
51 +    do {
52 +       while (ch != EOF  &&  ch != CR  &&  ch != LF) {
53 +           if (ch != ' '  && ch != '\t')
54 +               last = ch;              /* Last non-whitespace */
55 +           ch = getc(fp);              /* Skip until end-of-line */
56 +       }
57 +       while (ch != EOF &&
58 +              (ch == CR  ||  ch == LF))/*Skip carriage returns and linefeeds*/
59 +           ch = getc(fp);
60 +       if (ch != EOF)
61 +           ungetc(ch, fp);
62 +    } while (last == ',' && ch != EOF);        /* Skip also continuation lines */
63 +}
64 +
65 +
66 +/* PRIVATE                                                     read_item()
67 +**             READ AN ITEM FROM A PASSWORD, GROUP
68 +**             OR ACCESS CONTROL LIST FILE
69 +**             i.e. either a field, or a list item.
70 +** ON ENTRY:
71 +**     fp              is the file to read the characters from
72 +**     contents        is the character array to put the characters
73 +**     reading_list    if TRUE, read a list item (ends either in
74 +**                     acomma or acolon),
75 +**                     if FALSE, read a field (ends in acolon).
76 +**     max_len         is the maximum number of characters that may
77 +**                     be read (i.e. the size of dest minus one for
78 +**                     terminating null).
79 +** ON EXIT:
80 +**     returns         the terminating character
81 +**                     (i.e. either separator or CR or LF or EOF).
82 +**     contents        contains a null-terminated string representing
83 +**                     the read field.
84 +** NOTE 1:
85 +**                     Ignores leading and trailing blanks and tabs.
86 +** NOTE 2:
87 +**                     If the item is more than max_len characters
88 +**                     long, the rest of the characters in that item
89 +**                     are ignored.  However, contents is always
90 +**                     null-terminated!
91 +*/
92 +PRIVATE int read_item ARGS4(FILE *,    fp,
93 +                           char *,     contents,
94 +                           BOOL,       reading_list,
95 +                           int,        max_len)
96 +{
97 +    char * dest = contents;
98 +    char * end = contents;
99 +    int cnt = 0;
100 +    int ch = getc(fp);
101 +
102 +    while (SPACE == ch || TAB == ch)   /* Skip spaces and tabs */
103 +       ch = getc(fp);
104 +
105 +    while (ch != FIELD_SEPARATOR &&
106 +          (!reading_list || ch != LIST_SEPARATOR) &&
107 +          ch != CR  &&  ch != LF  &&  ch != EOF  &&  cnt < max_len) {
108 +       *(dest++) = ch;
109 +       cnt++;
110 +       if (ch != SPACE && ch != TAB)
111 +           end = dest;
112 +       ch = getc(fp);
113 +    } /* while not eol or eof or too many read */
114 +
115 +    if (cnt == max_len)        {
116 +       /* If the field was too long (or exactly maximum) ignore the rest */
117 +       while (ch != FIELD_SEPARATOR &&
118 +              (!reading_list || ch != LIST_SEPARATOR) &&
119 +              ch != CR  &&  ch != LF  &&  ch != EOF)
120 +           ch = getc(fp);
121 +    }
122 +
123 +    if (ch == CR || ch == LF)
124 +       ungetc(ch, fp); /* Push back the record separator (NL or LF) */
125 +
126 +    /* Terminate the string, truncating trailing whitespace off.
127 +    ** Otherwise (if whitespace would be included), here would
128 +    ** be *dest='\0'; and  cnt -= ... would be left out.
129 +    */
130 +    *end = '\0';
131 +    cnt -= dest-end;
132 +
133 +    return ch;         /* Return the terminating character */
134 +}
135 +
136 +
137 +
138 +/* PUBLIC                                              HTAAFile_readField()
139 +**             READ A FIELD FROM A PASSWORD, GROUP
140 +**             OR ACCESS CONTROL LIST FILE
141 +**             i.e. an item terminated by colon,
142 +**             end-of-line, or end-of-file. 
143 +** ON ENTRY:
144 +**     fp              is the file to read the characters from
145 +**     contents        is the character array to put the characters
146 +**     max_len         is the maximum number of characters that may
147 +**                     be read (i.e. the size of dest minus one for
148 +**                     terminating null).
149 +** ON EXIT:
150 +**     returns         the terminating character
151 +**                     (i.e. either separator or CR or LF or EOF).
152 +**     contents        contains a null-terminated string representing
153 +**                     the read field.
154 +** NOTE 1:
155 +**                     Ignores leading and trailing blanks and tabs.
156 +** NOTE 2:
157 +**                     If the field is more than max_len characters
158 +**                     long, the rest of the characters in that item
159 +**                     are ignored.  However, contents is always
160 +**                     null-terminated!
161 +*/
162 +PUBLIC int HTAAFile_readField ARGS3(FILE *, fp,
163 +                                   char *, contents,
164 +                                   int,    max_len)
165 +{
166 +    return read_item(fp, contents, NO, max_len);
167 +}
168 +
169 +
170 +
171 +
172 +/* PUBLIC                                              HTAAFile_readList()
173 +**
174 +**                     READ A LIST OF STRINGS SEPARATED BY COMMAS
175 +**                     (FROM A GROUP OR ACCESS CONTROL LIST FILE)
176 +** ON ENTRY:
177 +**     fp              is a pointer to the input file.
178 +**     result          is the list to which append the read items.
179 +**     max_len         is the maximum number of characters in each
180 +**                     list entry (extra characters are ignored).
181 +** ON EXIT:
182 +**     returns         the number of items read.
183 +**
184 +*/
185 +PUBLIC int HTAAFile_readList ARGS3(FILE *,     fp,
186 +                                  HTList *,    result,
187 +                                  int,         max_len)
188 +{
189 +    char *item = NULL;
190 +    int terminator;
191 +    int cnt = 0;
192 +
193 +    do {
194 +       if (!item  &&  !(item = (char*)malloc(max_len+1)))
195 +           outofmem(__FILE__, "HTAAFile_readList");
196 +       terminator = read_item(fp, item, YES, max_len);
197 +       if (strlen(item) > 0) {
198 +           cnt++;
199 +           HTList_addObject(result, (void*)item);
200 +           item = NULL;
201 +       }
202 +    } while (terminator != FIELD_SEPARATOR  &&
203 +            terminator != CR  &&  terminator != LF  &&
204 +            terminator != EOF);
205 +
206 +    FREE(item);        /* This was not needed */
207 +    return cnt;
208 +}
209 +