~ubuntu-branches/ubuntu/lucid/loop-aes-utils/lucid-security

« back to all changes in this revision

Viewing changes to mount/sundries.c

  • Committer: Bazaar Package Importer
  • Author(s): Max Vozeler
  • Date: 2009-07-06 02:08:18 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090706020818-11pxao7bhgjenfv9
Tags: 2.15.1~rc1-2
Disable ncurses (--without-ncurses), not used in
mount/. Fixes FTBFS (closes: #535676).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Support functions.  Exported functions are prototyped in sundries.h.
3
 
 * sundries.c,v 1.1.1.1 1993/11/18 08:40:51 jrs Exp
4
3
 *
5
4
 * added fcntl locking by Kjetil T. (kjetilho@math.uio.no) - aeb, 950927
6
5
 *
12
11
#include <stdio.h>
13
12
#include <string.h>
14
13
#include <mntent.h>             /* for MNTTYPE_SWAP */
 
14
 
 
15
#include "canonicalize.h"
 
16
 
15
17
#include "fstab.h"
16
18
#include "sundries.h"
17
 
#include "realpath.h"
18
19
#include "xmalloc.h"
19
20
#include "nls.h"
20
21
 
 
22
int mount_quiet;
 
23
int verbose;
 
24
char *progname;
 
25
 
21
26
char *
22
27
xstrndup (const char *s, int n) {
23
28
     char *t;
108
113
     fputc('\n', stderr);
109
114
}
110
115
 
 
116
/* Fatal error.  Print message and exit.  */
 
117
void
 
118
die(int err, const char *fmt, ...) {
 
119
        va_list args;
 
120
 
 
121
        va_start(args, fmt);
 
122
        vfprintf(stderr, fmt, args);
 
123
        fprintf(stderr, "\n");
 
124
        va_end(args);
 
125
 
 
126
        exit(err);
 
127
}
 
128
 
111
129
/* True if fstypes match.  Null *TYPES means match anything,
112
130
   except that swap types always return false. */
113
131
/* Accept nonfs,proc,devpts and nonfs,noproc,nodevpts
224
242
     return 1;
225
243
}
226
244
 
 
245
int
 
246
is_pseudo_fs(const char *type)
 
247
{
 
248
        if (type == NULL || *type == '/')
 
249
                return 0;
 
250
        if (streq(type, "none") ||
 
251
            streq(type, "proc") ||
 
252
            streq(type, "tmpfs") ||
 
253
            streq(type, "sysfs") ||
 
254
            streq(type, "devpts"))
 
255
                return 1;
 
256
        return 0;
 
257
}
 
258
 
227
259
/* Make a canonical pathname from PATH.  Returns a freshly malloced string.
228
260
   It is up the *caller* to ensure that the PATH is sensible.  i.e.
229
261
   canonicalize ("/dev/fd0/.") returns "/dev/fd0" even though ``/dev/fd0/.''
230
262
   is not a legal pathname for ``/dev/fd0''.  Anything we cannot parse
231
263
   we return unmodified.   */
232
264
char *
233
 
canonicalize (const char *path) {
234
 
        char canonical[PATH_MAX+2];
 
265
canonicalize_spec (const char *path)
 
266
{
 
267
        char *res;
235
268
 
236
269
        if (path == NULL)
237
270
                return NULL;
238
 
 
239
 
#if 1
240
 
        if (streq(path, "none") ||
241
 
            streq(path, "proc") ||
242
 
            streq(path, "devpts"))
 
271
        if (is_pseudo_fs(path))
243
272
                return xstrdup(path);
244
 
#endif
245
 
        if (myrealpath (path, canonical, PATH_MAX+1))
246
 
                return xstrdup(canonical);
247
273
 
248
 
        return xstrdup(path);
 
274
        res = canonicalize_path(path);
 
275
        if (!res)
 
276
                die(EX_SYSERR, _("not enough memory"));
 
277
        return res;
249
278
}
250
279
 
251
 
 
252
 
/*
253
 
 * Parses NAME=value, returns -1 on parse error, 0 success. The success is also
254
 
 * when the 'spec' doesn't contain name=value pair (because the spec could be
255
 
 * a devname too). In particular case the pointer 'name' is set to NULL.
256
 
 
257
 
 * The result is a new allocated string (the 'name' pointer).
258
 
 */
259
 
int
260
 
parse_spec(const char *spec, char **name, char **value)
 
280
char *canonicalize (const char *path)
261
281
{
262
 
        char *vl, *tk, *cp;
263
 
 
264
 
        *name = NULL;
265
 
        *value = NULL;
266
 
 
267
 
        if (!(cp = strchr(spec, '=')))
268
 
                return 0;                               /* no name= */
269
 
 
270
 
        tk = xstrdup(spec);
271
 
        vl = tk + (cp - spec);
272
 
        *vl++ = '\0';
273
 
 
274
 
        if (*vl == '"' || *vl == '\'') {
275
 
                if (!(cp = strrchr(vl+1, *vl))) {
276
 
                        free(tk);
277
 
                        return -1;                      /* parse error */
278
 
                }
279
 
                vl++;
280
 
                *cp = '\0';
281
 
        }
282
 
 
283
 
        *name = tk;
284
 
        *value = vl;
285
 
        return 0;
 
282
        char *res = canonicalize_path(path);
 
283
 
 
284
        if (!res)
 
285
                die(EX_SYSERR, _("not enough memory"));
 
286
        return res;
286
287
}
287
288