Projet

Général

Profil

umask.diff

Emmanuel GARETTE, 22/12/2011 10:00

Télécharger (5,92 ko)

Voir les différences:

bacula.py 2011-12-21 21:07:12.000000000 +0100
116 116
    if dic['support'] == 'none':
117 117
        raise Exception("ERREUR : bacula n'est pas configuré")
118 118

  
119
    #demonte avant de faire le montage
119
    #umount before mount
120 120
    umount_bacula_support()
121

  
122
    #get config options
121 123
    config = ConfigObj(BACULA_CONF)
122
    DISTANT_LOGIN_MOUNT = config.get('DISTANT_LOGIN_MOUNT', '/bin/mount -t smbfs -o username={0},password={1},ip={2},uid={3},noexec,nosuid,nodev //{4}/{5} {6}')
123
    DISTANT_MOUNT = config.get('DISTANT_MOUNT', '/bin/mount -t smbfs -o password={0},ip={1},uid={2},noexec,nosuid,nodev //{3}/{4} {5}')
124 124

  
125
    #make mount point directory is not already exists
125 126
    if not os.path.isdir(MOUNT_POINT):
126 127
        os.makedirs(MOUNT_POINT)
127
    #montage
128
    #mount as bacula user
129
    try:
130
        uid = pwd.getpwnam('bacula').pw_uid
131
    except:
132
        uid = 102
133
    #chown_mount_point = False
128

  
134 129
    if dic['support'] == 'usb':
135 130
        #si usb_path est un lien symbolique, suivre le lien (#2447)
136 131
        usb_path = dic['usb_path']
......
139 134
                    os.path.dirname(usb_path), os.readlink(usb_path)))
140 135
        if device_is_mount(usb_path):
141 136
            raise Exception('ERREUR : périphérique {0} déjà monté'.format(usb_path))
137

  
142 138
        USB_MOUNT = config.get('USB_MOUNT', None)
143 139
        if USB_MOUNT == None:
144
            #if USB_MOUNT not set:
145
            #if volume if in VFAT, add uid option
146
            code, volumes, stderr=system_out(['/usr/bin/lshw', '-short', '-quiet', '-class', 'volume'])
140
            #if USB_MOUNT not set in config file
141
            #get volume informations
142
            code, volumes, stderr=system_out(['/usr/bin/lshw', '-short',
143
                                        '-quiet', '-class', 'volume'])
147 144
            if code != 0:
148 145
                raise Exception('Erreur avec lshw : {0}'.format(stderr))
149 146
            volume_found = False
150 147
            for volume in volumes.strip().split('\n'):
151 148
                line = volume.strip().split()
149
                #get volume format
152 150
                if len(line) > 3 and line[1] == usb_path:
153
                    if ' '.join(line[-3:]) == 'Windows FAT volume':
154
                        USB_MOUNT = '/bin/mount {0} {1} -o noexec,nosuid,nodev,uid={2}'
155
                    else:
156
                        USB_MOUNT = '/bin/mount {0} {1} -o noexec,nosuid,nodev'
157
                        #chown_mount_point = True
151
                    USB_MOUNT = '/bin/mount {0} {1} -o noexec,nosuid,nodev'
152
                    #for VFAT and NTFS volume not supported posix right
153
                    #add uid and umask option
154
                    if ' '.join(line[-3:]) in ['Windows FAT volume',
155
                            'Windows NTFS volume']:
156
                        USB_MOUNT += ',uid={2},umask=0077'
158 157
                    volume_found = True
159 158
                    break
160 159
            if not volume_found:
161 160
                raise Exception('ERREUR : périphérique {0} non reconnu'.format(dic['usb_path']))
162 161

  
162
        #mount as bacula user
163
        try:
164
            uid = pwd.getpwnam('bacula').pw_uid
165
        except:
166
            uid = 102
167

  
163 168
        cmd = USB_MOUNT.format(usb_path, MOUNT_POINT, uid).split()
164 169
        nbtest = usb_test
170

  
165 171
    elif dic['support'] == 'smb':
172
        #test if smb port is available
166 173
        ret = tcpcheck(dic['smb_ip'], '139', 2)
167 174
        if not ret:
168 175
            ret = tcpcheck(dic['smb_ip'], '445', 2)
169 176
            if not ret:
170 177
                raise Exception("La machine {0} n'est pas accessible sur les ports 139 et 445".format(dic['smb_ip']))
171 178
        if dic['smb_login'] != None:
172
            cmd = DISTANT_LOGIN_MOUNT.format(dic['smb_login'],
179
            distant_mount = config.get('DISTANT_LOGIN_MOUNT',
180
                '/bin/mount -t smbfs -o username={0},password={1},ip={2},uid={3},noexec,nosuid,nodev //{4}/{5} {6}')
181
            cmd = distant_mount.format(dic['smb_login'],
173 182
                    dic['smb_password'], dic['smb_ip'], uid,
174 183
                    dic['smb_machine'], dic['smb_partage'], MOUNT_POINT).split()
175 184
        else:
176
            cmd = DISTANT_MOUNT.format(dic['smb_password'], dic['smb_ip'], uid,
185
            distant_mount = config.get('DISTANT_MOUNT',
186
                '/bin/mount -t smbfs -o password={0},ip={1},uid={2},noexec,nosuid,nodev //{3}/{4} {5}')
187
            cmd = distant_mount.format(dic['smb_password'], dic['smb_ip'], uid,
177 188
                    dic['smb_machine'], dic['smb_partage'], MOUNT_POINT).split()
178 189
        nbtest = 1
190

  
191
    #default return value
179 192
    ret = 1
193

  
194
    #try to mount support nbtest times
180 195
    for i in range(1, nbtest+1):
181 196
        ret, stdout, stderr = system_out(cmd)
182 197
        if ret == 0:
......
187 202

  
188 203
    if ret != 0:
189 204
        umount_bacula_support()
190
        raise Exception('ERREUR : montage impossible : {0}, {1}'.format(stdout,stderr))
205
        raise Exception('ERREUR : montage impossible : {0}, {1}'.format(stdout,
206
                stderr))
191 207

  
192 208
    if not os.path.ismount(MOUNT_POINT):
193 209
        umount_bacula_support()
194 210
        raise Exception('ERREUR : point de montage {0} non monté'.format(MOUNT_POINT))
195
    #if chown_mount_point:
196
    #    system_out(['/bin/chown', '-R', 'bacula:root', MOUNT_POINT])
211

  
197 212
    return True
198 213

  
199 214
def umount_bacula_support(error=False):
......
336 351
    try:
337 352
        code = os.system('su - bacula -c "touch %s" -s /bin/bash'%TEST_MOUNT_FILE)
338 353
        if code != 0:
354
            print "Pas de permission d'écrire sur le support de sauvegarde"
355
            print "Essayer de faire :"
356
            print "/usr/share/eole/bacula/baculamount.py --mount"
357
            print "chown -R bacula:root /mnt/sauvegardes"
358
            print "chmod -R 700 /mnt/sauvegardes"
359
            print "/usr/share/eole/bacula/baculamount.py --umount"
339 360
            raise Exception('ERREUR : écriture impossible')
340 361
        code = os.system('su - bacula -c "rm -f %s" -s /bin/bash'%TEST_MOUNT_FILE)
341 362
        if code != 0: