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
00016
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
00031 else if (S_ISSOCK(mode))
00032 perms[0] = 's';
00033
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
00065
00067
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
00078 FILE * f = (FILE *) fdGetFp(fd);
00079
00080 int rc = 0;
00081 int i;
00082
00083
00084 if (f != NULL)
00085 while (1) {
00086 char line[BUFSIZ];
00087
00088
00089 s = fgets(line, sizeof(line) - 1, f);
00090 if (s == NULL) {
00091
00092 break;
00093 }
00094
00095
00096 if ((se = strchr(s, '#')) != NULL) *se = '\0';
00097
00098
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
00107 if (*s < 32) {
00108 rc = 1;
00109 goto exit;
00110 }
00111
00112
00113 *se++ = ' ';
00114 *se = '\0';
00115 appendStringBuf(sb, s);
00116 }
00117
00118
00119 if (s == NULL)
00120 s = getStringBuf(sb);
00121
00122
00123 if (!(s && *s)) {
00124 rc = 1;
00125 goto exit;
00126 }
00127
00128
00129 rc = rpmGlob(s, &ac, &av);
00130 if (rc) goto exit;
00131
00132
00133 for (i = 0; i < argc; i++)
00134 if (argv && argv[i]) break;
00135
00136
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
00155 if (argvPtr) {
00156 *argvPtr = _free(*argvPtr);
00157 *argvPtr = av;
00158 }
00159 if (argcPtr)
00160 *argcPtr = ac;
00161
00162
00163 exit:
00164
00165 if (argvPtr == NULL || (rc != 0 && av)) {
00166 if (av)
00167
00168 for (i = 0; i < ac; i++)
00169 av[i] = _free(av[i]);
00170
00171 av = _free(av);
00172 }
00173
00174 sb = freeStringBuf(sb);
00175
00176 return rc;
00177
00178 }
00179