diff options
Diffstat (limited to 'frontend/xsane.c')
-rw-r--r-- | frontend/xsane.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/frontend/xsane.c b/frontend/xsane.c index 6302168..89a54a0 100644 --- a/frontend/xsane.c +++ b/frontend/xsane.c @@ -44,6 +44,11 @@ /* ---------------------------------------------------------------------------------------------------------------------- */ +char *path_sane_tmp = NULL; +extern int errno; + +/* ---------------------------------------------------------------------------------------------------------------------- */ + struct option long_options[] = { {"help", no_argument, 0, 'h'}, @@ -4685,9 +4690,39 @@ void xsane_interface(int argc, char **argv) int main(int argc, char **argv) { + int len; + char *login; + struct stat st; + dialog = 0; memset(&xsane, 0, sizeof(xsane)); /* set all values in xsane to 0 */ + /* Create directory PATH_SANE_TMP/xsane-$uid */ + login = getlogin (); + if (login == NULL) { + if ((login = (char *)malloc (10)) == NULL) + return 1; + snprintf (login, 10, "%d", getuid ()); + } + + len = strlen (login) + strlen (PATH_SANE_TMP) + 8; + if ((path_sane_tmp = (char *)malloc (len)) == NULL) + return 1; + sprintf (path_sane_tmp, "%s/xsane-%s", PATH_SANE_TMP, login); + + if (lstat (path_sane_tmp, &st)) { + if (errno == ENOENT) { + if (mkdir (path_sane_tmp, 0700)) + return 1; /* Can't create dir, huh? */ + } else + return 1; /* Can't stat, huh? */ + } else { + if (st.st_uid != getuid()) { + fprintf (stderr, "%s not owned by you, security problem?\n", path_sane_tmp); + return 1; + } + } + umask(XSANE_DEFAULT_UMASK); /* define permissions of new files */ xsane.sensitivity = TRUE; |