rpmio/rpmrpc.c

Go to the documentation of this file.
00001 
00005 #include "system.h"
00006 
00007 #if defined(HAVE_PTHREAD_H) && !defined(__LCLINT__)
00008 #include <pthread.h>
00009 #endif
00010 
00011 #include <rpmio_internal.h>
00012 
00013 #define _RPMDAV_INTERNAL
00014 #include <rpmdav.h>
00015 
00016 #include "ugid.h"
00017 #include "debug.h"
00018 
00019 /*@access DIR @*/
00020 /*@access FD_t @*/
00021 /*@access urlinfo @*/
00022 
00028 /*@unused@*/ static inline /*@null@*/ void *
00029 _free(/*@only@*/ /*@null@*/ /*@out@*/ const void * p)
00030         /*@modifies p@*/
00031 {
00032     if (p != NULL)      free((void *)p);
00033     return NULL;
00034 }
00035 
00036 /* =============================================================== */
00037 static int ftpMkdir(const char * path, /*@unused@*/ mode_t mode)
00038         /*@globals h_errno, fileSystem, internalState @*/
00039         /*@modifies fileSystem, internalState @*/
00040 {
00041     int rc;
00042     if ((rc = ftpCmd("MKD", path, NULL)) != 0)
00043         return rc;
00044 #if NOTYET
00045     {   char buf[20];
00046         sprintf(buf, " 0%o", mode);
00047         (void) ftpCmd("SITE CHMOD", path, buf);
00048     }
00049 #endif
00050     return rc;
00051 }
00052 
00053 static int ftpChdir(const char * path)
00054         /*@globals h_errno, fileSystem, internalState @*/
00055         /*@modifies fileSystem, internalState @*/
00056 {
00057     return ftpCmd("CWD", path, NULL);
00058 }
00059 
00060 static int ftpRmdir(const char * path)
00061         /*@globals h_errno, fileSystem, internalState @*/
00062         /*@modifies fileSystem, internalState @*/
00063 {
00064     return ftpCmd("RMD", path, NULL);
00065 }
00066 
00067 static int ftpRename(const char * oldpath, const char * newpath)
00068         /*@globals h_errno, fileSystem, internalState @*/
00069         /*@modifies fileSystem, internalState @*/
00070 {
00071     int rc;
00072     if ((rc = ftpCmd("RNFR", oldpath, NULL)) != 0)
00073         return rc;
00074     return ftpCmd("RNTO", newpath, NULL);
00075 }
00076 
00077 static int ftpUnlink(const char * path)
00078         /*@globals h_errno, fileSystem, internalState @*/
00079         /*@modifies fileSystem, internalState @*/
00080 {
00081     return ftpCmd("DELE", path, NULL);
00082 }
00083 
00084 /* =============================================================== */
00085 int Mkdir (const char * path, mode_t mode)
00086 {
00087     const char * lpath;
00088     int ut = urlPath(path, &lpath);
00089 
00090     switch (ut) {
00091     case URL_IS_FTP:
00092         return ftpMkdir(path, mode);
00093         /*@notreached@*/ break;
00094     case URL_IS_PATH:
00095         path = lpath;
00096         /*@fallthrough@*/
00097     case URL_IS_UNKNOWN:
00098         break;
00099     case URL_IS_DASH:
00100     case URL_IS_HKP:
00101     default:
00102         return -2;
00103         /*@notreached@*/ break;
00104     }
00105     return mkdir(path, mode);
00106 }
00107 
00108 int Chdir (const char * path)
00109 {
00110     const char * lpath;
00111     int ut = urlPath(path, &lpath);
00112 
00113     switch (ut) {
00114     case URL_IS_FTP:
00115         return ftpChdir(path);
00116         /*@notreached@*/ break;
00117     case URL_IS_PATH:
00118         path = lpath;
00119         /*@fallthrough@*/
00120     case URL_IS_UNKNOWN:
00121         break;
00122     case URL_IS_DASH:
00123     case URL_IS_HKP:
00124     default:
00125         return -2;
00126         /*@notreached@*/ break;
00127     }
00128     return chdir(path);
00129 }
00130 
00131 int Rmdir (const char * path)
00132 {
00133     const char * lpath;
00134     int ut = urlPath(path, &lpath);
00135 
00136     switch (ut) {
00137     case URL_IS_FTP:
00138         return ftpRmdir(path);
00139         /*@notreached@*/ break;
00140     case URL_IS_PATH:
00141         path = lpath;
00142         /*@fallthrough@*/
00143     case URL_IS_UNKNOWN:
00144         break;
00145     case URL_IS_DASH:
00146     case URL_IS_HKP:
00147     default:
00148         return -2;
00149         /*@notreached@*/ break;
00150     }
00151     return rmdir(path);
00152 }
00153 
00154 /* XXX rpmdb.c: analogue to rename(2). */
00155 
00156 int Rename (const char * oldpath, const char * newpath)
00157 {
00158     const char *oe = NULL;
00159     const char *ne = NULL;
00160     int oldut, newut;
00161 
00162     /* XXX lib/install.c used to rely on this behavior. */
00163     if (!strcmp(oldpath, newpath)) return 0;
00164 
00165     oldut = urlPath(oldpath, &oe);
00166     switch (oldut) {
00167     case URL_IS_FTP:            /* XXX WRONG WRONG WRONG */
00168     case URL_IS_PATH:
00169     case URL_IS_UNKNOWN:
00170         break;
00171     case URL_IS_DASH:
00172     case URL_IS_HKP:
00173     default:
00174         return -2;
00175         /*@notreached@*/ break;
00176     }
00177 
00178     newut = urlPath(newpath, &ne);
00179     switch (newut) {
00180     case URL_IS_FTP:
00181 if (_rpmio_debug)
00182 fprintf(stderr, "*** rename old %*s new %*s\n", (int)(oe - oldpath), oldpath, (int)(ne - newpath), newpath);
00183         if (!(oldut == newut && oe && ne && (oe - oldpath) == (ne - newpath) &&
00184             !xstrncasecmp(oldpath, newpath, (oe - oldpath))))
00185             return -2;
00186         return ftpRename(oldpath, newpath);
00187         /*@notreached@*/ break;
00188     case URL_IS_HTTPS:          /* XXX WRONG WRONG WRONG */
00189     case URL_IS_HTTP:           /* XXX WRONG WRONG WRONG */
00190     case URL_IS_PATH:
00191         oldpath = oe;
00192         newpath = ne;
00193         break;
00194     case URL_IS_UNKNOWN:
00195         break;
00196     case URL_IS_DASH:
00197     case URL_IS_HKP:
00198     default:
00199         return -2;
00200         /*@notreached@*/ break;
00201     }
00202     return rename(oldpath, newpath);
00203 }
00204 
00205 int Link (const char * oldpath, const char * newpath)
00206 {
00207     const char *oe = NULL;
00208     const char *ne = NULL;
00209     int oldut, newut;
00210 
00211     oldut = urlPath(oldpath, &oe);
00212     switch (oldut) {
00213     case URL_IS_HTTPS:          /* XXX WRONG WRONG WRONG */
00214     case URL_IS_HTTP:           /* XXX WRONG WRONG WRONG */
00215     case URL_IS_FTP:            /* XXX WRONG WRONG WRONG */
00216     case URL_IS_PATH:
00217     case URL_IS_UNKNOWN:
00218         break;
00219     case URL_IS_DASH:
00220     case URL_IS_HKP:
00221     default:
00222         return -2;
00223         /*@notreached@*/ break;
00224     }
00225 
00226     newut = urlPath(newpath, &ne);
00227     switch (newut) {
00228     case URL_IS_HTTPS:          /* XXX WRONG WRONG WRONG */
00229     case URL_IS_HTTP:           /* XXX WRONG WRONG WRONG */
00230     case URL_IS_FTP:            /* XXX WRONG WRONG WRONG */
00231     case URL_IS_PATH:
00232 if (_rpmio_debug)
00233 fprintf(stderr, "*** link old %*s new %*s\n", (int)(oe - oldpath), oldpath, (int)(ne - newpath), newpath);
00234         if (!(oldut == newut && oe && ne && (oe - oldpath) == (ne - newpath) &&
00235             !xstrncasecmp(oldpath, newpath, (oe - oldpath))))
00236             return -2;
00237         oldpath = oe;
00238         newpath = ne;
00239         break;
00240     case URL_IS_UNKNOWN:
00241         break;
00242     case URL_IS_DASH:
00243     case URL_IS_HKP:
00244     default:
00245         return -2;
00246         /*@notreached@*/ break;
00247     }
00248     return link(oldpath, newpath);
00249 }
00250 
00251 /* XXX build/build.c: analogue to unlink(2). */
00252 
00253 int Unlink(const char * path) {
00254     const char * lpath;
00255     int ut = urlPath(path, &lpath);
00256 
00257     switch (ut) {
00258     case URL_IS_FTP:
00259         return ftpUnlink(path);
00260         /*@notreached@*/ break;
00261     case URL_IS_PATH:
00262         path = lpath;
00263         /*@fallthrough@*/
00264     case URL_IS_UNKNOWN:
00265         break;
00266     case URL_IS_DASH:
00267     case URL_IS_HKP:
00268     default:
00269         return -2;
00270         /*@notreached@*/ break;
00271     }
00272     return unlink(path);
00273 }
00274 
00275 /* XXX swiped from mc-4.5.39-pre9 vfs/ftpfs.c */
00276 
00277 #define g_strdup        xstrdup
00278 #define g_free          free
00279 
00280 /*
00281  * FIXME: this is broken. It depends on mc not crossing border on month!
00282  */
00283 /*@unchecked@*/
00284 static int current_mday;
00285 /*@unchecked@*/
00286 static int current_mon;
00287 /*@unchecked@*/
00288 static int current_year;
00289 
00290 /* Following stuff (parse_ls_lga) is used by ftpfs and extfs */
00291 #define MAXCOLS         30
00292 
00293 /*@unchecked@*/
00294 static char *columns [MAXCOLS]; /* Points to the string in column n */
00295 /*@unchecked@*/
00296 static int   column_ptr [MAXCOLS]; /* Index from 0 to the starting positions of the columns */
00297 
00298 /*@-boundswrite@*/
00299 static int
00300 vfs_split_text (char *p)
00301         /*@globals columns, column_ptr @*/
00302         /*@modifies *p, columns, column_ptr @*/
00303 {
00304     char *original = p;
00305     int  numcols;
00306 
00307 
00308     for (numcols = 0; *p && numcols < MAXCOLS; numcols++){
00309         while (*p == ' ' || *p == '\r' || *p == '\n'){
00310             *p = 0;
00311             p++;
00312         }
00313         columns [numcols] = p;
00314         column_ptr [numcols] = p - original;
00315         while (*p && *p != ' ' && *p != '\r' && *p != '\n')
00316             p++;
00317     }
00318     return numcols;
00319 }
00320 /*@=boundswrite@*/
00321 
00322 /*@-boundsread@*/
00323 static int
00324 is_num (int idx)
00325         /*@*/
00326 {
00327     if (!columns [idx] || columns [idx][0] < '0' || columns [idx][0] > '9')
00328         return 0;
00329     return 1;
00330 }
00331 /*@=boundsread@*/
00332 
00333 /*@-boundsread@*/
00334 static int
00335 is_dos_date(/*@null@*/ const char *str)
00336         /*@*/
00337 {
00338     if (str != NULL && strlen(str) == 8 &&
00339                 str[2] == str[5] && strchr("\\-/", (int)str[2]) != NULL)
00340         return 1;
00341     return 0;
00342 }
00343 /*@=boundsread@*/
00344 
00345 static int
00346 is_week (/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
00347         /*@modifies *tim @*/
00348 {
00349 /*@observer@*/ static const char * week = "SunMonTueWedThuFriSat";
00350     const char * pos;
00351 
00352     /*@-observertrans -mayaliasunique@*/
00353     if (str != NULL && (pos=strstr(week, str)) != NULL) {
00354     /*@=observertrans =mayaliasunique@*/
00355         if (tim != NULL)
00356             tim->tm_wday = (pos - week)/3;
00357         return 1;
00358     }
00359     return 0;    
00360 }
00361 
00362 static int
00363 is_month (/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
00364         /*@modifies *tim @*/
00365 {
00366 /*@observer@*/ static const char * month = "JanFebMarAprMayJunJulAugSepOctNovDec";
00367     const char * pos;
00368     
00369     /*@-observertrans -mayaliasunique@*/
00370     if (str != NULL && (pos = strstr(month, str)) != NULL) {
00371     /*@=observertrans -mayaliasunique@*/
00372         if (tim != NULL)
00373             tim->tm_mon = (pos - month)/3;
00374         return 1;
00375     }
00376     return 0;
00377 }
00378 
00379 static int
00380 is_time (/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
00381         /*@modifies *tim @*/
00382 {
00383     const char * p, * p2;
00384 
00385     if (str != NULL && (p = strchr(str, ':')) && (p2 = strrchr(str, ':'))) {
00386         if (p != p2) {
00387             if (sscanf (str, "%2d:%2d:%2d", &tim->tm_hour, &tim->tm_min, &tim->tm_sec) != 3)
00388                 return 0;
00389         } else {
00390             if (sscanf (str, "%2d:%2d", &tim->tm_hour, &tim->tm_min) != 2)
00391                 return 0;
00392         }
00393     } else 
00394         return 0;
00395     
00396     return 1;
00397 }
00398 
00399 static int is_year(/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
00400         /*@modifies *tim @*/
00401 {
00402     long year;
00403 
00404     if (str == NULL)
00405         return 0;
00406 
00407     if (strchr(str,':'))
00408         return 0;
00409 
00410     if (strlen(str) != 4)
00411         return 0;
00412 
00413     if (sscanf(str, "%ld", &year) != 1)
00414         return 0;
00415 
00416     if (year < 1900 || year > 3000)
00417         return 0;
00418 
00419     tim->tm_year = (int) (year - 1900);
00420 
00421     return 1;
00422 }
00423 
00424 /*
00425  * FIXME: this is broken. Consider following entry:
00426  * -rwx------   1 root     root            1 Aug 31 10:04 2904 1234
00427  * where "2904 1234" is filename. Well, this code decodes it as year :-(.
00428  */
00429 
00430 static int
00431 vfs_parse_filetype (char c)
00432         /*@*/
00433 {
00434     switch (c) {
00435         case 'd': return S_IFDIR; 
00436         case 'b': return S_IFBLK;
00437         case 'c': return S_IFCHR;
00438         case 'l': return S_IFLNK;
00439         case 's':
00440 #ifdef IS_IFSOCK /* And if not, we fall through to IFIFO, which is pretty close */
00441                   return S_IFSOCK;
00442 #endif
00443         case 'p': return S_IFIFO;
00444         case 'm': case 'n':             /* Don't know what these are :-) */
00445         case '-': case '?': return S_IFREG;
00446         default: return -1;
00447     }
00448 }
00449 
00450 static int vfs_parse_filemode (const char *p)
00451         /*@*/
00452 {       /* converts rw-rw-rw- into 0666 */
00453     int res = 0;
00454     switch (*(p++)) {
00455         case 'r': res |= 0400; break;
00456         case '-': break;
00457         default: return -1;
00458     }
00459     switch (*(p++)) {
00460         case 'w': res |= 0200; break;
00461         case '-': break;
00462         default: return -1;
00463     }
00464     switch (*(p++)) {
00465         case 'x': res |= 0100; break;
00466         case 's': res |= 0100 | S_ISUID; break;
00467         case 'S': res |= S_ISUID; break;
00468         case '-': break;
00469         default: return -1;
00470     }
00471     switch (*(p++)) {
00472         case 'r': res |= 0040; break;
00473         case '-': break;
00474         default: return -1;
00475     }
00476     switch (*(p++)) {
00477         case 'w': res |= 0020; break;
00478         case '-': break;
00479         default: return -1;
00480     }
00481     switch (*(p++)) {
00482         case 'x': res |= 0010; break;
00483         case 's': res |= 0010 | S_ISGID; break;
00484         case 'l': /* Solaris produces these */
00485         case 'S': res |= S_ISGID; break;
00486         case '-': break;
00487         default: return -1;
00488     }
00489     switch (*(p++)) {
00490         case 'r': res |= 0004; break;
00491         case '-': break;
00492         default: return -1;
00493     }
00494     switch (*(p++)) {
00495         case 'w': res |= 0002; break;
00496         case '-': break;
00497         default: return -1;
00498     }
00499     switch (*(p++)) {
00500         case 'x': res |= 0001; break;
00501         case 't': res |= 0001 | S_ISVTX; break;
00502         case 'T': res |= S_ISVTX; break;
00503         case '-': break;
00504         default: return -1;
00505     }
00506     return res;
00507 }
00508 
00509 /*@-boundswrite@*/
00510 static int vfs_parse_filedate(int idx, /*@out@*/ time_t *t)
00511         /*@modifies *t @*/
00512 {       /* This thing parses from idx in columns[] array */
00513 
00514     char *p;
00515     struct tm tim;
00516     int d[3];
00517     int got_year = 0;
00518 
00519     /* Let's setup default time values */
00520     tim.tm_year = current_year;
00521     tim.tm_mon  = current_mon;
00522     tim.tm_mday = current_mday;
00523     tim.tm_hour = 0;
00524     tim.tm_min  = 0;
00525     tim.tm_sec  = 0;
00526     tim.tm_isdst = -1; /* Let mktime() try to guess correct dst offset */
00527     
00528     p = columns [idx++];
00529     
00530     /* We eat weekday name in case of extfs */
00531     if(is_week(p, &tim))
00532         p = columns [idx++];
00533 
00534     /* Month name */
00535     if(is_month(p, &tim)){
00536         /* And we expect, it followed by day number */
00537         if (is_num (idx))
00538             tim.tm_mday = (int)atol (columns [idx++]);
00539         else
00540             return 0; /* No day */
00541 
00542     } else {
00543         /* We usually expect:
00544            Mon DD hh:mm
00545            Mon DD  YYYY
00546            But in case of extfs we allow these date formats:
00547            Mon DD YYYY hh:mm
00548            Mon DD hh:mm YYYY
00549            Wek Mon DD hh:mm:ss YYYY
00550            MM-DD-YY hh:mm
00551            where Mon is Jan-Dec, DD, MM, YY two digit day, month, year,
00552            YYYY four digit year, hh, mm, ss two digit hour, minute or second. */
00553 
00554         /* Here just this special case with MM-DD-YY */
00555         if (is_dos_date(p)){
00556             /*@-mods@*/
00557             p[2] = p[5] = '-';
00558             /*@=mods@*/
00559             
00560             memset(d, 0, sizeof(d));
00561             if (sscanf(p, "%2d-%2d-%2d", &d[0], &d[1], &d[2]) == 3){
00562             /*  We expect to get:
00563                 1. MM-DD-YY
00564                 2. DD-MM-YY
00565                 3. YY-MM-DD
00566                 4. YY-DD-MM  */
00567                 
00568                 /* Hmm... maybe, next time :)*/
00569                 
00570                 /* At last, MM-DD-YY */
00571                 d[0]--; /* Months are zerobased */
00572                 /* Y2K madness */
00573                 if(d[2] < 70)
00574                     d[2] += 100;
00575 
00576                 tim.tm_mon  = d[0];
00577                 tim.tm_mday = d[1];
00578                 tim.tm_year = d[2];
00579                 got_year = 1;
00580             } else
00581                 return 0; /* sscanf failed */
00582         } else
00583             return 0; /* unsupported format */
00584     }
00585 
00586     /* Here we expect to find time and/or year */
00587     
00588     if (is_num (idx)) {
00589         if(is_time(columns[idx], &tim) || (got_year = is_year(columns[idx], &tim))) {
00590         idx++;
00591 
00592         /* This is a special case for ctime() or Mon DD YYYY hh:mm */
00593         if(is_num (idx) && 
00594             ((got_year = is_year(columns[idx], &tim)) || is_time(columns[idx], &tim)))
00595                 idx++; /* time & year or reverse */
00596         } /* only time or date */
00597     }
00598     else 
00599         return 0; /* Nor time or date */
00600 
00601     /*
00602      * If the date is less than 6 months in the past, it is shown without year
00603      * other dates in the past or future are shown with year but without time
00604      * This does not check for years before 1900 ... I don't know, how
00605      * to represent them at all
00606      */
00607     if (!got_year &&
00608         current_mon < 6 && current_mon < tim.tm_mon && 
00609         tim.tm_mon - current_mon >= 6)
00610 
00611         tim.tm_year--;
00612 
00613     if ((*t = mktime(&tim)) < 0)
00614         *t = 0;
00615     return idx;
00616 }
00617 /*@=boundswrite@*/
00618 
00619 /*@-boundswrite@*/
00620 static int
00621 vfs_parse_ls_lga (char * p, /*@out@*/ struct stat * st,
00622                 /*@out@*/ const char ** filename,
00623                 /*@out@*/ const char ** linkname)
00624         /*@modifies *p, *st, *filename, *linkname @*/
00625 {
00626     int idx, idx2, num_cols;
00627     int i;
00628     char *p_copy;
00629     
00630     if (strncmp (p, "total", 5) == 0)
00631         return 0;
00632 
00633     p_copy = g_strdup(p);
00634 /* XXX FIXME: parse out inode number from "NLST -lai ." */
00635 /* XXX FIXME: parse out sizein blocks from "NLST -lais ." */
00636 
00637     if ((i = vfs_parse_filetype(*(p++))) == -1)
00638         goto error;
00639 
00640     st->st_mode = i;
00641     if (*p == ' ')      /* Notwell 4 */
00642         p++;
00643     if (*p == '['){
00644         if (strlen (p) <= 8 || p [8] != ']')
00645             goto error;
00646         /* Should parse here the Notwell permissions :) */
00647         /*@-unrecog@*/
00648         if (S_ISDIR (st->st_mode))
00649             st->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IXUSR | S_IXGRP | S_IXOTH);
00650         else
00651             st->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR);
00652         p += 9;
00653         /*@=unrecog@*/
00654     } else {
00655         if ((i = vfs_parse_filemode(p)) == -1)
00656             goto error;
00657         st->st_mode |= i;
00658         p += 9;
00659 
00660         /* This is for an extra ACL attribute (HP-UX) */
00661         if (*p == '+')
00662             p++;
00663     }
00664 
00665     g_free(p_copy);
00666     p_copy = g_strdup(p);
00667     num_cols = vfs_split_text (p);
00668 
00669     st->st_nlink = atol (columns [0]);
00670     if (st->st_nlink < 0)
00671         goto error;
00672 
00673     if (!is_num (1))
00674 #ifdef  HACK
00675         st->st_uid = finduid (columns [1]);
00676 #else
00677         (void) unameToUid (columns [1], &st->st_uid);
00678 #endif
00679     else
00680         st->st_uid = (uid_t) atol (columns [1]);
00681 
00682     /* Mhm, the ls -lg did not produce a group field */
00683     for (idx = 3; idx <= 5; idx++) 
00684         if (is_month(columns [idx], NULL) || is_week(columns [idx], NULL) || is_dos_date(columns[idx]))
00685             break;
00686 
00687     if (idx == 6 || (idx == 5 && !S_ISCHR (st->st_mode) && !S_ISBLK (st->st_mode)))
00688         goto error;
00689 
00690     /* We don't have gid */     
00691     if (idx == 3 || (idx == 4 && (S_ISCHR(st->st_mode) || S_ISBLK (st->st_mode))))
00692         idx2 = 2;
00693     else { 
00694         /* We have gid field */
00695         if (is_num (2))
00696             st->st_gid = (gid_t) atol (columns [2]);
00697         else
00698 #ifdef  HACK
00699             st->st_gid = findgid (columns [2]);
00700 #else
00701             (void) gnameToGid (columns [1], &st->st_gid);
00702 #endif
00703         idx2 = 3;
00704     }
00705 
00706     /* This is device */
00707     if (S_ISCHR (st->st_mode) || S_ISBLK (st->st_mode)){
00708         unsigned maj, min;
00709         
00710         if (!is_num (idx2) || sscanf(columns [idx2], " %d,", &maj) != 1)
00711             goto error;
00712         
00713         if (!is_num (++idx2) || sscanf(columns [idx2], " %d", &min) != 1)
00714             goto error;
00715         
00716 #ifdef HAVE_ST_RDEV
00717         st->st_rdev = ((maj & 0x000000ffU) << 8) | (min & 0x000000ffU);
00718 #endif
00719         st->st_size = 0;
00720         
00721     } else {
00722         /* Common file size */
00723         if (!is_num (idx2))
00724             goto error;
00725         
00726         st->st_size = (size_t) atol (columns [idx2]);
00727 #ifdef HAVE_ST_RDEV
00728         st->st_rdev = 0;
00729 #endif
00730     }
00731 
00732     idx = vfs_parse_filedate(idx, &st->st_mtime);
00733     if (!idx)
00734         goto error;
00735     /* Use resulting time value */
00736     st->st_atime = st->st_ctime = st->st_mtime;
00737     st->st_dev = 0;
00738     st->st_ino = 0;
00739 #ifdef HAVE_ST_BLKSIZE
00740     st->st_blksize = 512;
00741 #endif
00742 #ifdef HAVE_ST_BLOCKS
00743     st->st_blocks = (st->st_size + 511) / 512;
00744 #endif
00745 
00746     for (i = idx + 1, idx2 = 0; i < num_cols; i++ ) 
00747         if (strcmp (columns [i], "->") == 0){
00748             idx2 = i;
00749             break;
00750         }
00751     
00752     if (((S_ISLNK (st->st_mode) || 
00753         (num_cols == idx + 3 && st->st_nlink > 1))) /* Maybe a hardlink? (in extfs) */
00754         && idx2){
00755         int tlen;
00756         char *t;
00757             
00758         if (filename){
00759 #ifdef HACK
00760             t = g_strndup (p_copy + column_ptr [idx], column_ptr [idx2] - column_ptr [idx] - 1);
00761 #else
00762             int nb = column_ptr [idx2] - column_ptr [idx] - 1;
00763             t = xmalloc(nb+1);
00764             strncpy(t, p_copy + column_ptr [idx], nb);
00765 #endif
00766             *filename = t;
00767         }
00768         if (linkname){
00769             t = g_strdup (p_copy + column_ptr [idx2+1]);
00770             tlen = strlen (t);
00771             if (t [tlen-1] == '\r' || t [tlen-1] == '\n')
00772                 t [tlen-1] = 0;
00773             if (t [tlen-2] == '\r' || t [tlen-2] == '\n')
00774                 t [tlen-2] = 0;
00775                 
00776             *linkname = t;
00777         }
00778     } else {
00779         /* Extract the filename from the string copy, not from the columns
00780          * this way we have a chance of entering hidden directories like ". ."
00781          */
00782         if (filename){
00783             /* 
00784             *filename = g_strdup (columns [idx++]);
00785             */
00786             int tlen;
00787             char *t;
00788             
00789             t = g_strdup (p_copy + column_ptr [idx]); idx++;
00790             tlen = strlen (t);
00791             /* g_strchomp(); */
00792             if (t [tlen-1] == '\r' || t [tlen-1] == '\n')
00793                 t [tlen-1] = 0;
00794             if (t [tlen-2] == '\r' || t [tlen-2] == '\n')
00795                 t [tlen-2] = 0;
00796             
00797             *filename = t;
00798         }
00799         if (linkname)
00800             *linkname = NULL;
00801     }
00802     g_free (p_copy);
00803     return 1;
00804 
00805 error:
00806 #ifdef  HACK
00807     {
00808       static int errorcount = 0;
00809 
00810       if (++errorcount < 5) {
00811         message_1s (1, "Could not parse:", p_copy);
00812       } else if (errorcount == 5)
00813         message_1s (1, "More parsing errors will be ignored.", "(sorry)" );
00814     }
00815 #endif
00816 
00817     /*@-usereleased@*/
00818     if (p_copy != p)            /* Carefull! */
00819     /*@=usereleased@*/
00820         g_free (p_copy);
00821     return 0;
00822 }
00823 /*@=boundswrite@*/
00824 
00825 typedef enum {
00826         DO_FTP_STAT     = 1,
00827         DO_FTP_LSTAT    = 2,
00828         DO_FTP_READLINK = 3,
00829         DO_FTP_ACCESS   = 4,
00830         DO_FTP_GLOB     = 5
00831 } ftpSysCall_t;
00832 
00835 /*@unchecked@*/
00836 static size_t ftpBufAlloced = 0;
00837 
00840 /*@unchecked@*/
00841 static /*@only@*/ char * ftpBuf = NULL;
00842         
00843 #define alloca_strdup(_s)       strcpy(alloca(strlen(_s)+1), (_s))
00844 
00845 /*@-boundswrite@*/
00846 static int ftpNLST(const char * url, ftpSysCall_t ftpSysCall,
00847                 /*@out@*/ /*@null@*/ struct stat * st,
00848                 /*@out@*/ /*@null@*/ char * rlbuf, size_t rlbufsiz)
00849         /*@globals ftpBufAlloced, ftpBuf,
00850                 h_errno, fileSystem, internalState @*/
00851         /*@modifies *st, *rlbuf, ftpBufAlloced, ftpBuf,
00852                 fileSystem, internalState @*/
00853 {
00854     FD_t fd;
00855     const char * path;
00856     int bufLength, moretodo;
00857     const char *n, *ne, *o, *oe;
00858     char * s;
00859     char * se;
00860     const char * urldn;
00861     char * bn = NULL;
00862     int nbn = 0;
00863     urlinfo u;
00864     int rc;
00865 
00866     n = ne = o = oe = NULL;
00867     (void) urlPath(url, &path);
00868     if (*path == '\0')
00869         return -2;
00870 
00871     switch (ftpSysCall) {
00872     case DO_FTP_GLOB:
00873         fd = ftpOpen(url, 0, 0, &u);
00874         if (fd == NULL || u == NULL)
00875             return -1;
00876 
00877         u->openError = ftpReq(fd, "LIST", path);
00878         break;
00879     default:
00880         urldn = alloca_strdup(url);
00881         /*@-branchstate@*/
00882         if ((bn = strrchr(urldn, '/')) == NULL)
00883             return -2;
00884         else if (bn == path)
00885             bn = ".";
00886         else
00887             *bn++ = '\0';
00888         /*@=branchstate@*/
00889         nbn = strlen(bn);
00890 
00891         rc = ftpChdir(urldn);           /* XXX don't care about CWD */
00892         if (rc < 0)
00893             return rc;
00894 
00895         fd = ftpOpen(url, 0, 0, &u);
00896         if (fd == NULL || u == NULL)
00897             return -1;
00898 
00899         /* XXX possibly should do "NLST -lais" to get st_ino/st_blocks also */
00900         u->openError = ftpReq(fd, "NLST", "-la");
00901 
00902         if (bn == NULL || nbn <= 0) {
00903             rc = -2;
00904             goto exit;
00905         }
00906         break;
00907     }
00908 
00909     if (u->openError < 0) {
00910         fd = fdLink(fd, "error data (ftpStat)");
00911         rc = -2;
00912         goto exit;
00913     }
00914 
00915     if (ftpBufAlloced == 0 || ftpBuf == NULL) {
00916         ftpBufAlloced = _url_iobuf_size;
00917         ftpBuf = xcalloc(ftpBufAlloced, sizeof(ftpBuf[0]));
00918     }
00919     *ftpBuf = '\0';
00920 
00921     bufLength = 0;
00922     moretodo = 1;
00923 
00924     do {
00925 
00926         /* XXX FIXME: realloc ftpBuf if < ~128 chars remain */
00927         if ((ftpBufAlloced - bufLength) < (1024+80)) {
00928             ftpBufAlloced <<= 2;
00929             assert(ftpBufAlloced < (8*1024*1024));
00930             ftpBuf = xrealloc(ftpBuf, ftpBufAlloced);
00931         }
00932         s = se = ftpBuf + bufLength;
00933         *se = '\0';
00934 
00935         rc = fdFgets(fd, se, (ftpBufAlloced - bufLength));
00936         if (rc <= 0) {
00937             moretodo = 0;
00938             break;
00939         }
00940         if (ftpSysCall == DO_FTP_GLOB) {        /* XXX HACK */
00941             bufLength += strlen(se);
00942             continue;
00943         }
00944 
00945         for (s = se; *s != '\0'; s = se) {
00946             int bingo;
00947 
00948             while (*se && *se != '\n') se++;
00949             if (se > s && se[-1] == '\r') se[-1] = '\0';
00950             if (*se == '\0') 
00951                 /*@innerbreak@*/ break;
00952             *se++ = '\0';
00953 
00954             if (!strncmp(s, "total ", sizeof("total ")-1))
00955                 /*@innercontinue@*/ continue;
00956 
00957             o = NULL;
00958             for (bingo = 0, n = se; n >= s; n--) {
00959                 switch (*n) {
00960                 case '\0':
00961                     oe = ne = n;
00962                     /*@switchbreak@*/ break;
00963                 case ' ':
00964                     if (o || !(n[-3] == ' ' && n[-2] == '-' && n[-1] == '>')) {
00965                         while (*(++n) == ' ')
00966                             {};
00967                         bingo++;
00968                         /*@switchbreak@*/ break;
00969                     }
00970                     for (o = n + 1; *o == ' '; o++)
00971                         {};
00972                     n -= 3;
00973                     ne = n;
00974                     /*@switchbreak@*/ break;
00975                 default:
00976                     /*@switchbreak@*/ break;
00977                 }
00978                 if (bingo)
00979                     /*@innerbreak@*/ break;
00980             }
00981 
00982             if (nbn != (ne - n))        /* Same name length? */
00983                 /*@innercontinue@*/ continue;
00984             if (strncmp(n, bn, nbn))    /* Same name? */
00985                 /*@innercontinue@*/ continue;
00986 
00987             moretodo = 0;
00988             /*@innerbreak@*/ break;
00989         }
00990 
00991         if (moretodo && se > s) {
00992             bufLength = se - s - 1;
00993             if (s != ftpBuf)
00994                 memmove(ftpBuf, s, bufLength);
00995         } else {
00996             bufLength = 0;
00997         }
00998     } while (moretodo);
00999 
01000     switch (ftpSysCall) {
01001     case DO_FTP_STAT:
01002         if (o && oe) {
01003             /* XXX FIXME: symlink, replace urldn/bn from [o,oe) and restart */
01004         }
01005         /*@fallthrough@*/
01006     case DO_FTP_LSTAT:
01007         if (st == NULL || !(n && ne)) {
01008             rc = -1;
01009         } else {
01010             rc = ((vfs_parse_ls_lga(s, st, NULL, NULL) > 0) ? 0 : -1);
01011         }
01012         break;
01013     case DO_FTP_READLINK:
01014         if (rlbuf == NULL || !(o && oe)) {
01015             rc = -1;
01016         } else {
01017             rc = oe - o;
01018             if (rc > rlbufsiz)
01019                 rc = rlbufsiz;
01020             memcpy(rlbuf, o, rc);
01021             if (rc < rlbufsiz)
01022                 rlbuf[rc] = '\0';
01023         }
01024         break;
01025     case DO_FTP_ACCESS:
01026         rc = 0;         /* XXX WRONG WRONG WRONG */
01027         break;
01028     case DO_FTP_GLOB:
01029         rc = 0;         /* XXX WRONG WRONG WRONG */
01030         break;
01031     }
01032 
01033 exit:
01034     (void) ufdClose(fd);
01035     return rc;
01036 }
01037 /*@=boundswrite@*/
01038 
01039 static const char * statstr(const struct stat * st,
01040                 /*@returned@*/ /*@out@*/ char * buf)
01041         /*@modifies *buf @*/
01042 {
01043     sprintf(buf,
01044         "*** dev %x ino %x mode %0o nlink %d uid %d gid %d rdev %x size %x\n",
01045         (unsigned int)st->st_dev,
01046         (unsigned int)st->st_ino,
01047         (unsigned int)st->st_mode,
01048         (unsigned int)st->st_nlink,
01049         (unsigned int)st->st_uid,
01050         (unsigned int)st->st_gid,
01051         (unsigned int)st->st_rdev,
01052         (unsigned int)st->st_size);
01053     return buf;
01054 }
01055 
01056 /*@unchecked@*/
01057 static int ftp_st_ino = 0xdead0000;
01058 
01059 /* FIXME: borked for path with trailing '/' */
01060 static int ftpStat(const char * path, /*@out@*/ struct stat *st)
01061         /*@globals ftp_st_ino, h_errno, fileSystem, internalState @*/
01062         /*@modifies *st, ftp_st_ino, fileSystem, internalState @*/
01063 {
01064     char buf[1024];
01065     int rc;
01066     rc = ftpNLST(path, DO_FTP_STAT, st, NULL, 0);
01067     /* XXX fts(3) needs/uses st_ino, make something up for now. */
01068     if (st->st_ino == 0)
01069         st->st_ino = ftp_st_ino++;
01070 if (_ftp_debug)
01071 fprintf(stderr, "*** ftpStat(%s) rc %d\n%s", path, rc, statstr(st, buf));
01072     return rc;
01073 }
01074 
01075 /* FIXME: borked for path with trailing '/' */
01076 static int ftpLstat(const char * path, /*@out@*/ struct stat *st)
01077         /*@globals ftp_st_ino, h_errno, fileSystem, internalState @*/
01078         /*@modifies *st, ftp_st_ino, fileSystem, internalState @*/
01079 {
01080     char buf[1024];
01081     int rc;
01082     rc = ftpNLST(path, DO_FTP_LSTAT, st, NULL, 0);
01083     /* XXX fts(3) needs/uses st_ino, make something up for now. */
01084     if (st->st_ino == 0)
01085         st->st_ino = ftp_st_ino++;
01086 if (_ftp_debug)
01087 fprintf(stderr, "*** ftpLstat(%s) rc %d\n%s\n", path, rc, statstr(st, buf));
01088     return rc;
01089 }
01090 
01091 static int ftpReadlink(const char * path, /*@out@*/ char * buf, size_t bufsiz)
01092         /*@globals h_errno, fileSystem, internalState @*/
01093         /*@modifies *buf, fileSystem, internalState @*/
01094 {
01095     int rc;
01096     rc = ftpNLST(path, DO_FTP_READLINK, NULL, buf, bufsiz);
01097 if (_ftp_debug)
01098 fprintf(stderr, "*** ftpReadlink(%s) rc %d\n", path, rc);
01099     return rc;
01100 }
01101 
01102 /*@-boundswrite@*/
01103 /*@null@*/
01104 static DIR * ftpOpendir(const char * path)
01105         /*@globals h_errno, fileSystem, internalState @*/
01106         /*@modifies fileSystem, internalState @*/
01107 {
01108     AVDIR avdir;
01109     struct dirent * dp;
01110     size_t nb;
01111     const char * s, * sb, * se;
01112     const char ** av;
01113     unsigned char * dt;
01114     char * t;
01115     int ac;
01116     int c;
01117     int rc;
01118 
01119 if (_ftp_debug)
01120 fprintf(stderr, "*** ftpOpendir(%s)\n", path);
01121     rc = ftpNLST(path, DO_FTP_GLOB, NULL, NULL, 0);
01122     if (rc)
01123         return NULL;
01124 
01125     /*
01126      * ftpBuf now contains absolute paths, newline terminated.
01127      * Calculate the number of bytes to hold the directory info.
01128      */
01129     nb = sizeof(".") + sizeof("..");
01130     ac = 2;
01131     sb = NULL;
01132     s = se = ftpBuf;
01133     while ((c = *se) != '\0') {
01134         se++;
01135         switch (c) {
01136         case '/':
01137             sb = se;
01138             /*@switchbreak@*/ break;
01139         case '\r':
01140             if (sb == NULL) {
01141                 for (sb = se; sb > s && sb[-1] != ' '; sb--)
01142                     {};
01143             }
01144             ac++;
01145             nb += (se - sb);
01146 
01147             if (*se == '\n') se++;
01148             sb = NULL;
01149             s = se;
01150             /*@switchbreak@*/ break;
01151         default:
01152             /*@switchbreak@*/ break;
01153         }
01154     }
01155 
01156     nb += sizeof(*avdir) + sizeof(*dp) + ((ac + 1) * sizeof(*av)) + (ac + 1);
01157     avdir = xcalloc(1, nb);
01158     /*@-abstract@*/
01159     dp = (struct dirent *) (avdir + 1);
01160     av = (const char **) (dp + 1);
01161     dt = (char *) (av + (ac + 1));
01162     t = (char *) (dt + ac + 1);
01163     /*@=abstract@*/
01164 
01165     avdir->fd = avmagicdir;
01166 /*@-usereleased@*/
01167     avdir->data = (char *) dp;
01168 /*@=usereleased@*/
01169     avdir->allocation = nb;
01170     avdir->size = ac;
01171     avdir->offset = -1;
01172     avdir->filepos = 0;
01173 
01174 #if defined(HAVE_PTHREAD_H)
01175 /*@-moduncon -noeffectuncon@*/
01176     (void) pthread_mutex_init(&avdir->lock, NULL);
01177 /*@=moduncon =noeffectuncon@*/
01178 #endif
01179 
01180     ac = 0;
01181     /*@-dependenttrans -unrecog@*/
01182     dt[ac] = DT_DIR;    av[ac++] = t;   t = stpcpy(t, ".");     t++;
01183     dt[ac] = DT_DIR;    av[ac++] = t;   t = stpcpy(t, "..");    t++;
01184     /*@=dependenttrans =unrecog@*/
01185     sb = NULL;
01186     s = se = ftpBuf;
01187     while ((c = *se) != '\0') {
01188         se++;
01189         switch (c) {
01190         case '/':
01191             sb = se;
01192             /*@switchbreak@*/ break;
01193         case '\r':
01194             /*@-dependenttrans@*/
01195             av[ac] = t;
01196             /*@=dependenttrans@*/
01197             if (sb == NULL) {
01198                 /*@-unrecog@*/
01199                 switch(*s) {
01200                 case 'p':
01201                     dt[ac] = DT_FIFO;
01202                     /*@innerbreak@*/ break;
01203                 case 'c':
01204                     dt[ac] = DT_CHR;
01205                     /*@innerbreak@*/ break;
01206                 case 'd':
01207                     dt[ac] = DT_DIR;
01208                     /*@innerbreak@*/ break;
01209                 case 'b':
01210                     dt[ac] = DT_BLK;
01211                     /*@innerbreak@*/ break;
01212                 case '-':
01213                     dt[ac] = DT_REG;
01214                     /*@innerbreak@*/ break;
01215                 case 'l':
01216                     dt[ac] = DT_LNK;
01217                     /*@innerbreak@*/ break;
01218                 case 's':
01219                     dt[ac] = DT_SOCK;
01220                     /*@innerbreak@*/ break;
01221                 default:
01222                     dt[ac] = DT_UNKNOWN;
01223                     /*@innerbreak@*/ break;
01224                 }
01225                 /*@=unrecog@*/
01226                 for (sb = se; sb > s && sb[-1] != ' '; sb--)
01227                     {};
01228             }
01229             ac++;
01230             t = stpncpy(t, sb, (se - sb));
01231             t[-1] = '\0';
01232             if (*se == '\n') se++;
01233             sb = NULL;
01234             s = se;
01235             /*@switchbreak@*/ break;
01236         default:
01237             /*@switchbreak@*/ break;
01238         }
01239     }
01240     av[ac] = NULL;
01241 
01242 /*@-kepttrans@*/
01243     return (DIR *) avdir;
01244 /*@=kepttrans@*/
01245 }
01246 /*@=boundswrite@*/
01247 
01248 int Stat(const char * path, struct stat * st)
01249 {
01250     const char * lpath;
01251     int ut = urlPath(path, &lpath);
01252 
01253 if (_rpmio_debug)
01254 fprintf(stderr, "*** Stat(%s,%p)\n", path, st);
01255     switch (ut) {
01256     case URL_IS_FTP:
01257         return ftpStat(path, st);
01258         /*@notreached@*/ break;
01259     case URL_IS_PATH:
01260         path = lpath;
01261         /*@fallthrough@*/
01262     case URL_IS_UNKNOWN:
01263         break;
01264     case URL_IS_DASH:
01265     case URL_IS_HKP:
01266     default:
01267         return -2;
01268         /*@notreached@*/ break;
01269     }
01270     return stat(path, st);
01271 }
01272 
01273 int Lstat(const char * path, struct stat * st)
01274 {
01275     const char * lpath;
01276     int ut = urlPath(path, &lpath);
01277 
01278 if (_rpmio_debug)
01279 fprintf(stderr, "*** Lstat(%s,%p)\n", path, st);
01280     switch (ut) {
01281     case URL_IS_FTP:
01282         return ftpLstat(path, st);
01283         /*@notreached@*/ break;
01284     case URL_IS_PATH:
01285         path = lpath;
01286         /*@fallthrough@*/
01287     case URL_IS_UNKNOWN:
01288         break;
01289     case URL_IS_DASH:
01290     case URL_IS_HKP:
01291     default:
01292         return -2;
01293         /*@notreached@*/ break;
01294     }
01295     return lstat(path, st);
01296 }
01297 
01298 int Readlink(const char * path, char * buf, size_t bufsiz)
01299 {
01300     const char * lpath;
01301     int ut = urlPath(path, &lpath);
01302 
01303     switch (ut) {
01304     case URL_IS_FTP:
01305         return ftpReadlink(path, buf, bufsiz);
01306         /*@notreached@*/ break;
01307     case URL_IS_PATH:
01308         path = lpath;
01309         /*@fallthrough@*/
01310     case URL_IS_UNKNOWN:
01311         break;
01312     case URL_IS_DASH:
01313     case URL_IS_HKP:
01314     default:
01315         return -2;
01316         /*@notreached@*/ break;
01317     }
01318 /*@-compdef@*/ /* FIX: *buf is undefined */
01319     return readlink(path, buf, bufsiz);
01320 /*@=compdef@*/
01321 }
01322 
01323 int Access(const char * path, int amode)
01324 {
01325     const char * lpath;
01326     int ut = urlPath(path, &lpath);
01327 
01328 if (_rpmio_debug)
01329 fprintf(stderr, "*** Access(%s,%d)\n", path, amode);
01330     switch (ut) {
01331     case URL_IS_HTTPS:          /* XXX WRONG WRONG WRONG */
01332     case URL_IS_HTTP:           /* XXX WRONG WRONG WRONG */
01333     case URL_IS_FTP:            /* XXX WRONG WRONG WRONG */
01334     case URL_IS_PATH:
01335         path = lpath;
01336         /*@fallthrough@*/
01337     case URL_IS_UNKNOWN:
01338         break;
01339     case URL_IS_DASH:
01340     case URL_IS_HKP:
01341     default:
01342         return -2;
01343         /*@notreached@*/ break;
01344     }
01345     return access(path, amode);
01346 }
01347 
01348 /* glob_pattern_p() taken from bash
01349  * Copyright (C) 1985, 1988, 1989 Free Software Foundation, Inc.
01350  *
01351  * Return nonzero if PATTERN has any special globbing chars in it.
01352  */
01353 int Glob_pattern_p (const char * pattern, int quote)
01354 {
01355     const char *p;
01356     int open = 0;
01357     char c;
01358   
01359     (void) urlPath(pattern, &p);
01360     while ((c = *p++) != '\0')
01361         switch (c) {
01362         case '?':
01363         case '*':
01364             return (1);
01365         case '\\':
01366             if (quote && p[1] != '\0')
01367                 p++;
01368             continue;
01369 
01370         case '[':
01371             open = 1;
01372             continue;
01373         case ']':
01374             if (open)
01375                 return (1);
01376             continue;
01377 
01378         case '+':
01379         case '@':
01380         case '!':
01381             if (*p == '(')
01382                 return (1);
01383             continue;
01384         }
01385 
01386     return (0);
01387 }
01388 
01389 int Glob_error(/*@unused@*/const char * epath, /*@unused@*/ int eerrno)
01390 {
01391     return 1;
01392 }
01393 
01394 int Glob(const char *pattern, int flags,
01395         int errfunc(const char * epath, int eerrno), glob_t *pglob)
01396 {
01397     const char * lpath;
01398     int ut = urlPath(pattern, &lpath);
01399 
01400 /*@-castfcnptr@*/
01401 if (_rpmio_debug)
01402 fprintf(stderr, "*** Glob(%s,0x%x,%p,%p)\n", pattern, (unsigned)flags, (void *)errfunc, pglob);
01403 /*@=castfcnptr@*/
01404     switch (ut) {
01405     case URL_IS_HTTPS:
01406     case URL_IS_HTTP:
01407     case URL_IS_FTP:
01408 /*@-type@*/
01409         pglob->gl_closedir = Closedir;
01410         pglob->gl_readdir = Readdir;
01411         pglob->gl_opendir = Opendir;
01412         pglob->gl_lstat = Lstat;
01413         pglob->gl_stat = Stat;
01414 /*@=type@*/
01415         flags |= GLOB_ALTDIRFUNC;
01416         flags &= ~GLOB_TILDE;
01417         break;
01418     case URL_IS_PATH:
01419         pattern = lpath;
01420         /*@fallthrough@*/
01421     case URL_IS_UNKNOWN:
01422         break;
01423     case URL_IS_DASH:
01424     case URL_IS_HKP:
01425     default:
01426         return -2;
01427         /*@notreached@*/ break;
01428     }
01429     return glob(pattern, flags, errfunc, pglob);
01430 }
01431 
01432 void Globfree(glob_t *pglob)
01433 {
01434 if (_rpmio_debug)
01435 fprintf(stderr, "*** Globfree(%p)\n", pglob);
01436     globfree(pglob);
01437 }
01438 
01439 DIR * Opendir(const char * path)
01440 {
01441     const char * lpath;
01442     int ut = urlPath(path, &lpath);
01443 
01444 if (_rpmio_debug)
01445 fprintf(stderr, "*** Opendir(%s)\n", path);
01446     switch (ut) {
01447     case URL_IS_FTP:
01448         return ftpOpendir(path);
01449         /*@notreached@*/ break;
01450     case URL_IS_PATH:
01451         path = lpath;
01452         /*@fallthrough@*/
01453     case URL_IS_UNKNOWN:
01454         break;
01455     case URL_IS_DASH:
01456     case URL_IS_HKP:
01457     default:
01458         return NULL;
01459         /*@notreached@*/ break;
01460     }
01461     /*@-dependenttrans@*/
01462     return opendir(path);
01463     /*@=dependenttrans@*/
01464 }
01465 
01466 struct dirent * Readdir(DIR * dir)
01467 {
01468 if (_rpmio_debug)
01469 fprintf(stderr, "*** Readdir(%p)\n", (void *)dir);
01470     if (dir == NULL)
01471         return NULL;
01472     if (ISAVMAGIC(dir))
01473         return avReaddir(dir);
01474     return readdir(dir);
01475 }
01476 
01477 int Closedir(DIR * dir)
01478 {
01479 if (_rpmio_debug)
01480 fprintf(stderr, "*** Closedir(%p)\n", (void *)dir);
01481     if (dir == NULL)
01482         return 0;
01483     if (ISAVMAGIC(dir))
01484         return avClosedir(dir);
01485     return closedir(dir);
01486 }

Generated on Tue Feb 19 22:27:03 2008 for rpm by  doxygen 1.5.1