Print this page
10097 indenting fixes in usr/src/{lib,common}
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/pam_modules/authtok_check/packlib.c
+++ new/usr/src/lib/pam_modules/authtok_check/packlib.c
1 1 /*
2 2 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
3 3 * Use is subject to license terms.
4 4 */
5 5
6 6 /*
7 + * Copyright (c) 2018, Joyent, Inc.
8 + */
9 +
10 +/*
7 11 * This program is copyright Alec Muffett 1993. The author disclaims all
8 12 * responsibility or liability with respect to it's usage or its effect
9 13 * upon hardware or computer systems, and maintains copyright as set out
10 14 * in the "LICENCE" document which accompanies distributions of Crack v4.0
11 15 * and upwards.
12 16 */
13 17
14 18 #include "packer.h"
15 19
16 20 void
17 21 PWRemove(char *path)
18 22 {
19 23 char fname[PATH_MAX];
20 24
21 25 (void) snprintf(fname, sizeof (fname), "%s/%s", path,
22 26 DICT_DATABASE_PWI);
23 27 (void) unlink(fname);
24 28 (void) snprintf(fname, sizeof (fname), "%s/%s", path,
25 29 DICT_DATABASE_PWD);
26 30 (void) unlink(fname);
27 31 (void) snprintf(fname, sizeof (fname), "%s/%s", path,
28 32 DICT_DATABASE_HWM);
29 33 (void) unlink(fname);
30 34 }
31 35
32 36 PWDICT *
33 37 PWOpen(char *path, char *mode)
34 38 {
35 39 PWDICT *pdesc;
36 40 char iname[PATH_MAX];
37 41 char dname[PATH_MAX];
38 42 char wname[PATH_MAX];
39 43 int fd_d;
40 44 int fd_i;
41 45 int fd_w;
42 46 FILE *dfp;
43 47 FILE *ifp;
44 48 FILE *wfp;
45 49
46 50 if ((pdesc = calloc(1, sizeof (PWDICT))) == NULL)
47 51 return ((PWDICT *) 0);
48 52
49 53 if (pdesc->header.pih_magic == PIH_MAGIC) {
50 54 return ((PWDICT *) 0);
51 55 }
52 56 (void) memset(pdesc, '\0', sizeof (pdesc));
53 57
54 58 (void) snprintf(iname, sizeof (iname), "%s/%s", path,
55 59 DICT_DATABASE_PWI);
56 60 (void) snprintf(dname, sizeof (dname), "%s/%s", path,
57 61 DICT_DATABASE_PWD);
58 62 (void) snprintf(wname, sizeof (wname), "%s/%s", path,
59 63 DICT_DATABASE_HWM);
60 64
61 65 if ((fd_d = open(dname, O_RDWR|O_CREAT, 0600)) == -1)
62 66 syslog(LOG_ERR, "PWopen: can't open %s: %s", dname,
63 67 strerror(errno));
64 68 if ((fd_i = open(iname, O_RDWR|O_CREAT, 0600)) == -1)
65 69 syslog(LOG_ERR, "PWopen: can't open %s: %s", iname,
66 70 strerror(errno));
67 71 if ((fd_w = open(wname, O_RDWR|O_CREAT, 0600)) == -1)
68 72 syslog(LOG_ERR, "PWopen: can't open %s: %s", wname,
69 73 strerror(errno));
70 74
71 75 if (!(pdesc->dfp = fdopen(fd_d, mode))) {
72 76 return ((PWDICT *) 0);
73 77 }
74 78
75 79 if (!(pdesc->ifp = fdopen(fd_i, mode))) {
76 80 (void) fclose(pdesc->dfp);
77 81 return ((PWDICT *) 0);
78 82 }
79 83
80 84 if (pdesc->wfp = fdopen(fd_w, mode)) {
81 85 pdesc->flags |= PFOR_USEHWMS;
82 86 }
83 87
84 88 ifp = pdesc->ifp;
85 89 dfp = pdesc->dfp;
86 90 wfp = pdesc->wfp;
87 91
88 92 if (mode[0] == 'w') {
89 93 pdesc->flags |= PFOR_WRITE;
90 94 pdesc->header.pih_magic = PIH_MAGIC;
91 95 pdesc->header.pih_blocklen = NUMWORDS;
92 96 pdesc->header.pih_numwords = 0;
93 97
94 98 (void) fwrite((char *)&(pdesc->header), sizeof (pdesc->header),
95 99 1, ifp);
96 100 } else {
97 101 pdesc->flags &= ~PFOR_WRITE;
98 102
99 103 if (!fread((char *)&(pdesc->header), sizeof (pdesc->header),
100 104 1, ifp)) {
101 105 pdesc->header.pih_magic = 0;
102 106 (void) fclose(ifp);
103 107 (void) fclose(dfp);
104 108 return ((PWDICT *) 0);
105 109 }
106 110
107 111 if (pdesc->header.pih_magic != PIH_MAGIC) {
108 112 pdesc->header.pih_magic = 0;
109 113 (void) fclose(ifp);
110 114 (void) fclose(dfp);
111 115 return ((PWDICT *) 0);
112 116 }
113 117
114 118 if (pdesc->header.pih_blocklen != NUMWORDS) {
115 119 pdesc->header.pih_magic = 0;
116 120 (void) fclose(ifp);
117 121 (void) fclose(dfp);
118 122 return ((PWDICT *) 0);
119 123 }
120 124
121 125 if (pdesc->flags & PFOR_USEHWMS) {
122 126 if (fread(pdesc->hwms, 1, sizeof (pdesc->hwms), wfp) !=
123 127 sizeof (pdesc->hwms)) {
124 128 pdesc->flags &= ~PFOR_USEHWMS;
125 129 }
126 130 }
127 131 }
128 132 return (pdesc);
129 133 }
130 134
131 135 int
132 136 PWClose(PWDICT *pwp)
133 137 {
134 138 if (pwp->header.pih_magic != PIH_MAGIC) {
135 139 return (-1);
136 140 }
137 141
138 142 if (pwp->flags & PFOR_WRITE) {
139 143 pwp->flags |= PFOR_FLUSH;
140 144 (void) PutPW(pwp, (char *)0); /* flush last index if necess */
141 145
142 146 if (fseek(pwp->ifp, 0L, 0)) {
143 147 return (-1);
144 148 }
145 149
146 150 if (!fwrite((char *)&pwp->header, sizeof (pwp->header),
147 151 1, pwp->ifp)) {
148 152 return (-1);
149 153 }
150 154
151 155 if (pwp->flags & PFOR_USEHWMS) {
152 156 int i;
153 157 for (i = 1; i <= 0xff; i++) {
154 158 if (!pwp->hwms[i]) {
155 159 pwp->hwms[i] = pwp->hwms[i-1];
156 160 }
157 161 }
158 162 (void) fwrite(pwp->hwms, 1, sizeof (pwp->hwms),
159 163 pwp->wfp);
160 164 }
161 165 }
162 166
163 167 (void) fclose(pwp->ifp);
164 168 (void) fclose(pwp->dfp);
165 169 (void) fclose(pwp->wfp);
166 170
167 171 pwp->header.pih_magic = 0;
168 172
169 173 free(pwp);
170 174
171 175 return (0);
172 176 }
173 177
174 178 int
175 179 PutPW(PWDICT *pwp, char *string)
176 180 {
177 181 if (!(pwp->flags & PFOR_WRITE)) {
178 182 return (-1);
179 183 }
180 184
181 185 if (string) {
182 186 (void) strncpy(pwp->data[pwp->count], string, MAXWORDLEN);
183 187 pwp->data[pwp->count][MAXWORDLEN - 1] = '\0';
184 188
185 189 pwp->hwms[string[0] & 0xff] = pwp->header.pih_numwords;
186 190
187 191 ++(pwp->count);
188 192 ++(pwp->header.pih_numwords);
189 193
190 194 } else if (!(pwp->flags & PFOR_FLUSH)) {
191 195 return (-1);
192 196 }
193 197
194 198 if ((pwp->flags & PFOR_FLUSH) || !(pwp->count % NUMWORDS)) {
195 199 int i;
196 200 uint32_t datum;
197 201 register char *ostr;
198 202
199 203 datum = (uint32_t)ftell(pwp->dfp);
200 204
201 205 (void) fwrite((char *)&datum, sizeof (datum), 1, pwp->ifp);
202 206
203 207 (void) fputs(pwp->data[0], pwp->dfp);
204 208 (void) putc(0, pwp->dfp);
205 209
206 210 ostr = pwp->data[0];
207 211
208 212 for (i = 1; i < NUMWORDS; i++) {
209 213 register int j;
210 214 register char *nstr;
211 215
212 216 nstr = pwp->data[i];
213 217
214 218 if (nstr[0]) {
215 219 for (j = 0; ostr[j] && nstr[j] &&
↓ open down ↓ |
199 lines elided |
↑ open up ↑ |
216 220 (ostr[j] == nstr[j]); j++)
217 221 ;
218 222 (void) putc(j & 0xff, pwp->dfp);
219 223 (void) fputs(nstr + j, pwp->dfp);
220 224 }
221 225 (void) putc(0, pwp->dfp);
222 226
223 227 ostr = nstr;
224 228 }
225 229
226 - (void) memset(pwp->data, '\0', sizeof (pwp->data));
227 - pwp->count = 0;
230 + (void) memset(pwp->data, '\0', sizeof (pwp->data));
231 + pwp->count = 0;
228 232 }
229 233 return (0);
230 234 }
231 235
232 236 char *
233 237 GetPW(PWDICT *pwp, uint32_t number)
234 238 {
235 239 uint32_t datum;
236 240 register int i;
237 241 register char *ostr;
238 242 register char *nstr;
239 243 register char *bptr;
240 244 char buffer[NUMWORDS * MAXWORDLEN];
241 245 static char data[NUMWORDS][MAXWORDLEN];
242 246 static uint32_t prevblock = 0xffffffff;
243 247 uint32_t thisblock;
244 248
245 249 thisblock = number / NUMWORDS;
246 250
247 251 if (prevblock == thisblock) {
248 252 return (data[number % NUMWORDS]);
249 253 }
250 254
251 255 if (fseek(pwp->ifp, sizeof (struct pi_header) +
252 256 (thisblock * sizeof (uint32_t)), 0)) {
253 257 return (NULL);
254 258 }
255 259
256 260 if (!fread((char *)&datum, sizeof (datum), 1, pwp->ifp)) {
257 261 return (NULL);
258 262 }
259 263
260 264 if (fseek(pwp->dfp, datum, 0)) {
261 265 return (NULL);
262 266 }
263 267
264 268 if (!fread(buffer, 1, sizeof (buffer), pwp->dfp)) {
265 269 return (NULL);
266 270 }
267 271
268 272 prevblock = thisblock;
269 273
270 274 bptr = buffer;
271 275
272 276 for (ostr = data[0]; *(ostr++) = *(bptr++); /* nothing */)
273 277 ;
274 278
275 279 ostr = data[0];
276 280
277 281 for (i = 1; i < NUMWORDS; i++) {
278 282 nstr = data[i];
279 283 (void) strcpy(nstr, ostr);
280 284 ostr = nstr + *(bptr++);
281 285 while (*(ostr++) = *(bptr++))
282 286 ;
283 287
284 288 ostr = nstr;
285 289 }
286 290
287 291 return (data[number % NUMWORDS]);
288 292 }
289 293
290 294 uint32_t
291 295 FindPW(PWDICT *pwp, char *string)
292 296 {
293 297 int lwm;
294 298 int hwm;
295 299 int idx;
296 300
297 301 if (string == NULL)
298 302 return (PW_WORDS(pwp));
299 303
300 304 if (pwp->flags & PFOR_USEHWMS) {
301 305 idx = string[0] & 0xff;
302 306 lwm = idx ? pwp->hwms[idx - 1] : 0;
303 307 hwm = pwp->hwms[idx];
304 308 } else {
305 309 lwm = 0;
306 310 hwm = PW_WORDS(pwp) - 1;
307 311 }
308 312
309 313 for (;;) {
310 314 int cmp;
311 315 int pivot;
312 316 char *this;
313 317
314 318 pivot = lwm + ((hwm+1)-lwm)/2;
315 319
316 320 if (feof(pwp->ifp) && feof(pwp->dfp) && feof(pwp->wfp))
317 321 break;
318 322
319 323 if ((this = GetPW(pwp, pivot)) == NULL)
320 324 break;
321 325
322 326 cmp = strcmp(string, this); /* INLINE ? */
323 327
324 328 if (cmp == 0)
325 329 return (pivot);
326 330 else if (cmp < 0)
327 331 hwm = pivot-1;
328 332 else
329 333 lwm = pivot+1;
330 334
331 335 if (lwm > hwm) /* searched all; not found */
332 336 break;
333 337 }
334 338
335 339 /* not found */
336 340 return (PW_WORDS(pwp));
337 341 }
↓ open down ↓ |
100 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX