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