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 char * rpmPermsString(int mode)
00018 {
00019 char *perms = xstrdup("----------");
00020
00021 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 else if (S_ISSOCK(mode))
00028 perms[0] = 's';
00029 else if (S_ISCHR(mode))
00030 perms[0] = 'c';
00031 else if (S_ISBLK(mode))
00032 perms[0] = 'b';
00033
00034 if (mode & S_IRUSR) perms[1] = 'r';
00035 if (mode & S_IWUSR) perms[2] = 'w';
00036 if (mode & S_IXUSR) perms[3] = 'x';
00037
00038 if (mode & S_IRGRP) perms[4] = 'r';
00039 if (mode & S_IWGRP) perms[5] = 'w';
00040 if (mode & S_IXGRP) perms[6] = 'x';
00041
00042 if (mode & S_IROTH) perms[7] = 'r';
00043 if (mode & S_IWOTH) perms[8] = 'w';
00044 if (mode & S_IXOTH) perms[9] = 'x';
00045
00046 if (mode & S_ISUID)
00047 perms[3] = ((mode & S_IXUSR) ? 's' : 'S');
00048
00049 if (mode & S_ISGID)
00050 perms[6] = ((mode & S_IXGRP) ? 's' : 'S');
00051
00052 if (mode & S_ISVTX)
00053 perms[9] = ((mode & S_IXOTH) ? 't' : 'T');
00054
00055 return perms;
00056 }
00057
00059 int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr)
00060 {
00061 StringBuf sb = newStringBuf();
00062 char * s = NULL;
00063 char * se;
00064 int ac = 0;
00065 const char ** av = NULL;
00066 int argc = (argcPtr ? *argcPtr : 0);
00067 const char ** argv = (argvPtr ? *argvPtr : NULL);
00068 FILE * f = fdGetFp(fd);
00069 int rc = 0;
00070 int i;
00071
00072 if (f != NULL)
00073 while (1) {
00074 char line[BUFSIZ];
00075
00076
00077 s = fgets(line, sizeof(line) - 1, f);
00078 if (s == NULL) {
00079
00080 break;
00081 }
00082
00083
00084 if ((se = strchr(s, '#')) != NULL) *se = '\0';
00085
00086
00087 se = s + strlen(s);
00088 while (se > s && (se[-1] == '\n' || se[-1] == '\r'))
00089 *(--se) = '\0';
00090 while (*s && strchr(" \f\n\r\t\v", *s) != NULL)
00091 s++;
00092 if (*s == '\0') continue;
00093
00094
00095 if (*s < 32) {
00096 rc = 1;
00097 goto exit;
00098 }
00099
00100
00101 *se++ = ' ';
00102 *se = '\0';
00103 appendStringBuf(sb, s);
00104 }
00105
00106 if (s == NULL)
00107 s = getStringBuf(sb);
00108
00109 if (!(s && *s)) {
00110 rc = 1;
00111 goto exit;
00112 }
00113
00114
00115 rc = rpmGlob(s, &ac, &av);
00116 if (rc) goto exit;
00117
00118
00119 for (i = 0; i < argc; i++)
00120 if (argv && argv[i]) break;
00121
00122
00123 if (argv && i < argc) {
00124 int nac = ac + (argc - i);
00125 const char ** nav = xcalloc((nac + 1), sizeof(*nav));
00126
00127 if (ac)
00128 memcpy(nav, av, ac * sizeof(*nav));
00129 if ((argc - i) > 0)
00130 memcpy(nav + ac, argv + i, (argc - i) * sizeof(*nav));
00131 nav[nac] = NULL;
00132
00133 if (argvPtr)
00134 *argvPtr = argv = _free(argv);
00135 av = _free(av);
00136 av = nav;
00137 ac = nac;
00138 }
00139
00140
00141 if (argvPtr) {
00142 *argvPtr = _free(*argvPtr);
00143 *argvPtr = av;
00144 }
00145 if (argcPtr)
00146 *argcPtr = ac;
00147
00148 exit:
00149 if (argvPtr == NULL || (rc != 0 && av)) {
00150 if (av)
00151 for (i = 0; i < ac; i++)
00152 av[i] = _free(av[i]);
00153 av = _free(av);
00154 }
00155 sb = freeStringBuf(sb);
00156
00157 return rc;
00158
00159 }