- Main Page
- Related Pages
- Modules
- Data Structures
- Files

# lib/manifest.c

Go to the documentation of this file.

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