7 #include <rpm/rpmlog.h>
8 #include <rpm/rpmfileutil.h>
11 #include "lib/manifest.h"
16 char * rpmPermsString(int mode)
18 char *perms = xstrdup("----------");
22 else if (S_ISDIR(mode))
24 else if (S_ISLNK(mode))
26 else if (S_ISFIFO(mode))
28 else if (S_ISSOCK(mode))
30 else if (S_ISCHR(mode))
32 else if (S_ISBLK(mode))
37 if (mode & S_IRUSR) perms[1] = 'r';
38 if (mode & S_IWUSR) perms[2] = 'w';
39 if (mode & S_IXUSR) perms[3] = 'x';
41 if (mode & S_IRGRP) perms[4] = 'r';
42 if (mode & S_IWGRP) perms[5] = 'w';
43 if (mode & S_IXGRP) perms[6] = 'x';
45 if (mode & S_IROTH) perms[7] = 'r';
46 if (mode & S_IWOTH) perms[8] = 'w';
47 if (mode & S_IXOTH) perms[9] = 'x';
50 perms[3] = ((mode & S_IXUSR) ? 's' : 'S');
53 perms[6] = ((mode & S_IXGRP) ? 's' : 'S');
56 perms[9] = ((mode & S_IXOTH) ? 't' : 'T');
61 /**@todo Infinite loops through manifest files exist, operator error for now. */
62 rpmRC rpmReadPackageManifest(FD_t fd, int * argcPtr, char *** argvPtr)
69 int argc = (argcPtr ? *argcPtr : 0);
70 char ** argv = (argvPtr ? *argvPtr : NULL);
71 FILE * f = fdopen(Fileno(fd), "r");
72 rpmRC rpmrc = RPMRC_OK;
80 s = fgets(line, sizeof(line) - 1, f);
82 /* XXX Ferror check needed */
87 if ((se = strchr(s, '#')) != NULL) *se = '\0';
89 /* Trim white space. */
91 while (se > s && (se[-1] == '\n' || se[-1] == '\r'))
93 while (*s && strchr(" \f\n\r\t\v", *s) != NULL)
95 if (*s == '\0') continue;
97 /* Sanity checks: skip obviously binary lines and dash (for stdin) */
98 if (*s < 32 || rstreq(s, "-")) {
100 rpmrc = RPMRC_NOTFOUND;
104 /* Concatenate next line in buffer. */
109 s = argvJoin(sb, " ");
112 rpmrc = RPMRC_NOTFOUND;
116 /* Glob manifest items. */
117 rpmrc = (rpmGlob(s, &ac, &av) == 0 ? RPMRC_OK : RPMRC_FAIL);
118 if (rpmrc != RPMRC_OK) goto exit;
120 rpmlog(RPMLOG_DEBUG, "adding %d args from manifest.\n", ac);
122 /* Count non-NULL args, keeping track of 1st arg after last NULL. */
126 for (i = 0; i < argc; i++) {
133 /* Copy old arg list, inserting manifest before argv[next]. */
136 char ** nav = xcalloc((nac + 1), sizeof(*nav));
138 for (i = 0, j = 0; i < next; i++) {
144 memcpy(nav + j, av, ac * sizeof(*nav));
145 if ((argc - next) > 0)
146 memcpy(nav + j + ac, argv + next, (argc - next) * sizeof(*nav));
150 *argvPtr = argv = _free(argv);
156 /* Save new argc/argv list. */
158 *argvPtr = _free(*argvPtr);
165 if (argvPtr == NULL || (rpmrc != RPMRC_OK && av)) {
167 for (i = 0; i < ac; i++)
168 av[i] = _free(av[i]);
173 /* FIX: *argvPtr may be NULL. */