Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

lib/manifest.c

Go to the documentation of this file.
00001 
00005 #include "system.h"
00006 
00007 #include <rpmio_internal.h>
00008 #include <rpmlib.h>
00009 #include <rpmmacro.h>
00010 
00011 #include "stringbuf.h"
00012 #include "manifest.h"
00013 #include "misc.h"
00014 #include "debug.h"
00015 
00016 /*@access StringBuf @*/
00017 
00018 /*@-boundswrite@*/
00019 char * rpmPermsString(int mode)
00020 {
00021     char *perms = xstrdup("----------");
00022    
00023     if (S_ISREG(mode)) 
00024         perms[0] = '-';
00025     else if (S_ISDIR(mode)) 
00026         perms[0] = 'd';
00027     else if (S_ISLNK(mode))
00028         perms[0] = 'l';
00029     else if (S_ISFIFO(mode)) 
00030         perms[0] = 'p';
00031     /*@-unrecog@*/
00032     else if (S_ISSOCK(mode)) 
00033         perms[0] = 's';
00034     /*@=unrecog@*/
00035     else if (S_ISCHR(mode))
00036         perms[0] = 'c';
00037     else if (S_ISBLK(mode))
00038         perms[0] = 'b';
00039     else
00040         perms[0] = '?';
00041 
00042     if (mode & S_IRUSR) perms[1] = 'r';
00043     if (mode & S_IWUSR) perms[2] = 'w';
00044     if (mode & S_IXUSR) perms[3] = 'x';
00045  
00046     if (mode & S_IRGRP) perms[4] = 'r';
00047     if (mode & S_IWGRP) perms[5] = 'w';
00048     if (mode & S_IXGRP) perms[6] = 'x';
00049 
00050     if (mode & S_IROTH) perms[7] = 'r';
00051     if (mode & S_IWOTH) perms[8] = 'w';
00052     if (mode & S_IXOTH) perms[9] = 'x';
00053 
00054     if (mode & S_ISUID)
00055         perms[3] = ((mode & S_IXUSR) ? 's' : 'S'); 
00056 
00057     if (mode & S_ISGID)
00058         perms[6] = ((mode & S_IXGRP) ? 's' : 'S'); 
00059 
00060     if (mode & S_ISVTX)
00061         perms[9] = ((mode & S_IXOTH) ? 't' : 'T');
00062 
00063     return perms;
00064 }
00065 /*@=boundswrite@*/
00066 
00068 /*@-boundsread@*/
00069 rpmRC rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr)
00070 {
00071     StringBuf sb = newStringBuf();
00072     char * s = NULL;
00073     char * se;
00074     int ac = 0;
00075     const char ** av = NULL;
00076     int argc = (argcPtr ? *argcPtr : 0);
00077     const char ** argv = (argvPtr ? *argvPtr : NULL);
00078     FD_t xfd;
00079     FILE * f;
00080     rpmRC rpmrc = RPMRC_OK;
00081     int i, j, next, npre;
00082 
00083 /*@-boundswrite@*/
00084 /*@-branchstate@*/
00085     if (fdGetFp(fd) == NULL)
00086         xfd = Fdopen(fd, "r.fpio");
00087     else
00088         xfd = fd;
00089 /*@=branchstate@*/
00090 
00091 /*@+voidabstract@*/
00092     if ((f = (FILE *) fdGetFp(xfd)) == NULL) {
00093 /*@=voidabstract@*/
00094         rpmrc = RPMRC_NOTFOUND;
00095         goto exit;
00096     }
00097 
00098     while (1) {
00099         char line[BUFSIZ];
00100 
00101         /* Read next line. */
00102         s = fgets(line, sizeof(line) - 1, f);
00103         if (s == NULL) {
00104             /* XXX Ferror check needed */
00105             break;
00106         }
00107 
00108         /* XXX stop processing manifest if HTML is found. */
00109 #define DOCTYPE_HTML_PUBLIC     "<!DOCTYPE HTML PUBLIC"
00110         if (!strncmp(line, DOCTYPE_HTML_PUBLIC, sizeof(DOCTYPE_HTML_PUBLIC)-1)) {
00111             rpmrc = RPMRC_NOTFOUND;
00112             goto exit;
00113         }
00114 
00115         /* Skip comments. */
00116         if ((se = strchr(s, '#')) != NULL) *se = '\0';
00117 
00118         /* Trim white space. */
00119         se = s + strlen(s);
00120         while (se > s && (se[-1] == '\n' || se[-1] == '\r'))
00121             *(--se) = '\0';
00122         while (*s && strchr(" \f\n\r\t\v", *s) != NULL)
00123             s++;
00124         if (*s == '\0') continue;
00125 
00126         /* Insure that file contains only ASCII */
00127         if (*s < 32) {
00128             rpmrc = RPMRC_NOTFOUND;
00129             goto exit;
00130         }
00131 
00132         /* Concatenate next line in buffer. */
00133         *se++ = ' ';
00134         *se = '\0';
00135         appendStringBuf(sb, s);
00136     }
00137 
00138     /*@-branchstate@*/
00139     if (s == NULL)              /* XXX always true */
00140         s = getStringBuf(sb);
00141     /*@=branchstate@*/
00142 
00143     if (!(s && *s)) {
00144         rpmrc = RPMRC_NOTFOUND;
00145         goto exit;
00146     }
00147 
00148     /* Glob manifest items. */
00149     rpmrc = rpmGlob(s, &ac, &av);
00150     if (rpmrc != RPMRC_OK) goto exit;
00151 
00152     rpmMessage(RPMMESS_DEBUG, D_("adding %d args from manifest.\n"), ac);
00153 
00154     /* Count non-NULL args, keeping track of 1st arg after last NULL. */
00155     npre = 0;
00156     next = 0;
00157     if (argv != NULL)
00158     for (i = 0; i < argc; i++) {
00159         if (argv[i] != NULL)
00160             npre++;
00161         else if (i >= next)
00162             next = i + 1;
00163     }
00164 
00165     /* Copy old arg list, inserting manifest before argv[next]. */
00166     if (argv != NULL) {
00167         int nac = npre + ac;
00168         const char ** nav = xcalloc((nac + 1), sizeof(*nav));
00169 
00170         for (i = 0, j = 0; i < next; i++) {
00171             if (argv[i] != NULL)
00172                 nav[j++] = argv[i];
00173         }
00174 
00175         if (ac)
00176             memcpy(nav + j, av, ac * sizeof(*nav));
00177         if ((argc - next) > 0)
00178             memcpy(nav + j + ac, argv + next, (argc - next) * sizeof(*nav));
00179         nav[nac] = NULL;
00180 
00181         if (argvPtr)
00182             *argvPtr = argv = _free(argv);
00183         av = _free(av);
00184         av = nav;
00185         ac = nac;
00186     }
00187 
00188     /* Save new argc/argv list. */
00189     if (argvPtr) {
00190         *argvPtr = _free(*argvPtr);
00191         *argvPtr = av;
00192     }
00193     if (argcPtr)
00194         *argcPtr = ac;
00195 /*@=boundswrite@*/
00196 
00197 exit:
00198     /*@-branchstate@*/
00199     if (argvPtr == NULL || (rpmrc != RPMRC_OK && av)) {
00200         if (av)
00201 /*@-boundswrite@*/
00202         for (i = 0; i < ac; i++)
00203             /*@-unqualifiedtrans@*/av[i] = _free(av[i]); /*@=unqualifiedtrans@*/
00204 /*@=boundswrite@*/
00205         /*@-dependenttrans@*/ av = _free(av); /*@=dependenttrans@*/
00206     }
00207     /*@=branchstate@*/
00208     sb = freeStringBuf(sb);
00209     /*@-nullstate@*/ /* FIX: *argvPtr may be NULL. */
00210     return rpmrc;
00211     /*@=nullstate@*/
00212 }
00213 /*@=boundsread@*/

Generated on Mon Aug 23 10:33:19 2010 for rpm by  doxygen 1.4.4