~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to lib/manifest.c

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** \ingroup rpmcli
 
2
 * \file lib/manifest.c
 
3
 */
 
4
 
 
5
#include "system.h"
 
6
 
 
7
#include <rpmlib.h>
 
8
#include <rpmio_internal.h>
 
9
#include "stringbuf.h"
 
10
#include "manifest.h"
 
11
#include "misc.h"
 
12
#include "debug.h"
 
13
 
 
14
/*@access StringBuf @*/
 
15
 
 
16
char * rpmPermsString(int mode)
 
17
{
 
18
    char *perms = xstrdup("----------");
 
19
   
 
20
    if (S_ISDIR(mode)) 
 
21
        perms[0] = 'd';
 
22
    else if (S_ISLNK(mode))
 
23
        perms[0] = 'l';
 
24
    else if (S_ISFIFO(mode)) 
 
25
        perms[0] = 'p';
 
26
    else if (S_ISSOCK(mode)) 
 
27
        perms[0] = 's';
 
28
    else if (S_ISCHR(mode))
 
29
        perms[0] = 'c';
 
30
    else if (S_ISBLK(mode))
 
31
        perms[0] = 'b';
 
32
 
 
33
    /*@-unrecog@*/
 
34
    if (mode & S_IRUSR) perms[1] = 'r';
 
35
    if (mode & S_IWUSR) perms[2] = 'w';
 
36
    if (mode & S_IXUSR) perms[3] = 'x';
 
37
 
 
38
    if (mode & S_IRGRP) perms[4] = 'r';
 
39
    if (mode & S_IWGRP) perms[5] = 'w';
 
40
    if (mode & S_IXGRP) perms[6] = 'x';
 
41
 
 
42
    if (mode & S_IROTH) perms[7] = 'r';
 
43
    if (mode & S_IWOTH) perms[8] = 'w';
 
44
    if (mode & S_IXOTH) perms[9] = 'x';
 
45
 
 
46
    if (mode & S_ISUID)
 
47
        perms[3] = ((mode & S_IXUSR) ? 's' : 'S'); 
 
48
 
 
49
    if (mode & S_ISGID)
 
50
        perms[6] = ((mode & S_IXGRP) ? 's' : 'S'); 
 
51
 
 
52
    if (mode & S_ISVTX)
 
53
        perms[9] = ((mode & S_IXOTH) ? 't' : 'T');
 
54
    /*@=unrecog@*/
 
55
 
 
56
    return perms;
 
57
}
 
58
 
 
59
/**@todo Infinite loops through manifest files exist, operator error for now. */
 
60
int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr)
 
61
{
 
62
    StringBuf sb = newStringBuf();
 
63
    char * s = NULL;
 
64
    char * se;
 
65
    int ac = 0;
 
66
    const char ** av = NULL;
 
67
    int argc = (argcPtr ? *argcPtr : 0);
 
68
    const char ** argv = (argvPtr ? *argvPtr : NULL);
 
69
    FILE * f = fdGetFp(fd);
 
70
    int rc = 0;
 
71
    int i;
 
72
 
 
73
    if (f != NULL)
 
74
    while (1) {
 
75
        char line[BUFSIZ];
 
76
 
 
77
        /* Read next line. */
 
78
        s = fgets(line, sizeof(line) - 1, f);
 
79
        if (s == NULL) {
 
80
            /* XXX Ferror check needed */
 
81
            break;
 
82
        }
 
83
 
 
84
        /* Skip comments. */
 
85
        if ((se = strchr(s, '#')) != NULL) *se = '\0';
 
86
 
 
87
        /* Trim white space. */
 
88
        se = s + strlen(s);
 
89
        while (se > s && (se[-1] == '\n' || se[-1] == '\r'))
 
90
            *(--se) = '\0';
 
91
        while (*s && strchr(" \f\n\r\t\v", *s) != NULL)
 
92
            s++;
 
93
        if (*s == '\0') continue;
 
94
 
 
95
        /* Insure that file contains only ASCII */
 
96
        if (*s < 32) {
 
97
            rc = 1;
 
98
            goto exit;
 
99
        }
 
100
 
 
101
        /* Concatenate next line in buffer. */
 
102
        *se++ = ' ';
 
103
        *se = '\0';
 
104
        appendStringBuf(sb, s);
 
105
    }
 
106
 
 
107
    if (s == NULL)              /* XXX always true */
 
108
        s = getStringBuf(sb);
 
109
 
 
110
    if (!(s && *s)) {
 
111
        rc = 1;
 
112
        goto exit;
 
113
    }
 
114
 
 
115
    /* Glob manifest items. */
 
116
    rc = rpmGlob(s, &ac, &av);
 
117
    if (rc) goto exit;
 
118
 
 
119
    /* Find 1st existing unprocessed arg. */
 
120
    for (i = 0; i < argc; i++)
 
121
        if (argv && argv[i]) break;
 
122
 
 
123
    /* Concatenate existing unprocessed args after manifest contents. */
 
124
    if (argv && i < argc) {
 
125
        int nac = ac + (argc - i);
 
126
        const char ** nav = xcalloc((nac + 1), sizeof(*nav));
 
127
 
 
128
        if (ac)
 
129
            memcpy(nav, av, ac * sizeof(*nav));
 
130
        if ((argc - i) > 0)
 
131
            memcpy(nav + ac, argv + i, (argc - i) * sizeof(*nav));
 
132
        nav[nac] = NULL;
 
133
 
 
134
        if (argvPtr)
 
135
            *argvPtr = argv = _free(argv);
 
136
        av = _free(av);
 
137
        av = nav;
 
138
        ac = nac;
 
139
    }
 
140
 
 
141
    /* Save new argc/argv list. */
 
142
    if (argvPtr) {
 
143
        *argvPtr = _free(*argvPtr);
 
144
        *argvPtr = av;
 
145
    }
 
146
    if (argcPtr)
 
147
        *argcPtr = ac;
 
148
 
 
149
exit:
 
150
    if (argvPtr == NULL || (rc != 0 && av)) {
 
151
        if (av)
 
152
        for (i = 0; i < ac; i++)
 
153
            /*@-unqualifiedtrans@*/av[i] = _free(av[i]); /*@=unqualifiedtrans@*/
 
154
        /*@-dependenttrans@*/ av = _free(av); /*@=dependenttrans@*/
 
155
    }
 
156
    sb = freeStringBuf(sb);
 
157
    /*@-nullstate@*/
 
158
    return rc;
 
159
    /*@=nullstate@*/
 
160
}