diff -dPNur pmount-0.9.13/src/pmount.c pmount-0.9.13-new/src/pmount.c --- pmount-0.9.13/src/pmount.c 2006-08-15 22:47:45.000000000 +0200 +++ pmount-0.9.13-new/src/pmount.c 2007-03-29 23:02:32.000000000 +0200 @@ -41,6 +41,9 @@ const int E_LOCKED = 8; const int E_INTERNAL = 100; +#define OPT_FMASK 128 +#define OPT_DMASK 129 + /** * Print some help. * @param exename Name of the executable (argv[0]). @@ -74,8 +77,12 @@ " -t : mount as file system type (default: autodetected)\n" " -c : use given I/O character set (default: 'utf8' if called\n" " in an UTF-8 locale, otherwise mount default)\n" - " -u : use specified umask instead of the default (only for\n" + " -u : use specified umask instead of the default (only for\n" " file sytems which actually support umask setting)\n" + " --fmask \n" + " use specified fmask\n" + " --dmask \n" + " use specified dmask\n" " --passphrase \n" " read passphrase from file instead of the terminal\n" " (only for LUKS encrypted devices)\n" @@ -202,17 +209,21 @@ * @param iocharset charset to use for file name conversion; NULL for mount * default * @param umask User specified umask (NULL for default) + * @param fmask User specified fmask (NULL for umask) + * @param dmask User specified dmask (NULL for umask) * @param suppress_errors: if true, stderr is redirected to /dev/null * @return exit status of mount, or -1 on failure. */ int do_mount( const char* device, const char* mntpt, const char* fsname, int async, int noatime, int exec, int force_write, const char* iocharset, const - char* umask, int suppress_errors ) + char* umask, const char *fmask, const char *dmask, int suppress_errors ) { const struct FS* fs; char ugid_opt[100]; char umask_opt[100]; + char fmask_opt[100]; + char dmask_opt[100]; char iocharset_opt[100]; const char* sync_opt = ",sync"; const char* atime_opt = ",atime"; @@ -238,8 +249,18 @@ return -1; } + if( fmask && parse_unsigned( fmask, E_ARGS ) > 0777 ) { + fprintf( stderr, _("Error: invalid fmask %s\n"), fmask ); + return -1; + } + + if( dmask && parse_unsigned( dmask, E_ARGS ) > 0777 ) { + fprintf( stderr, _("Error: invalid dmask %s\n"), dmask ); + return -1; + } + /* assemble option string */ - *ugid_opt = *umask_opt = *iocharset_opt = 0; + *ugid_opt = *umask_opt = *fmask_opt = *dmask_opt = *iocharset_opt = 0; if( fs->support_ugid ) { struct stat statbuf; int gid = getgid(); @@ -264,6 +285,14 @@ snprintf( umask_opt, sizeof( umask_opt ), ",umask=%s", umask ? umask : fs->umask ); + if( (fs->umask ) && (fmask)) + snprintf( fmask_opt, sizeof( fmask_opt ), ",fmask=%s", + fmask ); + + if( (fs->umask ) && (dmask)) + snprintf( dmask_opt, sizeof( dmask_opt ), ",dmask=%s", + dmask ); + if( async ) sync_opt = ",async"; @@ -288,9 +317,9 @@ snprintf( iocharset_opt, sizeof( iocharset_opt ), ",iocharset=%s", iocharset ); } - snprintf( options, sizeof( options ), "%s%s%s%s%s%s%s%s", + snprintf( options, sizeof( options ), "%s%s%s%s%s%s%s%s%s%s", fs->options, sync_opt, atime_opt, exec_opt, access_opt, ugid_opt, - umask_opt, iocharset_opt ); + umask_opt, fmask_opt, dmask_opt, iocharset_opt ); /* go for it */ return spawnl( SPAWN_EROOT | SPAWN_RROOT | (suppress_errors ? SPAWN_NO_STDERR : 0 ), @@ -311,12 +340,14 @@ * @param iocharset charset to use for file name conversion; NULL for mount * default * @param umask User specified umask (NULL for default) + * @param fmask User specified fmask (NULL for umask) + * @param dmask User specified dmask (NULL for umask) * @return last return value of do_mount (i. e. 0 on success, != 0 on error) */ int do_mount_auto( const char* device, const char* mntpt, int async, int noatime, int exec, int force_write, const char* iocharset, - const char* umask ) + const char* umask, const char *fmask, const char *dmask ) { const struct FS* fs; int nostderr = 1; @@ -327,14 +358,14 @@ if( (fs+1)->fsname == NULL ) nostderr = 0; result = do_mount( device, mntpt, fs->fsname, async, noatime, exec, - force_write, iocharset, umask, nostderr ); + force_write, iocharset, umask, fmask, dmask, nostderr ); if( result == 0 ) break; /* sometimes VFAT fails when using iocharset; try again without */ if( iocharset ) result = do_mount( device, mntpt, fs->fsname, async, noatime, exec, - force_write, NULL, umask, nostderr ); + force_write, NULL, umask, fmask, dmask, nostderr ); if( result <= 0 ) break; } @@ -503,6 +534,8 @@ const char* use_fstype = NULL; const char* iocharset = NULL; const char* umask = NULL; + const char* fmask = NULL; + const char* dmask = NULL; const char* passphrase = NULL; int result; @@ -520,6 +553,8 @@ { "type", 1, NULL, 't' }, { "charset", 1, NULL, 'c' }, { "umask", 1, NULL, 'u' }, + { "fmask", 1, NULL, OPT_FMASK }, + { "dmask", 1, NULL, OPT_DMASK }, { "passphrase", 1, NULL, 'p' }, { "read-only", 0, NULL, 'r' }, { "read-write", 0, NULL, 'w' }, @@ -567,6 +602,10 @@ case 'c': iocharset = optarg; break; case 'u': umask = optarg; break; + + case OPT_FMASK: fmask = optarg; break; + + case OPT_DMASK: dmask = optarg; break; case 'p': passphrase = optarg; break; @@ -701,10 +740,10 @@ /* off we go */ if( use_fstype ) result = do_mount( decrypted_device, mntpt, use_fstype, async, noatime, - exec, force_write, iocharset, umask, 0 ); + exec, force_write, iocharset, umask, fmask, dmask, 0 ); else result = do_mount_auto( decrypted_device, mntpt, async, noatime, exec, - force_write, iocharset, umask ); + force_write, iocharset, umask, fmask, dmask ); /* unlock the mount point again */ debug( "unlocking mount point directory\n" ); diff -dPNur pmount-0.9.13/src/pmount-hal.c pmount-0.9.13-new/src/pmount-hal.c --- pmount-0.9.13/src/pmount-hal.c 2006-08-15 22:31:02.000000000 +0200 +++ pmount-0.9.13-new/src/pmount-hal.c 2007-03-29 23:11:31.000000000 +0200 @@ -111,7 +111,7 @@ void exec_pmount( const char* device, const char* fstype, const char* label, dbus_bool_t sync, dbus_bool_t noatime, dbus_bool_t exec, const char* - umask, const char* iocharset, int addargc, const char* const* addargv ) + umask, const char *fmask, const char *dmask, const char* iocharset, int addargc, const char* const* addargv ) { const char** argv = (const char**) calloc( sizeof( const char* ), addargc+15 ); int argc = 0; @@ -137,6 +137,16 @@ argv[argc++] = umask; } + if ( fmask ) { + argv[argc++] = "--fmask"; + argv[argc++] = fmask; + } + + if ( dmask ) { + argv[argc++] = "--dmask"; + argv[argc++] = dmask; + } + if( iocharset ) { argv[argc++] = "-c"; argv[argc++] = iocharset; @@ -180,6 +190,8 @@ LibHalDrive* drive; dbus_bool_t sync = FALSE, noatime = FALSE, exec = FALSE; char *umask = NULL; + char *fmask = NULL; + char *dmask = NULL; char *iocharset = NULL; /* initialize locale */ @@ -358,6 +370,32 @@ debug( "umask: %s\n", umask ); + if( volume && libhal_device_property_exists( hal_ctx, + libhal_volume_get_udi( volume ), "volume.policy.mount_option.fmask", &error ) ) + fmask = libhal_device_get_property_string( hal_ctx, + libhal_volume_get_udi( volume ), "volume.policy.mount_option.fmask", &error ); + else if( libhal_device_property_exists( hal_ctx, + libhal_drive_get_udi( drive ), "storage.policy.mount_option.fmask", &error ) ) + fmask = libhal_device_get_property_string( hal_ctx, + libhal_drive_get_udi( drive ), "storage.policy.mount_option.fmask", &error ); + else if( libhal_device_property_exists( hal_ctx, computer_udi, "storage.policy.default.mount_option.fmask", &error ) ) + fmask = libhal_device_get_property_string( hal_ctx, computer_udi, "storage.policy.default.mount_option.fmask", &error ); + + debug( "fmask: %s\n", fmask ); + + if( volume && libhal_device_property_exists( hal_ctx, + libhal_volume_get_udi( volume ), "volume.policy.mount_option.dmask", &error ) ) + dmask = libhal_device_get_property_string( hal_ctx, + libhal_volume_get_udi( volume ), "volume.policy.mount_option.dmask", &error ); + else if( libhal_device_property_exists( hal_ctx, + libhal_drive_get_udi( drive ), "storage.policy.mount_option.dmask", &error ) ) + dmask = libhal_device_get_property_string( hal_ctx, + libhal_drive_get_udi( drive ), "storage.policy.mount_option.dmask", &error ); + else if( libhal_device_property_exists( hal_ctx, computer_udi, "storage.policy.default.mount_option.dmask", &error ) ) + dmask = libhal_device_get_property_string( hal_ctx, computer_udi, "storage.policy.default.mount_option.dmask", &error ); + + debug( "dmask: %s\n", dmask ); + /* shut down hal connection */ libhal_ctx_shutdown( hal_ctx, &error ); libhal_ctx_free( hal_ctx ); @@ -365,7 +403,7 @@ dbus_connection_unref( dbus_conn ); /* go */ - exec_pmount( device, fstype, label, sync, noatime, exec, umask, iocharset, argc-2, argv+2 ); + exec_pmount( device, fstype, label, sync, noatime, exec, umask, fmask, dmask, iocharset, argc-2, argv+2 ); return 0; }