~ubuntu-branches/ubuntu/precise/util-linux/precise-proposed

« back to all changes in this revision

Viewing changes to mount/mount_mntent.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-06-20 22:31:50 UTC
  • mfrom: (1.6.3 upstream) (4.5.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110620223150-lz8wrv0946ihcz3z
Tags: 2.19.1-2ubuntu1
* Merge from Debian unstable, remaining changes:
  - Build for multiarch.
  - Add pre-depends on multiarch-support.
  - configure.ac: don't try to be clever about extracting a path name from
    $libdir to append to /usr in a way that's not overridable; instead,
    reuse the built-in configurable libexecdir.
  - Fix up the .pc.in files to know about libexecdir, so our substitutions
    don't leave us with unusable pkg-config files.
  - Install custom blkid.conf to use /dev/.blkid.tab since we don't
    expect device names to survive a reboot
  - Mention mountall(8) in fstab(5) manpages, along with its special
    options.
  - Since upstart is required in Ubuntu, the hwclock.sh init script is not
    called on startup and the hwclockfirst.sh init script is removed.
  - Drop depends on initscripts for the above.
  - Replace hwclock udev rule with an Upstart job.
  - For the case where mount is called with a directory to mount, look
    that directory up in mountall's /lib/init/fstab if we couldn't find
    it mentioned anywhere else.  This means "mount /proc", "mount /sys",
    etc. work.
  - mount.8 points to the cifs-utils package, not the obsolete smbfs one. 
* Dropped changes:
  - mount.preinst: lsb_release has been fixed in lucid and above to be
    usable without configuration, so we don't have to diverge from Debian
    here anymore.
* Changes merged upstream:
  - sfdisk support for '+' with '-N'
  - mount/umount.c: fix a segfault on umount with empty mtab entry
  - Fix arbitrary unmount with fuse security issue

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
#include <string.h>             /* for index */
10
10
#include <ctype.h>              /* for isdigit */
11
11
#include <sys/stat.h>           /* for umask */
 
12
 
12
13
#include "mount_mntent.h"
13
14
#include "sundries.h"           /* for xmalloc */
14
15
#include "nls.h"
15
 
 
16
 
/* Unfortunately the classical Unix /etc/mtab and /etc/fstab
17
 
   do not handle directory names containing spaces.
18
 
   Here we mangle them, replacing a space by \040.
19
 
   What do other Unices do? */
20
 
 
21
 
static unsigned char need_escaping[] = { ' ', '\t', '\n', '\\' };
22
 
 
23
 
static char *
24
 
mangle(const char *s) {
25
 
        char *ss, *sp;
26
 
        int n;
27
 
 
28
 
        n = strlen(s);
29
 
        ss = sp = xmalloc(4*n+1);
30
 
        while(1) {
31
 
                for (n = 0; n < sizeof(need_escaping); n++) {
32
 
                        if (*s == need_escaping[n]) {
33
 
                                *sp++ = '\\';
34
 
                                *sp++ = '0' + ((*s & 0300) >> 6);
35
 
                                *sp++ = '0' + ((*s & 070) >> 3);
36
 
                                *sp++ = '0' + (*s & 07);
37
 
                                goto next;
38
 
                        }
39
 
                }
40
 
                *sp++ = *s;
41
 
                if (*s == 0)
42
 
                        break;
43
 
        next:
44
 
                s++;
45
 
        }
46
 
        return ss;
47
 
}
 
16
#include "mangle.h"
48
17
 
49
18
static int
50
19
is_space_or_tab (char c) {
58
27
        return s;
59
28
}
60
29
 
61
 
static char *
62
 
skip_nonspaces(char *s) {
63
 
        while (*s && !is_space_or_tab(*s))
64
 
                s++;
65
 
        return s;
66
 
}
67
 
 
68
 
#define isoctal(a) (((a) & ~7) == '0')
69
 
 
70
 
/* returns malloced pointer - no more strdup required */
71
 
static char *
72
 
unmangle(char *s) {
73
 
        char *ret, *ss, *sp;
74
 
 
75
 
        ss = skip_nonspaces(s);
76
 
        ret = sp = xmalloc(ss-s+1);
77
 
        while(s != ss) {
78
 
                if (*s == '\\' && isoctal(s[1]) && isoctal(s[2]) && isoctal(s[3])) {
79
 
                        *sp++ = 64*(s[1] & 7) + 8*(s[2] & 7) + (s[3] & 7);
80
 
                        s += 4;
81
 
                } else
82
 
                        *sp++ = *s++;
83
 
        }
84
 
        *sp = 0;
85
 
        return ret;
86
 
}
87
 
 
88
30
/*
89
31
 * fstat'ing the file and allocating a buffer holding all of it
90
32
 * may be a bad idea: if the file is /proc/mounts, the stat
177
119
                s = skip_spaces(buf);
178
120
        } while (*s == '\0' || *s == '#');
179
121
 
180
 
        me.mnt_fsname = unmangle(s);
181
 
        s = skip_nonspaces(s);
182
 
        s = skip_spaces(s);
183
 
        me.mnt_dir = unmangle(s);
184
 
        s = skip_nonspaces(s);
185
 
        s = skip_spaces(s);
186
 
        me.mnt_type = unmangle(s);
187
 
        s = skip_nonspaces(s);
188
 
        s = skip_spaces(s);
189
 
        me.mnt_opts = unmangle(s);
190
 
        s = skip_nonspaces(s);
191
 
        s = skip_spaces(s);
 
122
        me.mnt_fsname = unmangle(s, &s);
 
123
        s = skip_spaces(s);
 
124
        me.mnt_dir = unmangle(s, &s);
 
125
        s = skip_spaces(s);
 
126
        me.mnt_type = unmangle(s, &s);
 
127
        s = skip_spaces(s);
 
128
        me.mnt_opts = unmangle(s, &s);
 
129
        s = skip_spaces(s);
 
130
 
 
131
        if (!me.mnt_fsname || !me.mnt_dir || !me.mnt_type)
 
132
                goto err;
192
133
 
193
134
        if (isdigit(*s)) {
194
135
                me.mnt_freq = atoi(s);