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 
00010 #include "stringbuf.h"
00011 #include "manifest.h"
00012 #include "misc.h"
00013 #include "debug.h"
00014 
00015 /*@access StringBuf @*/
00016 
00017 /*@-boundswrite@*/
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 /*@=boundswrite@*/
00065 
00067 /*@-boundsread@*/
00068 int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr)
00069 {
00070     StringBuf sb = newStringBuf();
00071     char * s = NULL;
00072     char * se;
00073     int ac = 0;
00074     const char ** av = NULL;
00075     int argc = (argcPtr ? *argcPtr : 0);
00076     const char ** argv = (argvPtr ? *argvPtr : NULL);
00077 /*@+voidabstract@*/
00078     FILE * f = (FILE *) fdGetFp(fd);
00079 /*@=voidabstract@*/
00080     int rc = 0;
00081     int i;
00082 
00083 /*@-boundswrite@*/
00084     if (f != NULL)
00085     while (1) {
00086         char line[BUFSIZ];
00087 
00088         /* Read next line. */
00089         s = fgets(line, sizeof(line) - 1, f);
00090         if (s == NULL) {
00091             /* XXX Ferror check needed */
00092             break;
00093         }
00094 
00095         /* Skip comments. */
00096         if ((se = strchr(s, '#')) != NULL) *se = '\0';
00097 
00098         /* Trim white space. */
00099         se = s + strlen(s);
00100         while (se > s && (se[-1] == '\n' || se[-1] == '\r'))
00101             *(--se) = '\0';
00102         while (*s && strchr(" \f\n\r\t\v", *s) != NULL)
00103             s++;
00104         if (*s == '\0') continue;
00105 
00106         /* Insure that file contains only ASCII */
00107         if (*s < 32) {
00108             rc = 1;
00109             goto exit;
00110         }
00111 
00112         /* Concatenate next line in buffer. */
00113         *se++ = ' ';
00114         *se = '\0';
00115         appendStringBuf(sb, s);
00116     }
00117 
00118     /*@-branchstate@*/
00119     if (s == NULL)              /* XXX always true */
00120         s = getStringBuf(sb);
00121     /*@=branchstate@*/
00122 
00123     if (!(s && *s)) {
00124         rc = 1;
00125         goto exit;
00126     }
00127 
00128     /* Glob manifest items. */
00129     rc = rpmGlob(s, &ac, &av);
00130     if (rc) goto exit;
00131 
00132     /* Find 1st existing unprocessed arg. */
00133     for (i = 0; i < argc; i++)
00134         if (argv && argv[i]) break;
00135 
00136     /* Concatenate existing unprocessed args after manifest contents. */
00137     if (argv && i < argc) {
00138         int nac = ac + (argc - i);
00139         const char ** nav = xcalloc((nac + 1), sizeof(*nav));
00140 
00141         if (ac)
00142             memcpy(nav, av, ac * sizeof(*nav));
00143         if ((argc - i) > 0)
00144             memcpy(nav + ac, argv + i, (argc - i) * sizeof(*nav));
00145         nav[nac] = NULL;
00146 
00147         if (argvPtr)
00148             *argvPtr = argv = _free(argv);
00149         av = _free(av);
00150         av = nav;
00151         ac = nac;
00152     }
00153 
00154     /* Save new argc/argv list. */
00155     if (argvPtr) {
00156         *argvPtr = _free(*argvPtr);
00157         *argvPtr = av;
00158     }
00159     if (argcPtr)
00160         *argcPtr = ac;
00161 /*@=boundswrite@*/
00162 
00163 exit:
00164     /*@-branchstate@*/
00165     if (argvPtr == NULL || (rc != 0 && av)) {
00166         if (av)
00167 /*@-boundswrite@*/
00168         for (i = 0; i < ac; i++)
00169             /*@-unqualifiedtrans@*/av[i] = _free(av[i]); /*@=unqualifiedtrans@*/
00170 /*@=boundswrite@*/
00171         /*@-dependenttrans@*/ av = _free(av); /*@=dependenttrans@*/
00172     }
00173     /*@=branchstate@*/
00174     sb = freeStringBuf(sb);
00175     /*@-nullstate@*/ /* FIX: *argvPtr may be NULL. */
00176     return rc;
00177     /*@=nullstate@*/
00178 }
00179 /*@=boundsread@*/

Generated on Sun Oct 26 13:01:59 2003 for rpm by doxygen1.2.18