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