|
Lines 1717-1722
Link Here
|
| 1717 |
} |
1717 |
} |
| 1718 |
|
1718 |
|
| 1719 |
|
1719 |
|
|
|
1720 |
static gboolean |
| 1721 |
gvm_mount_options (GPtrArray *options, guint32 opts, const char *type, const char *where) |
| 1722 |
{ |
| 1723 |
char *option, *key, *tmp, *p; |
| 1724 |
GSList *list, *l, *n; |
| 1725 |
GConfClient *gconf; |
| 1726 |
const char *dir; |
| 1727 |
|
| 1728 |
if (!strncmp (where, "/org/freedesktop/Hal/", 21)) { |
| 1729 |
/* flatten the UDI */ |
| 1730 |
dir = p = tmp = g_strdup (where); |
| 1731 |
while (*p != '\0') { |
| 1732 |
if (*p == '/') |
| 1733 |
*p = '_'; |
| 1734 |
p++; |
| 1735 |
} |
| 1736 |
} else { |
| 1737 |
dir = where; |
| 1738 |
tmp = NULL; |
| 1739 |
} |
| 1740 |
|
| 1741 |
key = g_strdup_printf ("/system/storage/%s/%s/mount_options", type, dir); |
| 1742 |
g_free (tmp); |
| 1743 |
|
| 1744 |
gconf = gconf_client_get_default (); |
| 1745 |
list = gconf_client_get_list (gconf, key, GCONF_VALUE_STRING, NULL); |
| 1746 |
g_object_unref (gconf); |
| 1747 |
g_free (key); |
| 1748 |
|
| 1749 |
if (list == NULL) { |
| 1750 |
fprintf (stderr, "no mount options found for %s::%s\n", type, where); |
| 1751 |
return FALSE; |
| 1752 |
} |
| 1753 |
|
| 1754 |
for (l = list; l != NULL; l = n) { |
| 1755 |
option = l->data; |
| 1756 |
n = l->next; |
| 1757 |
|
| 1758 |
g_ptr_array_add (options, option); |
| 1759 |
|
| 1760 |
g_slist_free_1 (l); |
| 1761 |
} |
| 1762 |
|
| 1763 |
if (opts & MOUNT_UID) { |
| 1764 |
option = g_strdup_printf ("uid=%u", getuid ()); |
| 1765 |
g_ptr_array_add (options, option); |
| 1766 |
} |
| 1767 |
|
| 1768 |
return TRUE; |
| 1769 |
} |
| 1770 |
|
| 1771 |
|
| 1720 |
/* |
1772 |
/* |
| 1721 |
* gvm_device_mount - mount the given device. |
1773 |
* gvm_device_mount - mount the given device. |
| 1722 |
* |
1774 |
* |
|
Lines 1761-1770
Link Here
|
| 1761 |
|
1813 |
|
| 1762 |
return retval; |
1814 |
return retval; |
| 1763 |
} else { |
1815 |
} else { |
| 1764 |
char *mount_point, *fstype, fmask_opt[12], *charset_opt = NULL; |
1816 |
char *mount_point, *fstype, *drive, **moptions, fmask_opt[12], *charset_opt = NULL; |
| 1765 |
DBusMessage *dmesg, *reply; |
1817 |
DBusMessage *dmesg, *reply; |
|
|
1818 |
gboolean freev = FALSE; |
| 1766 |
GPtrArray *options; |
1819 |
GPtrArray *options; |
|
|
1820 |
guint32 opts = 0; |
| 1767 |
DBusError error; |
1821 |
DBusError error; |
|
|
1822 |
size_t i, j; |
| 1768 |
|
1823 |
|
| 1769 |
if (!(dmesg = dbus_message_new_method_call ("org.freedesktop.Hal", udi, |
1824 |
if (!(dmesg = dbus_message_new_method_call ("org.freedesktop.Hal", udi, |
| 1770 |
"org.freedesktop.Hal.Device.Volume", |
1825 |
"org.freedesktop.Hal.Device.Volume", |
|
Lines 1773-1798
Link Here
|
| 1773 |
return FALSE; |
1828 |
return FALSE; |
| 1774 |
} |
1829 |
} |
| 1775 |
|
1830 |
|
|
|
1831 |
if ((moptions = libhal_device_get_property_strlist (hal_ctx, udi, "volume.mount.valid_options", NULL))) { |
| 1832 |
for (i = 0; moptions[i]; i++) { |
| 1833 |
for (j = 0; j < G_N_ELEMENTS (mount_options); j++) { |
| 1834 |
if (!strcmp (moptions[i], mount_options[j].name)) |
| 1835 |
opts |= mount_options[j].flag; |
| 1836 |
} |
| 1837 |
} |
| 1838 |
|
| 1839 |
libhal_free_string_array (moptions); |
| 1840 |
} |
| 1841 |
|
| 1776 |
options = g_ptr_array_new (); |
1842 |
options = g_ptr_array_new (); |
|
|
1843 |
|
| 1844 |
/* check volume-specific mount options */ |
| 1845 |
if (gvm_mount_options (options, opts, "volumes", udi)) { |
| 1846 |
freev = TRUE; |
| 1847 |
goto mount; |
| 1848 |
} |
| 1849 |
|
| 1850 |
/* check drive specific mount options */ |
| 1851 |
if ((drive = libhal_device_get_property_string (hal_ctx, udi, "block.storage_device", NULL))) { |
| 1852 |
if (gvm_mount_options (options, opts, "drives", drive)) { |
| 1853 |
libhal_free_string (drive); |
| 1854 |
freev = TRUE; |
| 1855 |
goto mount; |
| 1856 |
} |
| 1857 |
libhal_free_string (drive); |
| 1858 |
} |
| 1859 |
|
| 1777 |
if ((fstype = libhal_device_get_property_string (hal_ctx, udi, "volume.fstype", NULL))) { |
1860 |
if ((fstype = libhal_device_get_property_string (hal_ctx, udi, "volume.fstype", NULL))) { |
| 1778 |
char **moptions = NULL; |
|
|
| 1779 |
const char *iocharset; |
1861 |
const char *iocharset; |
| 1780 |
guint32 opts = 0; |
|
|
| 1781 |
char uid[32]; |
1862 |
char uid[32]; |
| 1782 |
size_t i, j; |
|
|
| 1783 |
mode_t mask; |
1863 |
mode_t mask; |
| 1784 |
|
1864 |
|
| 1785 |
if ((moptions = libhal_device_get_property_strlist (hal_ctx, udi, "volume.mount.valid_options", NULL))) { |
1865 |
/* fall back to using fstype-specific mount options */ |
| 1786 |
for (i = 0; moptions[i]; i++) { |
1866 |
if (gvm_mount_options (options, opts, "default_options", fstype)) { |
| 1787 |
for (j = 0; j < G_N_ELEMENTS (mount_options); j++) { |
1867 |
libhal_free_string (fstype); |
| 1788 |
if (!strcmp (moptions[i], mount_options[j].name)) |
1868 |
freev = TRUE; |
| 1789 |
opts |= mount_options[j].flag; |
1869 |
goto mount; |
| 1790 |
} |
|
|
| 1791 |
} |
| 1792 |
|
| 1793 |
libhal_free_string_array (moptions); |
| 1794 |
} |
1870 |
} |
| 1795 |
|
1871 |
|
|
|
1872 |
/* take our best guess at what the user would want */ |
| 1796 |
if (!strcmp (fstype, "vfat")) { |
1873 |
if (!strcmp (fstype, "vfat")) { |
| 1797 |
if (opts & MOUNT_NOEXEC) |
1874 |
if (opts & MOUNT_NOEXEC) |
| 1798 |
g_ptr_array_add (options, "noexec"); |
1875 |
g_ptr_array_add (options, "noexec"); |
|
Lines 1843-1851
Link Here
|
| 1843 |
g_ptr_array_add (options, uid); |
1920 |
g_ptr_array_add (options, uid); |
| 1844 |
} |
1921 |
} |
| 1845 |
|
1922 |
|
| 1846 |
g_free (fstype); |
1923 |
libhal_free_string (fstype); |
| 1847 |
} |
1924 |
} |
| 1848 |
|
1925 |
|
|
|
1926 |
mount: |
| 1927 |
|
| 1849 |
mount_point = ""; |
1928 |
mount_point = ""; |
| 1850 |
fstype = ""; |
1929 |
fstype = ""; |
| 1851 |
|
1930 |
|
|
Lines 1857-1862
Link Here
|
| 1857 |
return FALSE; |
1936 |
return FALSE; |
| 1858 |
} |
1937 |
} |
| 1859 |
|
1938 |
|
|
|
1939 |
if (freev) { |
| 1940 |
for (i = 0; i < options->len; i++) |
| 1941 |
g_free (options->pdata[i]); |
| 1942 |
} |
| 1943 |
|
| 1860 |
g_ptr_array_free (options, TRUE); |
1944 |
g_ptr_array_free (options, TRUE); |
| 1861 |
g_free (charset_opt); |
1945 |
g_free (charset_opt); |
| 1862 |
|
1946 |
|
|
Lines 3080-3110
Link Here
|
| 3080 |
} |
3164 |
} |
| 3081 |
|
3165 |
|
| 3082 |
|
3166 |
|
|
|
3167 |
enum { |
| 3168 |
LOCAL_USER_CHECKED = (1 << 0), |
| 3169 |
LOCAL_USER_FOUND = (1 << 1) |
| 3170 |
}; |
| 3171 |
|
| 3083 |
/* checks that the user is logged-in at a local X session (which does not necessarily infer an *active* session) */ |
3172 |
/* checks that the user is logged-in at a local X session (which does not necessarily infer an *active* session) */ |
| 3084 |
static gboolean |
3173 |
static gboolean |
| 3085 |
gvm_local_user (void) |
3174 |
gvm_local_user (void) |
| 3086 |
{ |
3175 |
{ |
| 3087 |
gboolean local = FALSE; |
3176 |
static guint32 local = 0; |
|
|
3177 |
struct dirent *dent; |
| 3088 |
struct utmp *utmp; |
3178 |
struct utmp *utmp; |
| 3089 |
const char *user; |
3179 |
const char *user; |
| 3090 |
size_t ulen; |
3180 |
char *vtend; |
|
|
3181 |
size_t n; |
| 3182 |
DIR *dir; |
| 3183 |
int vt; |
| 3184 |
|
| 3185 |
if (local & LOCAL_USER_CHECKED) |
| 3186 |
return (local & LOCAL_USER_FOUND); |
| 3091 |
|
3187 |
|
| 3092 |
user = g_get_user_name (); |
3188 |
user = g_get_user_name (); |
| 3093 |
ulen = strlen (user); |
3189 |
n = strlen (user); |
| 3094 |
|
3190 |
|
| 3095 |
setutent (); |
3191 |
if (!(dir = opendir (GVM_CONSOLE_AUTH_DIR))) |
|
|
3192 |
goto fallback; |
| 3096 |
|
3193 |
|
| 3097 |
while (!local && (utmp = getutent ())) { |
3194 |
/* this works for pam_console ($path/user) and pam_foreground ($path/user:vt) - see bug #336932 */ |
| 3098 |
if (utmp->ut_type != USER_PROCESS || strncmp (utmp->ut_user, user, ulen) != 0) |
3195 |
while ((dent = readdir (dir))) { |
| 3099 |
continue; |
3196 |
if (!strncmp (user, dent->d_name, n) && dent->d_name[n] == '\0' |
|
|
3197 |
|| (dent->d_name[n] == ':' && ((vt = strtol (dent->d_name + n + 1, &vtend, 10)) >= 0) && *vtend == '\0')) { |
| 3198 |
local = LOCAL_USER_FOUND; |
| 3199 |
break; |
| 3200 |
} |
| 3201 |
} |
| 3202 |
|
| 3203 |
closedir (dir); |
| 3204 |
|
| 3205 |
fallback: |
| 3206 |
|
| 3207 |
if (!(local & LOCAL_USER_FOUND)) { |
| 3208 |
setutent (); |
| 3209 |
|
| 3210 |
while (!(local & LOCAL_USER_FOUND) && (utmp = getutent ())) { |
| 3211 |
if (utmp->ut_type != USER_PROCESS || strncmp (utmp->ut_user, user, n) != 0) |
| 3212 |
continue; |
| 3213 |
|
| 3214 |
/* only accept local X sessions or local tty's (user started X via `startx`) */ |
| 3215 |
local = utmp->ut_line[0] == ':' && utmp->ut_line[1] >= '0' && utmp->ut_line[1] <= '9' |
| 3216 |
|| !strncmp (utmp->ut_line, "tty", 3) ? LOCAL_USER_FOUND : 0; |
| 3217 |
} |
| 3100 |
|
3218 |
|
| 3101 |
/* only accept local X sessions */ |
3219 |
endutent (); |
| 3102 |
local = utmp->ut_line[0] == ':' && utmp->ut_line[1] >= '0' && utmp->ut_line[1] <= '9'; |
|
|
| 3103 |
} |
3220 |
} |
| 3104 |
|
3221 |
|
| 3105 |
endutent (); |
3222 |
local |= LOCAL_USER_CHECKED; |
| 3106 |
|
3223 |
|
| 3107 |
return local; |
3224 |
return (local & LOCAL_USER_FOUND); |
| 3108 |
} |
3225 |
} |
| 3109 |
|
3226 |
|
| 3110 |
/* checks that the user is at the local active X session */ |
3227 |
/* checks that the user is at the local active X session */ |