00001
00005 #include "system.h"
00006
00007 #include <rpmlib.h>
00008 #include <rpmio_internal.h>
00009 #include "stringbuf.h"
00010 #include "manifest.h"
00011 #include "misc.h"
00012 #include "debug.h"
00013
00014
00015
00016 char * rpmPermsString(int mode)
00017 {
00018 char *perms = xstrdup("----------");
00019
00020 if (S_ISDIR(mode))
00021 perms[0] = 'd';
00022 else if (S_ISLNK(mode))
00023 perms[0] = 'l';
00024 else if (S_ISFIFO(mode))
00025 perms[0] = 'p';
00026 else if (S_ISSOCK(mode))
00027 perms[0] = 's';
00028 else if (S_ISCHR(mode))
00029 perms[0] = 'c';
00030 else if (S_ISBLK(mode))
00031 perms[0] = 'b';
00032
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
00056 return perms;
00057 }
00058
00060 int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr)
00061 {
00062 StringBuf sb = newStringBuf();
00063 char * s = NULL;
00064 char * se;
00065 int ac = 0;
00066 const char ** av = NULL;
00067 int argc = (argcPtr ? *argcPtr : 0);
00068 const char ** argv = (argvPtr ? *argvPtr : NULL);
00069 FILE * f = fdGetFp(fd);
00070 int rc = 0;
00071 int i;
00072
00073 if (f != NULL)
00074 while (1) {
00075 char line[BUFSIZ];
00076
00077
00078 s = fgets(line, sizeof(line) - 1, f);
00079 if (s == NULL) {
00080
00081 break;
00082 }
00083
00084
00085 if ((se = strchr(s, '#')) != NULL) *se = '\0';
00086
00087
00088 se = s + strlen(s);
00089 while (se > s && (se[-1] == '\n' || se[-1] == '\r'))
00090 *(--se) = '\0';
00091 while (*s && strchr(" \f\n\r\t\v", *s) != NULL)
00092 s++;
00093 if (*s == '\0') continue;
00094
00095
00096 if (*s < 32) {
00097 rc = 1;
00098 goto exit;
00099 }
00100
00101
00102 *se++ = ' ';
00103 *se = '\0';
00104 appendStringBuf(sb, s);
00105 }
00106
00107 if (s == NULL)
00108 s = getStringBuf(sb);
00109
00110 if (!(s && *s)) {
00111 rc = 1;
00112 goto exit;
00113 }
00114
00115
00116 rc = rpmGlob(s, &ac, &av);
00117 if (rc) goto exit;
00118
00119
00120 for (i = 0; i < argc; i++)
00121 if (argv && argv[i]) break;
00122
00123
00124 if (argv && i < argc) {
00125 int nac = ac + (argc - i);
00126 const char ** nav = xcalloc((nac + 1), sizeof(*nav));
00127
00128 if (ac)
00129 memcpy(nav, av, ac * sizeof(*nav));
00130 if ((argc - i) > 0)
00131 memcpy(nav + ac, argv + i, (argc - i) * sizeof(*nav));
00132 nav[nac] = NULL;
00133
00134 if (argvPtr)
00135 *argvPtr = argv = _free(argv);
00136 av = _free(av);
00137 av = nav;
00138 ac = nac;
00139 }
00140
00141
00142 if (argvPtr) {
00143 *argvPtr = _free(*argvPtr);
00144 *argvPtr = av;
00145 }
00146 if (argcPtr)
00147 *argcPtr = ac;
00148
00149 exit:
00150 if (argvPtr == NULL || (rc != 0 && av)) {
00151 if (av)
00152 for (i = 0; i < ac; i++)
00153 av[i] = _free(av[i]);
00154 av = _free(av);
00155 }
00156 sb = freeStringBuf(sb);
00157
00158 return rc;
00159
00160 }