~ubuntu-branches/ubuntu/gutsy/samba/gutsy-updates

« back to all changes in this revision

Viewing changes to source/popt/poptconfig.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2006-11-28 20:14:37 UTC
  • mfrom: (0.10.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061128201437-a6x4lzlhempazocp
Tags: 3.0.23d-1ubuntu1
* Merge from debian unstable.
* Drop python2.4-samba, replace with python-samba. Added Conflicts/Replaces
  on python2.4-samba
* Drop track-connection-dos.patch, ubuntu-winbind-panic.patch, 
  ubuntu-fix-ldap.patch, ubuntu-setlocale.patch, ubuntu-setlocale-fixes.patch
* Remaining Ubuntu changes:
  - Revert Debian's installation of mount.cifs and umount.cifs as suid
  - Comment out the default [homes] shares and add more verbose comments to
    explain what they do and how they work (closes: launchpad.net/27608)
  - Add a "valid users = %S" stanza to the commented-out [homes] section, to
    show users how to restrict access to \\server\username to only username.
  - Change the (commented-out) "printer admin" example to use "@lpadmin"
    instead of "@ntadmin", since the lpadmin group is used for spool admin.
  - Alter the panic-action script to encourage users to report their
    bugs in Ubuntu packages to Ubuntu, rather than reporting to Debian.
    Modify text to more closely match the Debian script
  - Munge our init script to deal with the fact that our implementation
    (or lack thereof) of log_daemon_msg and log_progress_msg differs
    from Debian's implementation of the same (Ubuntu #19691)
  - Kept ubuntu-auxsrc.patch: some auxilliary sources (undocumented in 
    previous changelogs)
  - Set default workgroup to MSHOME

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING
 
1
/** \ingroup popt
 
2
 * \file popt/poptconfig.c
 
3
 */
 
4
 
 
5
/* (C) 1998-2002 Red Hat, Inc. -- Licensing details are in the COPYING
2
6
   file accompanying popt source distributions, available from 
3
 
   ftp://ftp.redhat.com/pub/code/popt */
 
7
   ftp://ftp.rpm.org/pub/rpm/dist. */
4
8
 
5
9
#include "system.h"
6
10
#include "poptint.h"
7
11
 
8
 
static void configLine(poptContext con, char * line) {
 
12
/*@-compmempass@*/      /* FIX: item->option.longName kept, not dependent. */
 
13
static void configLine(poptContext con, char * line)
 
14
        /*@modifies con @*/
 
15
{
 
16
    /*@-type@*/
9
17
    int nameLength = strlen(con->appName);
10
 
    char * opt;
11
 
    struct poptAlias alias;
12
 
    char * entryType;
13
 
    char * longName = NULL;
14
 
    char shortName = '\0';
 
18
    /*@=type@*/
 
19
    const char * entryType;
 
20
    const char * opt;
 
21
    poptItem item = alloca(sizeof(*item));
 
22
    int i, j;
15
23
    
 
24
/*@-boundswrite@*/
 
25
    memset(item, 0, sizeof(*item));
 
26
 
 
27
    /*@-type@*/
16
28
    if (strncmp(line, con->appName, nameLength)) return;
 
29
    /*@=type@*/
 
30
 
17
31
    line += nameLength;
18
 
    if (!*line || !isspace(*line)) return;
19
 
    while (*line && isspace(*line)) line++;
 
32
    if (*line == '\0' || !isspace(*line)) return;
 
33
 
 
34
    while (*line != '\0' && isspace(*line)) line++;
20
35
    entryType = line;
 
36
    while (*line == '\0' || !isspace(*line)) line++;
 
37
    *line++ = '\0';
21
38
 
22
 
    while (!*line || !isspace(*line)) line++;
23
 
    *line++ = '\0';
24
 
    while (*line && isspace(*line)) line++;
25
 
    if (!*line) return;
 
39
    while (*line != '\0' && isspace(*line)) line++;
 
40
    if (*line == '\0') return;
26
41
    opt = line;
27
 
 
28
 
    while (!*line || !isspace(*line)) line++;
 
42
    while (*line == '\0' || !isspace(*line)) line++;
29
43
    *line++ = '\0';
30
 
    while (*line && isspace(*line)) line++;
31
 
    if (!*line) return;
32
 
 
 
44
 
 
45
    while (*line != '\0' && isspace(*line)) line++;
 
46
    if (*line == '\0') return;
 
47
 
 
48
    /*@-temptrans@*/ /* FIX: line alias is saved */
33
49
    if (opt[0] == '-' && opt[1] == '-')
34
 
        longName = opt + 2;
35
 
    else if (opt[0] == '-' && !opt[2])
36
 
        shortName = opt[1];
37
 
 
38
 
    if (!strcmp(entryType, "alias")) {
39
 
        if (poptParseArgvString(line, &alias.argc, &alias.argv)) return;
40
 
        alias.longName = longName, alias.shortName = shortName;
41
 
        poptAddAlias(con, alias, 0);
42
 
    } else if (!strcmp(entryType, "exec")) {
43
 
        con->execs = realloc(con->execs,
44
 
                                sizeof(*con->execs) * (con->numExecs + 1));
45
 
        if (longName)
46
 
            con->execs[con->numExecs].longName = xstrdup(longName);
47
 
        else
48
 
            con->execs[con->numExecs].longName = NULL;
49
 
 
50
 
        con->execs[con->numExecs].shortName = shortName;
51
 
        con->execs[con->numExecs].script = xstrdup(line);
52
 
        
53
 
        con->numExecs++;
54
 
    }
 
50
        item->option.longName = opt + 2;
 
51
    else if (opt[0] == '-' && opt[2] == '\0')
 
52
        item->option.shortName = opt[1];
 
53
    /*@=temptrans@*/
 
54
 
 
55
    if (poptParseArgvString(line, &item->argc, &item->argv)) return;
 
56
 
 
57
    /*@-modobserver@*/
 
58
    item->option.argInfo = POPT_ARGFLAG_DOC_HIDDEN;
 
59
    for (i = 0, j = 0; i < item->argc; i++, j++) {
 
60
        const char * f;
 
61
        if (!strncmp(item->argv[i], "--POPTdesc=", sizeof("--POPTdesc=")-1)) {
 
62
            f = item->argv[i] + sizeof("--POPTdesc=");
 
63
            if (f[0] == '$' && f[1] == '"') f++;
 
64
            item->option.descrip = f;
 
65
            item->option.argInfo &= ~POPT_ARGFLAG_DOC_HIDDEN;
 
66
            j--;
 
67
        } else
 
68
        if (!strncmp(item->argv[i], "--POPTargs=", sizeof("--POPTargs=")-1)) {
 
69
            f = item->argv[i] + sizeof("--POPTargs=");
 
70
            if (f[0] == '$' && f[1] == '"') f++;
 
71
            item->option.argDescrip = f;
 
72
            item->option.argInfo &= ~POPT_ARGFLAG_DOC_HIDDEN;
 
73
            item->option.argInfo |= POPT_ARG_STRING;
 
74
            j--;
 
75
        } else
 
76
        if (j != i)
 
77
            item->argv[j] = item->argv[i];
 
78
    }
 
79
    if (j != i) {
 
80
        item->argv[j] = NULL;
 
81
        item->argc = j;
 
82
    }
 
83
    /*@=modobserver@*/
 
84
/*@=boundswrite@*/
 
85
 
 
86
    /*@-nullstate@*/ /* FIX: item->argv[] may be NULL */
 
87
    if (!strcmp(entryType, "alias"))
 
88
        (void) poptAddItem(con, item, 0);
 
89
    else if (!strcmp(entryType, "exec"))
 
90
        (void) poptAddItem(con, item, 1);
 
91
    /*@=nullstate@*/
55
92
}
 
93
/*@=compmempass@*/
56
94
 
57
 
int poptReadConfigFile(poptContext con, const char * fn) {
58
 
    char * file=NULL, * chptr, * end;
59
 
    char * buf=NULL, * dst;
 
95
int poptReadConfigFile(poptContext con, const char * fn)
 
96
{
 
97
    const char * file, * chptr, * end;
 
98
    char * buf;
 
99
/*@dependent@*/ char * dst;
60
100
    int fd, rc;
61
 
    int fileLength;
 
101
    off_t fileLength;
62
102
 
63
103
    fd = open(fn, O_RDONLY);
64
 
    if (fd < 0) {
65
 
        if (errno == ENOENT)
66
 
            return 0;
67
 
        else 
68
 
            return POPT_ERROR_ERRNO;
69
 
    }
 
104
    if (fd < 0)
 
105
        return (errno == ENOENT ? 0 : POPT_ERROR_ERRNO);
70
106
 
71
107
    fileLength = lseek(fd, 0, SEEK_END);
72
 
    (void) lseek(fd, 0, 0);
73
 
 
74
 
    file = malloc(fileLength + 1);
75
 
    if (read(fd, file, fileLength) != fileLength) {
76
 
        rc = errno;
77
 
        close(fd);
78
 
        errno = rc;
79
 
        if (file) free(file);
80
 
        return POPT_ERROR_ERRNO;
81
 
    }
82
 
    close(fd);
83
 
 
84
 
    dst = buf = malloc(fileLength + 1);
 
108
    if (fileLength == -1 || lseek(fd, 0, 0) == -1) {
 
109
        rc = errno;
 
110
        (void) close(fd);
 
111
        /*@-mods@*/
 
112
        errno = rc;
 
113
        /*@=mods@*/
 
114
        return POPT_ERROR_ERRNO;
 
115
    }
 
116
 
 
117
    file = alloca(fileLength + 1);
 
118
    if (read(fd, (char *)file, fileLength) != fileLength) {
 
119
        rc = errno;
 
120
        (void) close(fd);
 
121
        /*@-mods@*/
 
122
        errno = rc;
 
123
        /*@=mods@*/
 
124
        return POPT_ERROR_ERRNO;
 
125
    }
 
126
    if (close(fd) == -1)
 
127
        return POPT_ERROR_ERRNO;
 
128
 
 
129
/*@-boundswrite@*/
 
130
    dst = buf = alloca(fileLength + 1);
85
131
 
86
132
    chptr = file;
87
133
    end = (file + fileLength);
 
134
    /*@-infloops@*/     /* LCL: can't detect chptr++ */
88
135
    while (chptr < end) {
89
136
        switch (*chptr) {
90
137
          case '\n':
91
138
            *dst = '\0';
92
139
            dst = buf;
93
140
            while (*dst && isspace(*dst)) dst++;
94
 
            if (*dst && *dst != '#') {
 
141
            if (*dst && *dst != '#')
95
142
                configLine(con, dst);
96
 
            }
97
143
            chptr++;
98
 
            break;
 
144
            /*@switchbreak@*/ break;
99
145
          case '\\':
100
146
            *dst++ = *chptr++;
101
147
            if (chptr < end) {
105
151
                else
106
152
                    *dst++ = *chptr++;
107
153
            }
108
 
            break;
 
154
            /*@switchbreak@*/ break;
109
155
          default:
110
156
            *dst++ = *chptr++;
111
 
            break;
 
157
            /*@switchbreak@*/ break;
112
158
        }
113
159
    }
114
 
 
115
 
    free(file);
116
 
    free(buf);
 
160
    /*@=infloops@*/
 
161
/*@=boundswrite@*/
117
162
 
118
163
    return 0;
119
164
}
120
165
 
121
 
int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv) {
 
166
int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv)
 
167
{
122
168
    char * fn, * home;
123
169
    int rc;
124
170
 
 
171
    /*@-type@*/
125
172
    if (!con->appName) return 0;
 
173
    /*@=type@*/
126
174
 
127
175
    rc = poptReadConfigFile(con, "/etc/popt");
128
176
    if (rc) return rc;
 
177
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
129
178
    if (getuid() != geteuid()) return 0;
 
179
#endif
130
180
 
131
181
    if ((home = getenv("HOME"))) {
132
 
        fn = malloc(strlen(home) + 20);
 
182
        fn = alloca(strlen(home) + 20);
133
183
        strcpy(fn, home);
134
184
        strcat(fn, "/.popt");
135
185
        rc = poptReadConfigFile(con, fn);
136
 
        free(fn);
137
186
        if (rc) return rc;
138
187
    }
139
188
 
140
189
    return 0;
141
190
}
142