From a94513b02e5e88ec0fb7decafe314ae45b156b30 Mon Sep 17 00:00:00 2001 From: "syd%netscape.com" Date: Mon, 7 Jan 2002 00:33:55 +0000 Subject: [PATCH] Check for correct permissions on chosen install directory by calling access() instead of just looking to see if the user rwx bits are set (this fails if you are installing to a directory you do not own). r=samir, ssu, sr=dveditz. Fixes bug number 89436. git-svn-id: svn://10.0.0.236/trunk@111468 18797224-902f-48f8-a5cc-f745e15eee43 --- .../wizard/unix/src2/nsSetupTypeDlg.cpp | 71 +++++++++---------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/mozilla/xpinstall/wizard/unix/src2/nsSetupTypeDlg.cpp b/mozilla/xpinstall/wizard/unix/src2/nsSetupTypeDlg.cpp index 2698a228697..f1397a6ea55 100644 --- a/mozilla/xpinstall/wizard/unix/src2/nsSetupTypeDlg.cpp +++ b/mozilla/xpinstall/wizard/unix/src2/nsSetupTypeDlg.cpp @@ -661,12 +661,15 @@ nsSetupTypeDlg::SelectFolderOK(GtkWidget *aWidget, GtkFileSelection *aFileSel) struct stat destStat; char *selDir = gtk_file_selection_get_filename( GTK_FILE_SELECTION(aFileSel)); - if (0 == stat(selDir, &destStat)) - if (!S_ISDIR(destStat.st_mode)) /* not a directory so don't tear down */ - return; + + // put the candidate file name in the global variable, then verify it strcpy(gCtx->opt->mDestination, selDir); + if (0 == stat(selDir, &destStat)) + if (!S_ISDIR(destStat.st_mode) || VerifyDestination() != OK ) /* not a directory, or we don't have access permissions, so don't tear down */ + return; + // update folder path displayed gtk_label_set_text(GTK_LABEL(sFolder), gCtx->opt->mDestination); gtk_widget_show(sFolder); @@ -703,45 +706,41 @@ nsSetupTypeDlg::VerifyDestination() GtkWidget *yesButton, *noButton, *label; GtkWidget *noPermsDlg, *okButton; char message[MAXPATHLEN]; - + stat_err = stat(gCtx->opt->mDestination, &stbuf); if (stat_err == 0) { - // check perms on dir: we need rwx for user - if ( !(stbuf.st_mode & S_IREAD) || - !(stbuf.st_mode & S_IWRITE) || - !(stbuf.st_mode & S_IEXEC) ) + if (access(gCtx->opt->mDestination, R_OK | W_OK | X_OK ) != 0) + { + sprintf(message, gCtx->Res("NO_PERMS"), gCtx->opt->mDestination); + + noPermsDlg = gtk_dialog_new(); + label = gtk_label_new(message); + okButton = gtk_button_new_with_label(gCtx->Res("OK_LABEL")); + + if (noPermsDlg && label && okButton) { - sprintf(message, gCtx->Res("NO_PERMS"), gCtx->opt->mDestination); + gtk_window_set_title(GTK_WINDOW(noPermsDlg), gCtx->opt->mTitle); + gtk_window_set_position(GTK_WINDOW(noPermsDlg), + GTK_WIN_POS_CENTER); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_box_pack_start(GTK_BOX( + GTK_DIALOG(noPermsDlg)->action_area), okButton, FALSE, FALSE, 10); + gtk_signal_connect(GTK_OBJECT(okButton), "clicked", + GTK_SIGNAL_FUNC(NoPermsOK), noPermsDlg); + gtk_box_pack_start(GTK_BOX( + GTK_DIALOG(noPermsDlg)->vbox), label, FALSE, FALSE, 10); - noPermsDlg = gtk_dialog_new(); - label = gtk_label_new(message); - okButton = gtk_button_new_with_label(gCtx->Res("OK_LABEL")); - - if (noPermsDlg && label && okButton) - { - gtk_window_set_title(GTK_WINDOW(noPermsDlg), gCtx->opt->mTitle); - gtk_window_set_position(GTK_WINDOW(noPermsDlg), - GTK_WIN_POS_CENTER); - gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); - gtk_box_pack_start(GTK_BOX( - GTK_DIALOG(noPermsDlg)->action_area), okButton, - FALSE, FALSE, 10); - gtk_signal_connect(GTK_OBJECT(okButton), "clicked", - GTK_SIGNAL_FUNC(NoPermsOK), noPermsDlg); - gtk_box_pack_start(GTK_BOX( - GTK_DIALOG(noPermsDlg)->vbox), label, FALSE, FALSE, 10); - - gtk_widget_show_all(noPermsDlg); - } - - return E_NO_PERMS; - } - else - { - // perms OK, we can proceed - return OK; + gtk_widget_show_all(noPermsDlg); } + + return E_NO_PERMS; + } + else + { + // perms OK, we can proceed + return OK; + } } // destination doesn't exist so ask user if we should create it