- portabilitly: solaris fixes.
[platform/upstream/rpm.git] / rpmio / rpmrpc.c
1 /** \ingroup rpmio
2  * \file rpmio/rpmrpc.c
3  */
4
5 #include "system.h"
6
7 #if defined(HAVE_PTHREAD_H) && !defined(__LCLINT__)
8 #include <pthread.h>
9 #endif
10
11 #include <rpmio_internal.h>
12 #include "ugid.h"
13 #include "debug.h"
14
15 /*@access DIR@*/
16 /*@access FD_t@*/
17 /*@access urlinfo@*/
18
19 /* =============================================================== */
20 static int ftpMkdir(const char * path, /*@unused@*/ mode_t mode)
21         /*@globals fileSystem, internalState @*/
22         /*@modifies fileSystem, internalState @*/
23 {
24     int rc;
25     if ((rc = ftpCmd("MKD", path, NULL)) != 0)
26         return rc;
27 #if NOTYET
28     {   char buf[20];
29         sprintf(buf, " 0%o", mode);
30         (void) ftpCmd("SITE CHMOD", path, buf);
31     }
32 #endif
33     return rc;
34 }
35
36 static int ftpChdir(const char * path)
37         /*@globals fileSystem, internalState @*/
38         /*@modifies fileSystem, internalState @*/
39 {
40     return ftpCmd("CWD", path, NULL);
41 }
42
43 static int ftpRmdir(const char * path)
44         /*@globals fileSystem, internalState @*/
45         /*@modifies fileSystem, internalState @*/
46 {
47     return ftpCmd("RMD", path, NULL);
48 }
49
50 static int ftpRename(const char * oldpath, const char * newpath)
51         /*@globals fileSystem, internalState @*/
52         /*@modifies fileSystem, internalState @*/
53 {
54     int rc;
55     if ((rc = ftpCmd("RNFR", oldpath, NULL)) != 0)
56         return rc;
57     return ftpCmd("RNTO", newpath, NULL);
58 }
59
60 static int ftpUnlink(const char * path)
61         /*@globals fileSystem, internalState @*/
62         /*@modifies fileSystem, internalState @*/
63 {
64     return ftpCmd("DELE", path, NULL);
65 }
66
67 /* =============================================================== */
68 /* XXX rebuilddb.c: analogues to mkdir(2)/rmdir(2). */
69 int Mkdir (const char * path, mode_t mode)
70 {
71     const char * lpath;
72     int ut = urlPath(path, &lpath);
73
74     switch (ut) {
75     case URL_IS_FTP:
76         return ftpMkdir(path, mode);
77         /*@notreached@*/ break;
78     case URL_IS_HTTP:           /* XXX WRONG WRONG WRONG */
79     case URL_IS_PATH:
80         path = lpath;
81         /*@fallthrough@*/
82     case URL_IS_UNKNOWN:
83         break;
84     case URL_IS_DASH:
85     default:
86         return -2;
87         /*@notreached@*/ break;
88     }
89     return mkdir(path, mode);
90 }
91
92 int Chdir (const char * path)
93 {
94     const char * lpath;
95     int ut = urlPath(path, &lpath);
96
97     switch (ut) {
98     case URL_IS_FTP:
99         return ftpChdir(path);
100         /*@notreached@*/ break;
101     case URL_IS_HTTP:           /* XXX WRONG WRONG WRONG */
102     case URL_IS_PATH:
103         path = lpath;
104         /*@fallthrough@*/
105     case URL_IS_UNKNOWN:
106         break;
107     case URL_IS_DASH:
108     default:
109         return -2;
110         /*@notreached@*/ break;
111     }
112     return chdir(path);
113 }
114
115 int Rmdir (const char * path)
116 {
117     const char * lpath;
118     int ut = urlPath(path, &lpath);
119
120     switch (ut) {
121     case URL_IS_FTP:
122         return ftpRmdir(path);
123         /*@notreached@*/ break;
124     case URL_IS_HTTP:           /* XXX WRONG WRONG WRONG */
125     case URL_IS_PATH:
126         path = lpath;
127         /*@fallthrough@*/
128     case URL_IS_UNKNOWN:
129         break;
130     case URL_IS_DASH:
131     default:
132         return -2;
133         /*@notreached@*/ break;
134     }
135     return rmdir(path);
136 }
137
138 /* XXX rpmdb.c: analogue to rename(2). */
139
140 int Rename (const char * oldpath, const char * newpath)
141 {
142     const char *oe = NULL;
143     const char *ne = NULL;
144     int oldut, newut;
145
146     /* XXX lib/install.c used to rely on this behavior. */
147     if (!strcmp(oldpath, newpath)) return 0;
148
149     oldut = urlPath(oldpath, &oe);
150     switch (oldut) {
151     case URL_IS_FTP:            /* XXX WRONG WRONG WRONG */
152     case URL_IS_HTTP:           /* XXX WRONG WRONG WRONG */
153     case URL_IS_PATH:
154     case URL_IS_UNKNOWN:
155         break;
156     case URL_IS_DASH:
157     default:
158         return -2;
159         /*@notreached@*/ break;
160     }
161
162     newut = urlPath(newpath, &ne);
163     switch (newut) {
164     case URL_IS_FTP:
165 if (_rpmio_debug)
166 fprintf(stderr, "*** rename old %*s new %*s\n", (int)(oe - oldpath), oldpath, (int)(ne - newpath), newpath);
167         if (!(oldut == newut && oe && ne && (oe - oldpath) == (ne - newpath) &&
168             !xstrncasecmp(oldpath, newpath, (oe - oldpath))))
169             return -2;
170         return ftpRename(oldpath, newpath);
171         /*@notreached@*/ break;
172     case URL_IS_HTTP:           /* XXX WRONG WRONG WRONG */
173     case URL_IS_PATH:
174         oldpath = oe;
175         newpath = ne;
176         break;
177     case URL_IS_UNKNOWN:
178         break;
179     case URL_IS_DASH:
180     default:
181         return -2;
182         /*@notreached@*/ break;
183     }
184     return rename(oldpath, newpath);
185 }
186
187 int Link (const char * oldpath, const char * newpath)
188 {
189     const char *oe = NULL;
190     const char *ne = NULL;
191     int oldut, newut;
192
193     oldut = urlPath(oldpath, &oe);
194     switch (oldut) {
195     case URL_IS_FTP:            /* XXX WRONG WRONG WRONG */
196     case URL_IS_HTTP:           /* XXX WRONG WRONG WRONG */
197     case URL_IS_PATH:
198     case URL_IS_UNKNOWN:
199         break;
200     case URL_IS_DASH:
201     default:
202         return -2;
203         /*@notreached@*/ break;
204     }
205
206     newut = urlPath(newpath, &ne);
207     switch (newut) {
208     case URL_IS_HTTP:           /* XXX WRONG WRONG WRONG */
209     case URL_IS_FTP:            /* XXX WRONG WRONG WRONG */
210     case URL_IS_PATH:
211 if (_rpmio_debug)
212 fprintf(stderr, "*** link old %*s new %*s\n", (int)(oe - oldpath), oldpath, (int)(ne - newpath), newpath);
213         if (!(oldut == newut && oe && ne && (oe - oldpath) == (ne - newpath) &&
214             !xstrncasecmp(oldpath, newpath, (oe - oldpath))))
215             return -2;
216         oldpath = oe;
217         newpath = ne;
218         break;
219     case URL_IS_UNKNOWN:
220         break;
221     case URL_IS_DASH:
222     default:
223         return -2;
224         /*@notreached@*/ break;
225     }
226     return link(oldpath, newpath);
227 }
228
229 /* XXX build/build.c: analogue to unlink(2). */
230
231 int Unlink(const char * path) {
232     const char * lpath;
233     int ut = urlPath(path, &lpath);
234
235     switch (ut) {
236     case URL_IS_FTP:
237         return ftpUnlink(path);
238         /*@notreached@*/ break;
239     case URL_IS_HTTP:           /* XXX WRONG WRONG WRONG */
240     case URL_IS_PATH:
241         path = lpath;
242         /*@fallthrough@*/
243     case URL_IS_UNKNOWN:
244         break;
245     case URL_IS_DASH:
246     default:
247         return -2;
248         /*@notreached@*/ break;
249     }
250     return unlink(path);
251 }
252
253 /* XXX swiped from mc-4.5.39-pre9 vfs/ftpfs.c */
254
255 #define g_strdup        xstrdup
256 #define g_free          free
257
258 /*
259  * FIXME: this is broken. It depends on mc not crossing border on month!
260  */
261 /*@unchecked@*/
262 static int current_mday;
263 /*@unchecked@*/
264 static int current_mon;
265 /*@unchecked@*/
266 static int current_year;
267
268 /* Following stuff (parse_ls_lga) is used by ftpfs and extfs */
269 #define MAXCOLS         30
270
271 /*@unchecked@*/
272 static char *columns [MAXCOLS]; /* Points to the string in column n */
273 /*@unchecked@*/
274 static int   column_ptr [MAXCOLS]; /* Index from 0 to the starting positions of the columns */
275
276 /*@-boundswrite@*/
277 static int
278 vfs_split_text (char *p)
279         /*@globals columns, column_ptr @*/
280         /*@modifies *p, columns, column_ptr @*/
281 {
282     char *original = p;
283     int  numcols;
284
285
286     for (numcols = 0; *p && numcols < MAXCOLS; numcols++){
287         while (*p == ' ' || *p == '\r' || *p == '\n'){
288             *p = 0;
289             p++;
290         }
291         columns [numcols] = p;
292         column_ptr [numcols] = p - original;
293         while (*p && *p != ' ' && *p != '\r' && *p != '\n')
294             p++;
295     }
296     return numcols;
297 }
298 /*@=boundswrite@*/
299
300 /*@-boundsread@*/
301 static int
302 is_num (int idx)
303         /*@*/
304 {
305     if (!columns [idx] || columns [idx][0] < '0' || columns [idx][0] > '9')
306         return 0;
307     return 1;
308 }
309 /*@=boundsread@*/
310
311 /*@-boundsread@*/
312 static int
313 is_dos_date(/*@null@*/ const char *str)
314         /*@*/
315 {
316     if (str != NULL && strlen(str) == 8 &&
317                 str[2] == str[5] && strchr("\\-/", (int)str[2]) != NULL)
318         return 1;
319     return 0;
320 }
321 /*@=boundsread@*/
322
323 static int
324 is_week (/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
325         /*@modifies *tim @*/
326 {
327 /*@observer@*/ static const char * week = "SunMonTueWedThuFriSat";
328     const char * pos;
329
330     /*@-observertrans -mayaliasunique@*/
331     if (str != NULL && (pos=strstr(week, str)) != NULL) {
332     /*@=observertrans =mayaliasunique@*/
333         if (tim != NULL)
334             tim->tm_wday = (pos - week)/3;
335         return 1;
336     }
337     return 0;    
338 }
339
340 static int
341 is_month (/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
342         /*@modifies *tim @*/
343 {
344 /*@observer@*/ static const char * month = "JanFebMarAprMayJunJulAugSepOctNovDec";
345     const char * pos;
346     
347     /*@-observertrans -mayaliasunique@*/
348     if (str != NULL && (pos = strstr(month, str)) != NULL) {
349     /*@=observertrans -mayaliasunique@*/
350         if (tim != NULL)
351             tim->tm_mon = (pos - month)/3;
352         return 1;
353     }
354     return 0;
355 }
356
357 static int
358 is_time (/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
359         /*@modifies *tim @*/
360 {
361     const char * p, * p2;
362
363     if (str != NULL && (p = strchr(str, ':')) && (p2 = strrchr(str, ':'))) {
364         if (p != p2) {
365             if (sscanf (str, "%2d:%2d:%2d", &tim->tm_hour, &tim->tm_min, &tim->tm_sec) != 3)
366                 return 0;
367         } else {
368             if (sscanf (str, "%2d:%2d", &tim->tm_hour, &tim->tm_min) != 2)
369                 return 0;
370         }
371     } else 
372         return 0;
373     
374     return 1;
375 }
376
377 static int is_year(/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
378         /*@modifies *tim @*/
379 {
380     long year;
381
382     if (str == NULL)
383         return 0;
384
385     if (strchr(str,':'))
386         return 0;
387
388     if (strlen(str) != 4)
389         return 0;
390
391     if (sscanf(str, "%ld", &year) != 1)
392         return 0;
393
394     if (year < 1900 || year > 3000)
395         return 0;
396
397     tim->tm_year = (int) (year - 1900);
398
399     return 1;
400 }
401
402 /*
403  * FIXME: this is broken. Consider following entry:
404  * -rwx------   1 root     root            1 Aug 31 10:04 2904 1234
405  * where "2904 1234" is filename. Well, this code decodes it as year :-(.
406  */
407
408 static int
409 vfs_parse_filetype (char c)
410         /*@*/
411 {
412     switch (c) {
413         case 'd': return S_IFDIR; 
414         case 'b': return S_IFBLK;
415         case 'c': return S_IFCHR;
416         case 'l': return S_IFLNK;
417         case 's':
418 #ifdef IS_IFSOCK /* And if not, we fall through to IFIFO, which is pretty close */
419                   return S_IFSOCK;
420 #endif
421         case 'p': return S_IFIFO;
422         case 'm': case 'n':             /* Don't know what these are :-) */
423         case '-': case '?': return S_IFREG;
424         default: return -1;
425     }
426 }
427
428 static int vfs_parse_filemode (const char *p)
429         /*@*/
430 {       /* converts rw-rw-rw- into 0666 */
431     int res = 0;
432     switch (*(p++)) {
433         case 'r': res |= 0400; break;
434         case '-': break;
435         default: return -1;
436     }
437     switch (*(p++)) {
438         case 'w': res |= 0200; break;
439         case '-': break;
440         default: return -1;
441     }
442     switch (*(p++)) {
443         case 'x': res |= 0100; break;
444         case 's': res |= 0100 | S_ISUID; break;
445         case 'S': res |= S_ISUID; break;
446         case '-': break;
447         default: return -1;
448     }
449     switch (*(p++)) {
450         case 'r': res |= 0040; break;
451         case '-': break;
452         default: return -1;
453     }
454     switch (*(p++)) {
455         case 'w': res |= 0020; break;
456         case '-': break;
457         default: return -1;
458     }
459     switch (*(p++)) {
460         case 'x': res |= 0010; break;
461         case 's': res |= 0010 | S_ISGID; break;
462         case 'l': /* Solaris produces these */
463         case 'S': res |= S_ISGID; break;
464         case '-': break;
465         default: return -1;
466     }
467     switch (*(p++)) {
468         case 'r': res |= 0004; break;
469         case '-': break;
470         default: return -1;
471     }
472     switch (*(p++)) {
473         case 'w': res |= 0002; break;
474         case '-': break;
475         default: return -1;
476     }
477     switch (*(p++)) {
478         case 'x': res |= 0001; break;
479         case 't': res |= 0001 | S_ISVTX; break;
480         case 'T': res |= S_ISVTX; break;
481         case '-': break;
482         default: return -1;
483     }
484     return res;
485 }
486
487 /*@-boundswrite@*/
488 static int vfs_parse_filedate(int idx, /*@out@*/ time_t *t)
489         /*@modifies *t @*/
490 {       /* This thing parses from idx in columns[] array */
491
492     char *p;
493     struct tm tim;
494     int d[3];
495     int got_year = 0;
496
497     /* Let's setup default time values */
498     tim.tm_year = current_year;
499     tim.tm_mon  = current_mon;
500     tim.tm_mday = current_mday;
501     tim.tm_hour = 0;
502     tim.tm_min  = 0;
503     tim.tm_sec  = 0;
504     tim.tm_isdst = -1; /* Let mktime() try to guess correct dst offset */
505     
506     p = columns [idx++];
507     
508     /* We eat weekday name in case of extfs */
509     if(is_week(p, &tim))
510         p = columns [idx++];
511
512     /* Month name */
513     if(is_month(p, &tim)){
514         /* And we expect, it followed by day number */
515         if (is_num (idx))
516             tim.tm_mday = (int)atol (columns [idx++]);
517         else
518             return 0; /* No day */
519
520     } else {
521         /* We usually expect:
522            Mon DD hh:mm
523            Mon DD  YYYY
524            But in case of extfs we allow these date formats:
525            Mon DD YYYY hh:mm
526            Mon DD hh:mm YYYY
527            Wek Mon DD hh:mm:ss YYYY
528            MM-DD-YY hh:mm
529            where Mon is Jan-Dec, DD, MM, YY two digit day, month, year,
530            YYYY four digit year, hh, mm, ss two digit hour, minute or second. */
531
532         /* Here just this special case with MM-DD-YY */
533         if (is_dos_date(p)){
534             /*@-mods@*/
535             p[2] = p[5] = '-';
536             /*@=mods@*/
537             
538             memset(d, 0, sizeof(d));
539             if (sscanf(p, "%2d-%2d-%2d", &d[0], &d[1], &d[2]) == 3){
540             /*  We expect to get:
541                 1. MM-DD-YY
542                 2. DD-MM-YY
543                 3. YY-MM-DD
544                 4. YY-DD-MM  */
545                 
546                 /* Hmm... maybe, next time :)*/
547                 
548                 /* At last, MM-DD-YY */
549                 d[0]--; /* Months are zerobased */
550                 /* Y2K madness */
551                 if(d[2] < 70)
552                     d[2] += 100;
553
554                 tim.tm_mon  = d[0];
555                 tim.tm_mday = d[1];
556                 tim.tm_year = d[2];
557                 got_year = 1;
558             } else
559                 return 0; /* sscanf failed */
560         } else
561             return 0; /* unsupported format */
562     }
563
564     /* Here we expect to find time and/or year */
565     
566     if (is_num (idx)) {
567         if(is_time(columns[idx], &tim) || (got_year = is_year(columns[idx], &tim))) {
568         idx++;
569
570         /* This is a special case for ctime() or Mon DD YYYY hh:mm */
571         if(is_num (idx) && 
572             ((got_year = is_year(columns[idx], &tim)) || is_time(columns[idx], &tim)))
573                 idx++; /* time & year or reverse */
574         } /* only time or date */
575     }
576     else 
577         return 0; /* Nor time or date */
578
579     /*
580      * If the date is less than 6 months in the past, it is shown without year
581      * other dates in the past or future are shown with year but without time
582      * This does not check for years before 1900 ... I don't know, how
583      * to represent them at all
584      */
585     if (!got_year &&
586         current_mon < 6 && current_mon < tim.tm_mon && 
587         tim.tm_mon - current_mon >= 6)
588
589         tim.tm_year--;
590
591     if ((*t = mktime(&tim)) < 0)
592         *t = 0;
593     return idx;
594 }
595 /*@=boundswrite@*/
596
597 /*@-boundswrite@*/
598 static int
599 vfs_parse_ls_lga (char * p, /*@out@*/ struct stat * st,
600                 /*@out@*/ const char ** filename,
601                 /*@out@*/ const char ** linkname)
602         /*@modifies *p, *st, *filename, *linkname @*/
603 {
604     int idx, idx2, num_cols;
605     int i;
606     char *p_copy;
607     
608     if (strncmp (p, "total", 5) == 0)
609         return 0;
610
611     p_copy = g_strdup(p);
612 /* XXX FIXME: parse out inode number from "NLST -lai ." */
613 /* XXX FIXME: parse out sizein blocks from "NLST -lais ." */
614
615     if ((i = vfs_parse_filetype(*(p++))) == -1)
616         goto error;
617
618     st->st_mode = i;
619     if (*p == ' ')      /* Notwell 4 */
620         p++;
621     if (*p == '['){
622         if (strlen (p) <= 8 || p [8] != ']')
623             goto error;
624         /* Should parse here the Notwell permissions :) */
625         /*@-unrecog@*/
626         if (S_ISDIR (st->st_mode))
627             st->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IXUSR | S_IXGRP | S_IXOTH);
628         else
629             st->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR);
630         p += 9;
631         /*@=unrecog@*/
632     } else {
633         if ((i = vfs_parse_filemode(p)) == -1)
634             goto error;
635         st->st_mode |= i;
636         p += 9;
637
638         /* This is for an extra ACL attribute (HP-UX) */
639         if (*p == '+')
640             p++;
641     }
642
643     g_free(p_copy);
644     p_copy = g_strdup(p);
645     num_cols = vfs_split_text (p);
646
647     st->st_nlink = atol (columns [0]);
648     if (st->st_nlink < 0)
649         goto error;
650
651     if (!is_num (1))
652 #ifdef  HACK
653         st->st_uid = finduid (columns [1]);
654 #else
655         (void) unameToUid (columns [1], &st->st_uid);
656 #endif
657     else
658         st->st_uid = (uid_t) atol (columns [1]);
659
660     /* Mhm, the ls -lg did not produce a group field */
661     for (idx = 3; idx <= 5; idx++) 
662         if (is_month(columns [idx], NULL) || is_week(columns [idx], NULL) || is_dos_date(columns[idx]))
663             break;
664
665     if (idx == 6 || (idx == 5 && !S_ISCHR (st->st_mode) && !S_ISBLK (st->st_mode)))
666         goto error;
667
668     /* We don't have gid */     
669     if (idx == 3 || (idx == 4 && (S_ISCHR(st->st_mode) || S_ISBLK (st->st_mode))))
670         idx2 = 2;
671     else { 
672         /* We have gid field */
673         if (is_num (2))
674             st->st_gid = (gid_t) atol (columns [2]);
675         else
676 #ifdef  HACK
677             st->st_gid = findgid (columns [2]);
678 #else
679             (void) gnameToGid (columns [1], &st->st_gid);
680 #endif
681         idx2 = 3;
682     }
683
684     /* This is device */
685     if (S_ISCHR (st->st_mode) || S_ISBLK (st->st_mode)){
686         int maj, min;
687         
688         if (!is_num (idx2) || sscanf(columns [idx2], " %d,", &maj) != 1)
689             goto error;
690         
691         if (!is_num (++idx2) || sscanf(columns [idx2], " %d", &min) != 1)
692             goto error;
693         
694 #ifdef HAVE_ST_RDEV
695         st->st_rdev = ((maj & 0xff) << 8) | (min & 0xffff00ff);
696 #endif
697         st->st_size = 0;
698         
699     } else {
700         /* Common file size */
701         if (!is_num (idx2))
702             goto error;
703         
704         st->st_size = (size_t) atol (columns [idx2]);
705 #ifdef HAVE_ST_RDEV
706         st->st_rdev = 0;
707 #endif
708     }
709
710     idx = vfs_parse_filedate(idx, &st->st_mtime);
711     if (!idx)
712         goto error;
713     /* Use resulting time value */
714     st->st_atime = st->st_ctime = st->st_mtime;
715     st->st_dev = 0;
716     st->st_ino = 0;
717 #ifdef HAVE_ST_BLKSIZE
718     st->st_blksize = 512;
719 #endif
720 #ifdef HAVE_ST_BLOCKS
721     st->st_blocks = (st->st_size + 511) / 512;
722 #endif
723
724     for (i = idx + 1, idx2 = 0; i < num_cols; i++ ) 
725         if (strcmp (columns [i], "->") == 0){
726             idx2 = i;
727             break;
728         }
729     
730     if (((S_ISLNK (st->st_mode) || 
731         (num_cols == idx + 3 && st->st_nlink > 1))) /* Maybe a hardlink? (in extfs) */
732         && idx2){
733         int tlen;
734         char *t;
735             
736         if (filename){
737 #ifdef HACK
738             t = g_strndup (p_copy + column_ptr [idx], column_ptr [idx2] - column_ptr [idx] - 1);
739 #else
740             int nb = column_ptr [idx2] - column_ptr [idx] - 1;
741             t = xmalloc(nb+1);
742             strncpy(t, p_copy + column_ptr [idx], nb);
743 #endif
744             *filename = t;
745         }
746         if (linkname){
747             t = g_strdup (p_copy + column_ptr [idx2+1]);
748             tlen = strlen (t);
749             if (t [tlen-1] == '\r' || t [tlen-1] == '\n')
750                 t [tlen-1] = 0;
751             if (t [tlen-2] == '\r' || t [tlen-2] == '\n')
752                 t [tlen-2] = 0;
753                 
754             *linkname = t;
755         }
756     } else {
757         /* Extract the filename from the string copy, not from the columns
758          * this way we have a chance of entering hidden directories like ". ."
759          */
760         if (filename){
761             /* 
762             *filename = g_strdup (columns [idx++]);
763             */
764             int tlen;
765             char *t;
766             
767             t = g_strdup (p_copy + column_ptr [idx]); idx++;
768             tlen = strlen (t);
769             /* g_strchomp(); */
770             if (t [tlen-1] == '\r' || t [tlen-1] == '\n')
771                 t [tlen-1] = 0;
772             if (t [tlen-2] == '\r' || t [tlen-2] == '\n')
773                 t [tlen-2] = 0;
774             
775             *filename = t;
776         }
777         if (linkname)
778             *linkname = NULL;
779     }
780     g_free (p_copy);
781     return 1;
782
783 error:
784 #ifdef  HACK
785     {
786       static int errorcount = 0;
787
788       if (++errorcount < 5) {
789         message_1s (1, "Could not parse:", p_copy);
790       } else if (errorcount == 5)
791         message_1s (1, "More parsing errors will be ignored.", "(sorry)" );
792     }
793 #endif
794
795     /*@-usereleased@*/
796     if (p_copy != p)            /* Carefull! */
797     /*@=usereleased@*/
798         g_free (p_copy);
799     return 0;
800 }
801 /*@=boundswrite@*/
802
803 typedef enum {
804         DO_FTP_STAT     = 1,
805         DO_FTP_LSTAT    = 2,
806         DO_FTP_READLINK = 3,
807         DO_FTP_ACCESS   = 4,
808         DO_FTP_GLOB     = 5
809 } ftpSysCall_t;
810
811 /**
812  */
813 /*@unchecked@*/
814 static size_t ftpBufAlloced = 0;
815
816 /**
817  */
818 /*@unchecked@*/
819 static /*@only@*/ char * ftpBuf = NULL;
820         
821 #define alloca_strdup(_s)       strcpy(alloca(strlen(_s)+1), (_s))
822
823 /*@-boundswrite@*/
824 /*@-mods@*/
825 static int ftpNLST(const char * url, ftpSysCall_t ftpSysCall,
826                 /*@out@*/ /*@null@*/ struct stat * st,
827                 /*@out@*/ /*@null@*/ char * rlbuf, size_t rlbufsiz)
828         /*@globals fileSystem, internalState @*/
829         /*@modifies *st, *rlbuf, fileSystem, internalState @*/
830 {
831     FD_t fd;
832     const char * path;
833     int bufLength, moretodo;
834     const char *n, *ne, *o, *oe;
835     char * s;
836     char * se;
837     const char * urldn;
838     char * bn = NULL;
839     int nbn = 0;
840     urlinfo u;
841     int rc;
842
843     n = ne = o = oe = NULL;
844     (void) urlPath(url, &path);
845     if (*path == '\0')
846         return -2;
847
848     switch (ftpSysCall) {
849     case DO_FTP_GLOB:
850         fd = ftpOpen(url, 0, 0, &u);
851         if (fd == NULL || u == NULL)
852             return -1;
853
854         u->openError = ftpReq(fd, "LIST", path);
855         break;
856     default:
857         urldn = alloca_strdup(url);
858         /*@-branchstate@*/
859         if ((bn = strrchr(urldn, '/')) == NULL)
860             return -2;
861         else if (bn == path)
862             bn = ".";
863         else
864             *bn++ = '\0';
865         /*@=branchstate@*/
866         nbn = strlen(bn);
867
868         rc = ftpChdir(urldn);           /* XXX don't care about CWD */
869         if (rc < 0)
870             return rc;
871
872         fd = ftpOpen(url, 0, 0, &u);
873         if (fd == NULL || u == NULL)
874             return -1;
875
876         /* XXX possibly should do "NLST -lais" to get st_ino/st_blocks also */
877         u->openError = ftpReq(fd, "NLST", "-la");
878
879         if (bn == NULL || nbn <= 0) {
880             rc = -2;
881             goto exit;
882         }
883         break;
884     }
885
886     if (u->openError < 0) {
887         fd = fdLink(fd, "error data (ftpStat)");
888         rc = -2;
889         goto exit;
890     }
891
892     if (ftpBufAlloced == 0 || ftpBuf == NULL) {
893         ftpBufAlloced = _url_iobuf_size;
894         ftpBuf = xcalloc(ftpBufAlloced, sizeof(ftpBuf[0]));
895     }
896     *ftpBuf = '\0';
897
898     bufLength = 0;
899     moretodo = 1;
900
901     do {
902
903         /* XXX FIXME: realloc ftpBuf if < ~128 chars remain */
904         if ((ftpBufAlloced - bufLength) < (1024+80)) {
905             ftpBufAlloced <<= 2;
906             ftpBuf = xrealloc(ftpBuf, ftpBufAlloced);
907         }
908         s = se = ftpBuf + bufLength;
909         *se = '\0';
910
911         rc = fdFgets(fd, se, (ftpBufAlloced - bufLength));
912         if (rc <= 0) {
913             moretodo = 0;
914             break;
915         }
916         if (ftpSysCall == DO_FTP_GLOB) {        /* XXX HACK */
917             bufLength += strlen(se);
918             continue;
919         }
920
921         for (s = se; *s != '\0'; s = se) {
922             int bingo;
923
924             while (*se && *se != '\n') se++;
925             if (se > s && se[-1] == '\r') se[-1] = '\0';
926             if (*se == '\0') 
927                 /*@innerbreak@*/ break;
928             *se++ = '\0';
929
930             if (!strncmp(s, "total ", sizeof("total ")-1))
931                 /*@innercontinue@*/ continue;
932
933             o = NULL;
934             for (bingo = 0, n = se; n >= s; n--) {
935                 switch (*n) {
936                 case '\0':
937                     oe = ne = n;
938                     /*@switchbreak@*/ break;
939                 case ' ':
940                     if (o || !(n[-3] == ' ' && n[-2] == '-' && n[-1] == '>')) {
941                         while (*(++n) == ' ')
942                             {};
943                         bingo++;
944                         /*@switchbreak@*/ break;
945                     }
946                     for (o = n + 1; *o == ' '; o++)
947                         {};
948                     n -= 3;
949                     ne = n;
950                     /*@switchbreak@*/ break;
951                 default:
952                     /*@switchbreak@*/ break;
953                 }
954                 if (bingo)
955                     /*@innerbreak@*/ break;
956             }
957
958             if (nbn != (ne - n))        /* Same name length? */
959                 /*@innercontinue@*/ continue;
960             if (strncmp(n, bn, nbn))    /* Same name? */
961                 /*@innercontinue@*/ continue;
962
963             moretodo = 0;
964             /*@innerbreak@*/ break;
965         }
966
967         if (moretodo && se > s) {
968             bufLength = se - s - 1;
969             if (s != ftpBuf)
970                 memmove(ftpBuf, s, bufLength);
971         } else {
972             bufLength = 0;
973         }
974     } while (moretodo);
975
976     switch (ftpSysCall) {
977     case DO_FTP_STAT:
978         if (o && oe) {
979             /* XXX FIXME: symlink, replace urldn/bn from [o,oe) and restart */
980         }
981         /*@fallthrough@*/
982     case DO_FTP_LSTAT:
983         if (st == NULL || !(n && ne)) {
984             rc = -1;
985         } else {
986             rc = ((vfs_parse_ls_lga(s, st, NULL, NULL) > 0) ? 0 : -1);
987         }
988         break;
989     case DO_FTP_READLINK:
990         if (rlbuf == NULL || !(o && oe)) {
991             rc = -1;
992         } else {
993             rc = oe - o;
994             if (rc > rlbufsiz)
995                 rc = rlbufsiz;
996             memcpy(rlbuf, o, rc);
997             if (rc < rlbufsiz)
998                 rlbuf[rc] = '\0';
999         }
1000         break;
1001     case DO_FTP_ACCESS:
1002         rc = 0;         /* XXX WRONG WRONG WRONG */
1003         break;
1004     case DO_FTP_GLOB:
1005         rc = 0;         /* XXX WRONG WRONG WRONG */
1006         break;
1007     }
1008
1009 exit:
1010     (void) ufdClose(fd);
1011     return rc;
1012 }
1013 /*@=mods@*/
1014 /*@=boundswrite@*/
1015
1016 static const char * statstr(const struct stat * st,
1017                 /*@returned@*/ /*@out@*/ char * buf)
1018         /*@modifies *buf @*/
1019 {
1020     sprintf(buf,
1021         "*** dev %x ino %x mode %0o nlink %d uid %d gid %d rdev %x size %x\n",
1022         (unsigned)st->st_dev,
1023         (unsigned)st->st_ino,
1024         st->st_mode,
1025         (unsigned)st->st_nlink,
1026         st->st_uid,
1027         st->st_gid,
1028         (unsigned)st->st_rdev,
1029         (unsigned)st->st_size);
1030     return buf;
1031 }
1032
1033 /*@unchecked@*/
1034 static int ftp_st_ino = 0xdead0000;
1035
1036 static int ftpStat(const char * path, /*@out@*/ struct stat *st)
1037         /*@globals fileSystem, internalState @*/
1038         /*@modifies *st, fileSystem, internalState @*/
1039 {
1040     char buf[1024];
1041     int rc;
1042     rc = ftpNLST(path, DO_FTP_STAT, st, NULL, 0);
1043     /* XXX fts(3) needs/uses st_ino, make something up for now. */
1044     /*@-mods@*/
1045     if (st->st_ino == 0)
1046         st->st_ino = ftp_st_ino++;
1047     /*@=mods@*/
1048 if (_ftp_debug)
1049 fprintf(stderr, "*** ftpStat(%s) rc %d\n%s", path, rc, statstr(st, buf));
1050     return rc;
1051 }
1052
1053 static int ftpLstat(const char * path, /*@out@*/ struct stat *st)
1054         /*@globals fileSystem, internalState @*/
1055         /*@modifies *st, fileSystem, internalState @*/
1056 {
1057     char buf[1024];
1058     int rc;
1059     rc = ftpNLST(path, DO_FTP_LSTAT, st, NULL, 0);
1060     /* XXX fts(3) needs/uses st_ino, make something up for now. */
1061     /*@-mods@*/
1062     if (st->st_ino == 0)
1063         st->st_ino = ftp_st_ino++;
1064     /*@=mods@*/
1065 if (_ftp_debug)
1066 fprintf(stderr, "*** ftpLstat(%s) rc %d\n%s\n", path, rc, statstr(st, buf));
1067     return rc;
1068 }
1069
1070 static int ftpReadlink(const char * path, /*@out@*/ char * buf, size_t bufsiz)
1071         /*@globals fileSystem, internalState @*/
1072         /*@modifies *buf, fileSystem, internalState @*/
1073 {
1074     int rc;
1075     rc = ftpNLST(path, DO_FTP_READLINK, NULL, buf, bufsiz);
1076 if (_ftp_debug)
1077 fprintf(stderr, "*** ftpReadlink(%s) rc %d\n", path, rc);
1078     return rc;
1079 }
1080
1081 struct __dirstream {
1082     int fd;                     /* File descriptor.  */
1083     char * data;                /* Directory block.  */
1084     size_t allocation;          /* Space allocated for the block.  */
1085     size_t size;                /* Total valid data in the block.  */
1086     size_t offset;              /* Current offset into the block.  */
1087     off_t filepos;              /* Position of next entry to read.  */
1088 #if defined(HAVE_PTHREAD_H) && !defined(__LCLINT__)
1089     pthread_mutex_t lock;       /* Mutex lock for this structure.  */
1090 #endif
1091 };
1092
1093 #if !defined(DT_DIR)
1094 # define DT_UNKNOWN     0
1095 # define DT_FIFO        1
1096 # define DT_CHR         2
1097 # define DT_DIR         4
1098 # define DT_BLK         6
1099 # define DT_REG         8
1100 # define DT_LNK         10
1101 # define DT_SOCK        12
1102 # define DT_WHT         14
1103 typedef struct __dirstream *    FTPDIR;
1104 #else
1105 typedef DIR *                   FTPDIR;
1106 #endif
1107
1108 /*@unchecked@*/
1109 static int ftpmagicdir = 0x8440291;
1110 #define ISFTPMAGIC(_dir) (!memcmp((_dir), &ftpmagicdir, sizeof(ftpmagicdir)))
1111
1112 /*@-boundswrite@*/
1113 /*@-type@*/ /* FIX: abstract DIR */
1114 /*@null@*/
1115 static DIR * ftpOpendir(const char * path)
1116         /*@globals fileSystem, internalState @*/
1117         /*@modifies fileSystem, internalState @*/
1118 {
1119     FTPDIR mydir;
1120     struct dirent * dp;
1121     size_t nb;
1122     const char * s, * sb, * se;
1123     const char ** av;
1124     unsigned char * dt;
1125     char * t;
1126     int ac;
1127     int c;
1128     int rc;
1129
1130 if (_ftp_debug)
1131 fprintf(stderr, "*** ftpOpendir(%s)\n", path);
1132     rc = ftpNLST(path, DO_FTP_GLOB, NULL, NULL, 0);
1133     if (rc)
1134         return NULL;
1135
1136     /*
1137      * ftpBuf now contains absolute paths, newline terminated.
1138      * Calculate the number of bytes to hold the directory info.
1139      */
1140     nb = sizeof(".") + sizeof("..");
1141     ac = 2;
1142     sb = NULL;
1143     s = se = ftpBuf;
1144     while ((c = *se) != '\0') {
1145         se++;
1146         switch (c) {
1147         case '/':
1148             sb = se;
1149             /*@switchbreak@*/ break;
1150         case '\r':
1151             if (sb == NULL) {
1152                 for (sb = se; sb > s && sb[-1] != ' '; sb--)
1153                     {};
1154             }
1155             ac++;
1156             nb += (se - sb);
1157
1158             if (*se == '\n') se++;
1159             sb = NULL;
1160             s = se;
1161             /*@switchbreak@*/ break;
1162         default:
1163             /*@switchbreak@*/ break;
1164         }
1165     }
1166
1167     nb += sizeof(*mydir) + sizeof(*dp) + ((ac + 1) * sizeof(*av)) + (ac + 1);
1168     mydir = xcalloc(1, nb);
1169     /*@-abstract@*/
1170     dp = (struct dirent *) (mydir + 1);
1171     av = (const char **) (dp + 1);
1172     dt = (char *) (av + (ac + 1));
1173     t = (char *) (dt + ac + 1);
1174     /*@=abstract@*/
1175
1176     mydir->fd = ftpmagicdir;
1177 /*@-usereleased@*/
1178     mydir->data = (char *) dp;
1179 /*@=usereleased@*/
1180     mydir->allocation = nb;
1181     mydir->size = ac;
1182     mydir->offset = -1;
1183     mydir->filepos = 0;
1184
1185     ac = 0;
1186     /*@-dependenttrans -unrecog@*/
1187     dt[ac] = DT_DIR;    av[ac++] = t;   t = stpcpy(t, ".");     t++;
1188     dt[ac] = DT_DIR;    av[ac++] = t;   t = stpcpy(t, "..");    t++;
1189     /*@=dependenttrans =unrecog@*/
1190     sb = NULL;
1191     s = se = ftpBuf;
1192     while ((c = *se) != '\0') {
1193         se++;
1194         switch (c) {
1195         case '/':
1196             sb = se;
1197             /*@switchbreak@*/ break;
1198         case '\r':
1199             /*@-dependenttrans@*/
1200             av[ac] = t;
1201             /*@=dependenttrans@*/
1202             if (sb == NULL) {
1203                 /*@-unrecog@*/
1204                 switch(*s) {
1205                 case 'p':
1206                     dt[ac] = DT_FIFO;
1207                     /*@innerbreak@*/ break;
1208                 case 'c':
1209                     dt[ac] = DT_CHR;
1210                     /*@innerbreak@*/ break;
1211                 case 'd':
1212                     dt[ac] = DT_DIR;
1213                     /*@innerbreak@*/ break;
1214                 case 'b':
1215                     dt[ac] = DT_BLK;
1216                     /*@innerbreak@*/ break;
1217                 case '-':
1218                     dt[ac] = DT_REG;
1219                     /*@innerbreak@*/ break;
1220                 case 'l':
1221                     dt[ac] = DT_LNK;
1222                     /*@innerbreak@*/ break;
1223                 case 's':
1224                     dt[ac] = DT_SOCK;
1225                     /*@innerbreak@*/ break;
1226                 default:
1227                     dt[ac] = DT_UNKNOWN;
1228                     /*@innerbreak@*/ break;
1229                 }
1230                 /*@=unrecog@*/
1231                 for (sb = se; sb > s && sb[-1] != ' '; sb--)
1232                     {};
1233             }
1234             ac++;
1235             t = stpncpy(t, sb, (se - sb));
1236             t[-1] = '\0';
1237             if (*se == '\n') se++;
1238             sb = NULL;
1239             s = se;
1240             /*@switchbreak@*/ break;
1241         default:
1242             /*@switchbreak@*/ break;
1243         }
1244     }
1245     av[ac] = NULL;
1246
1247 /*@-kepttrans@*/
1248     return (DIR *) mydir;
1249 /*@=kepttrans@*/
1250 }
1251 /*@=boundswrite@*/
1252
1253 /*@dependent@*/ /*@null@*/
1254 static struct dirent * ftpReaddir(DIR * dir)
1255         /*@globals fileSystem @*/
1256         /*@modifies fileSystem @*/
1257 {
1258     FTPDIR mydir = (FTPDIR)dir;
1259     struct dirent * dp;
1260     const char ** av;
1261     unsigned char * dt;
1262     int ac;
1263     int i;
1264
1265     /*@+voidabstract@*/
1266     if (mydir == NULL || !ISFTPMAGIC(mydir) || mydir->data == NULL) {
1267         /* XXX TODO: EBADF errno. */
1268         return NULL;
1269     }
1270     /*@=voidabstract@*/
1271
1272     dp = (struct dirent *) mydir->data;
1273     av = (const char **) (dp + 1);
1274     ac = mydir->size;
1275     dt = (char *) (av + (ac + 1));
1276     i = mydir->offset + 1;
1277
1278 /*@-boundsread@*/
1279     if (i < 0 || i >= ac || av[i] == NULL)
1280         return NULL;
1281 /*@=boundsread@*/
1282
1283     mydir->offset = i;
1284
1285     /* XXX glob(3) uses REAL_DIR_ENTRY(dp) test on d_ino */
1286     dp->d_ino = i + 1;          /* W2DO? */
1287     dp->d_reclen = 0;           /* W2DO? */
1288
1289 #if !defined(hpux) && !defined(sun)
1290     dp->d_off = 0;              /* W2DO? */
1291 /*@-boundsread@*/
1292     dp->d_type = dt[i];
1293 /*@=boundsread@*/
1294 #endif
1295
1296     strncpy(dp->d_name, av[i], sizeof(dp->d_name));
1297 /*@+voidabstract@*/
1298 if (_ftp_debug)
1299 fprintf(stderr, "*** ftpReaddir(%p) %p \"%s\"\n", (void *)mydir, dp, dp->d_name);
1300 /*@=voidabstract@*/
1301     
1302     return dp;
1303 }
1304 /*@=type@*/
1305
1306 static int ftpClosedir(/*@only@*/ DIR * dir)
1307         /*@globals fileSystem @*/
1308         /*@modifies dir, fileSystem @*/
1309 {
1310     FTPDIR mydir = (FTPDIR)dir;
1311
1312     /*@+voidabstract@*/
1313 if (_ftp_debug)
1314 fprintf(stderr, "*** ftpClosedir(%p)\n", (void *)mydir);
1315     if (mydir == NULL || !ISFTPMAGIC(mydir)) {
1316         /* XXX TODO: EBADF errno. */
1317         return -1;
1318     }
1319     free((void *)mydir);
1320     /*@=voidabstract@*/
1321     mydir = NULL;
1322     return 0;
1323 }
1324
1325 int Stat(const char * path, struct stat * st)
1326 {
1327     const char * lpath;
1328     int ut = urlPath(path, &lpath);
1329
1330 if (_rpmio_debug)
1331 fprintf(stderr, "*** Stat(%s,%p)\n", path, st);
1332     switch (ut) {
1333     case URL_IS_FTP:
1334         return ftpStat(path, st);
1335         /*@notreached@*/ break;
1336     case URL_IS_HTTP:           /* XXX WRONG WRONG WRONG */
1337     case URL_IS_PATH:
1338         path = lpath;
1339         /*@fallthrough@*/
1340     case URL_IS_UNKNOWN:
1341         break;
1342     case URL_IS_DASH:
1343     default:
1344         return -2;
1345         /*@notreached@*/ break;
1346     }
1347     return stat(path, st);
1348 }
1349
1350 int Lstat(const char * path, struct stat * st)
1351 {
1352     const char * lpath;
1353     int ut = urlPath(path, &lpath);
1354
1355 if (_rpmio_debug)
1356 fprintf(stderr, "*** Lstat(%s,%p)\n", path, st);
1357     switch (ut) {
1358     case URL_IS_FTP:
1359         return ftpLstat(path, st);
1360         /*@notreached@*/ break;
1361     case URL_IS_HTTP:           /* XXX WRONG WRONG WRONG */
1362     case URL_IS_PATH:
1363         path = lpath;
1364         /*@fallthrough@*/
1365     case URL_IS_UNKNOWN:
1366         break;
1367     case URL_IS_DASH:
1368     default:
1369         return -2;
1370         /*@notreached@*/ break;
1371     }
1372     return lstat(path, st);
1373 }
1374
1375 int Readlink(const char * path, char * buf, size_t bufsiz)
1376 {
1377     const char * lpath;
1378     int ut = urlPath(path, &lpath);
1379
1380     switch (ut) {
1381     case URL_IS_FTP:
1382         return ftpReadlink(path, buf, bufsiz);
1383         /*@notreached@*/ break;
1384     case URL_IS_HTTP:           /* XXX WRONG WRONG WRONG */
1385     case URL_IS_PATH:
1386         path = lpath;
1387         /*@fallthrough@*/
1388     case URL_IS_UNKNOWN:
1389         break;
1390     case URL_IS_DASH:
1391     default:
1392         return -2;
1393         /*@notreached@*/ break;
1394     }
1395 /*@-compdef@*/
1396     return readlink(path, buf, bufsiz);
1397 /*@=compdef@*/
1398 }
1399
1400 int Access(const char * path, int amode)
1401 {
1402     const char * lpath;
1403     int ut = urlPath(path, &lpath);
1404
1405 if (_rpmio_debug)
1406 fprintf(stderr, "*** Access(%s,%d)\n", path, amode);
1407     switch (ut) {
1408     case URL_IS_FTP:            /* XXX WRONG WRONG WRONG */
1409     case URL_IS_HTTP:           /* XXX WRONG WRONG WRONG */
1410     case URL_IS_PATH:
1411         path = lpath;
1412         /*@fallthrough@*/
1413     case URL_IS_UNKNOWN:
1414         break;
1415     case URL_IS_DASH:
1416     default:
1417         return -2;
1418         /*@notreached@*/ break;
1419     }
1420     return access(path, amode);
1421 }
1422
1423 int Glob(const char *pattern, int flags,
1424         int errfunc(const char * epath, int eerrno), glob_t *pglob)
1425 {
1426     const char * lpath;
1427     int ut = urlPath(pattern, &lpath);
1428
1429 /*@-castfcnptr@*/
1430 if (_rpmio_debug)
1431 fprintf(stderr, "*** Glob(%s,0x%x,%p,%p)\n", pattern, (unsigned)flags, (void *)errfunc, pglob);
1432 /*@=castfcnptr@*/
1433     switch (ut) {
1434     case URL_IS_FTP:
1435 /*@-type@*/
1436         pglob->gl_closedir = Closedir;
1437         pglob->gl_readdir = Readdir;
1438         pglob->gl_opendir = Opendir;
1439         pglob->gl_lstat = Lstat;
1440         pglob->gl_stat = Stat;
1441 /*@=type@*/
1442         flags |= GLOB_ALTDIRFUNC;
1443         break;
1444     case URL_IS_HTTP:           /* XXX WRONG WRONG WRONG */
1445     case URL_IS_PATH:
1446         pattern = lpath;
1447         /*@fallthrough@*/
1448     case URL_IS_UNKNOWN:
1449         break;
1450     case URL_IS_DASH:
1451     default:
1452         return -2;
1453         /*@notreached@*/ break;
1454     }
1455     return glob(pattern, flags, errfunc, pglob);
1456 }
1457
1458 void Globfree(glob_t *pglob)
1459 {
1460 if (_rpmio_debug)
1461 fprintf(stderr, "*** Globfree(%p)\n", pglob);
1462     globfree(pglob);
1463 }
1464
1465 DIR * Opendir(const char * path)
1466 {
1467     const char * lpath;
1468     int ut = urlPath(path, &lpath);
1469
1470 if (_rpmio_debug)
1471 fprintf(stderr, "*** Opendir(%s)\n", path);
1472     switch (ut) {
1473     case URL_IS_FTP:
1474         return ftpOpendir(path);
1475         /*@notreached@*/ break;
1476     case URL_IS_HTTP:           /* XXX WRONG WRONG WRONG */
1477     case URL_IS_PATH:
1478         path = lpath;
1479         /*@fallthrough@*/
1480     case URL_IS_UNKNOWN:
1481         break;
1482     case URL_IS_DASH:
1483     default:
1484         return NULL;
1485         /*@notreached@*/ break;
1486     }
1487     /*@-dependenttrans@*/
1488     return opendir(path);
1489     /*@=dependenttrans@*/
1490 }
1491
1492 /*@+voidabstract@*/
1493 struct dirent * Readdir(DIR * dir)
1494 {
1495 if (_rpmio_debug)
1496 fprintf(stderr, "*** Readdir(%p)\n", (void *)dir);
1497     if (dir == NULL || ISFTPMAGIC(dir))
1498         return ftpReaddir(dir);
1499     return readdir(dir);
1500 }
1501
1502 int Closedir(DIR * dir)
1503 {
1504 if (_rpmio_debug)
1505 fprintf(stderr, "*** Closedir(%p)\n", (void *)dir);
1506     if (dir == NULL || ISFTPMAGIC(dir))
1507         return ftpClosedir(dir);
1508     return closedir(dir);
1509 }
1510 /*@=voidabstract@*/