gnome-commander r1967 - branches/gcmd-1-3/tools/mimeedit
- From: epiotr svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-commander r1967 - branches/gcmd-1-3/tools/mimeedit
- Date: Tue, 12 Aug 2008 21:17:28 +0000 (UTC)
Author: epiotr
Date: Tue Aug 12 21:17:28 2008
New Revision: 1967
URL: http://svn.gnome.org/viewvc/gnome-commander?rev=1967&view=rev
Log:
Fix for potentially unsafe tmpfile creation
Modified:
branches/gcmd-1-3/tools/mimeedit/ChangeLog
branches/gcmd-1-3/tools/mimeedit/mimeedit.sh
Modified: branches/gcmd-1-3/tools/mimeedit/mimeedit.sh
==============================================================================
--- branches/gcmd-1-3/tools/mimeedit/mimeedit.sh (original)
+++ branches/gcmd-1-3/tools/mimeedit/mimeedit.sh Tue Aug 12 21:17:28 2008
@@ -1,11 +1,11 @@
#!/bin/bash
#
-# gnome-file-types-properties -
-# A zenity-script for chosing preferred applications.
-# Written by Magnus StÃlnacke (jemamo at telia.com)
-# Version 0.8.4 Nov. 30 2007
+# gnome-file-types-properties -
+# A zenity-script for choosing preferred applications.
+# Written by Magnus StÃlnacke (jemamo at telia.com)
+# Version 0.8.4.1 2008-08-12
#
-export LANG=en_US.utf8
+export LANG=en_US.utf8
ARGU="$1"
UTMP="/tmp/$(whoami)"
@@ -19,24 +19,24 @@
NONEW=1
#
-# Create dirs in users home if missing.
+# Create dirs in users home if missing.
#
if [ -e "$DATA_DIR" ]; then :; else mkdir $DATA_DIR;fi
-if [ -e "$U_DEF" ]
-then :;
-else
- echo "[Default Applications]" > $DATA_DIR/defaults.list
+if [ -e "$U_DEF" ]
+then :;
+else
+ echo "[Default Applications]" > $DATA_DIR/defaults.list
fi
#
-# Check how we got started.
+# Check how we got started.
#
function checkarg (){
if [ -n "$ARGU" ]
then
if [ -e "$ARGU" ]
then
- chkmtpe
+ chkmtpe
deflist
else
showhelp
@@ -63,11 +63,13 @@
# Build a list with registered apps for this mimetype.
#
function deflist (){
- if [ -e "$UTMP.avail" ]; then cleanup;fi
+ TMP_AVAIL="`mktemp /tmp/gnome-commander.XXXXXX`"
+ TMP_CHOSEN="`mktemp /tmp/gnome-commander.XXXXXX`"
+ # if [ -e "$UTMP.avail" ]; then cleanup;fi
# Create the list in "$UTMP.avail" to be used by the zenity list-box
if [ "$NONEW" == 1 ]
then
- echo "FALSE Add_New_App New" > "$UTMP.avail"
+ echo "FALSE Add_New_App New" > $TMP_AVAIL
fi
# Get all sub-mimetypes, one per row.
SUB="$(grep -hs "^$MTPE" $SUBC $G_CACHE $U_CACHE | awk -F= '{print $1}' | sed 's/ /\n/g')"
@@ -77,39 +79,39 @@
then
for i in $(echo "$MTPEs" | sort -u); do
echo "FALSE $i $(grep -hs "^Name=" $GDATA_DIR/$i $DATA_DIR/$i | \
- sed 's/Name=//;s/ /_/g')" >> "$UTMP.avail"
+ sed 's/Name=//;s/ /_/g')" >> $TMP_AVAIL
done
fi
- # Change FALSE to TRUE for the default app.
- if grep -q "desktop" "$UTMP.avail"
+ # Change FALSE to TRUE for the default app.
+ if grep -q "desktop" $TMP_AVAIL
then
DEF_APP=$(gnomevfs-info -s "$ARGU" | grep "Default app" | sed 's/.*: //')
- sed -i "s|FALSE $DEF_APP|TRUE $DEF_APP|" "$UTMP.avail"
+ sed -i "s|FALSE $DEF_APP|TRUE $DEF_APP|" $TMP_AVAIL
fi
# Show the list
zenity --height="350" --width="550" --list --radiolist --text \
-"The list below show applications that already have an entry for the mimetype:
-$MTPE on your system, meaning they are registered to be able
-to deal with this mimetype. You can choose your preferred default application
-by checking the radiobutton. The script will adjust the mimetype settings in
+"The list below show applications that already have an entry for the mimetype:
+$MTPE on your system, meaning they are registered to be able
+to deal with this mimetype. You can choose your preferred default application
+by checking the radiobutton. The script will adjust the mimetype settings in
your local home directory, thus not changing anything systemwide.
-If you wish you can add an application that is not in the list by checking the first
-option in list named Add_New_App
+If you wish you can add an application that is not in the list by checking the first
+option in list named Add_New_App
Please select" \
--column "Pick" --column ".desktop file" --column "Application" \
- $(cat "$UTMP.avail") > "$UTMP.chosen"
+ $(cat $TMP_AVAIL ) > $TMP_CHOSEN
retval=$?
- choice=$(cat "$UTMP.chosen")
+ choice=$(cat $TMP_CHOSEN )
if grep -q "$MTPE=$choice" $U_DEF
then
retval=2
fi
case $retval in
0)
- DEF_CH=$(grep -s "$choice" "$UTMP.avail" | awk '{print $2}')
- DEF_NME=$(grep -s "$choice" "$UTMP.avail" | awk '{print $3}')
+ DEF_CH=$(grep -s "$choice" $TMP_AVAIL | awk '{print $2}')
+ DEF_NME=$(grep -s "$choice" $TMP_AVAIL | awk '{print $3}')
if [ "$DEF_CH" = Add_New_App ]
then
newmime
@@ -142,14 +144,14 @@
#
function newmime (){
NEWAPP=$(zenity --entry --text \
-"Fill in the Name and command for the application you want to handle the
+"Fill in the Name and command for the application you want to handle the
mimetype: $MTPE separate them with a colon (:)
-Separate Name and Command with a colon. If you omit the command, or
-type something that is not in your path, you will get the chance to
+Separate Name and Command with a colon. If you omit the command, or
+type something that is not in your path, you will get the chance to
provide the command with full path by a file chooser dialog.")
- case $? in
+ case $? in
0)
if echo "$NEWAPP" | grep -q ":"
then
@@ -179,7 +181,7 @@
}
#
-# Check if the command exists in path, if not give the
+# Check if the command exists in path, if not give the
# user a filechooser.
#
function check (){
@@ -196,13 +198,13 @@
}
#
-# Create a new *.desktop file for the added app that can handle
+# Create a new *.desktop file for the added app that can handle
# the mimetype in question.
#
function usercreate(){
APP=$(basename "$CMD")
USER_APP="$DATA_DIR/$APP-$EXT"
- if cat $G_CACHE $U_CACHE | grep "$MTPE" | grep -q "$APP"
+ if cat $G_CACHE $U_CACHE | grep "$MTPE" | grep -q "$APP"
then
zenity --error --text "The mime type: $MTPE is alredy assigned to: $APP"
NOCH=yes
@@ -214,7 +216,7 @@
zenity --info --text \
"The mime type: $MTPE is now registered to be handled by: $APP"
else
- cat <<EOF >$USER_APP
+ cat <<EOF >$USER_APP
[Desktop Entry]
Encoding=UTF-8
Name=$NAME
@@ -229,16 +231,16 @@
if [ -z "$NOCH" ]
then
zenity --question --text \
-"The created $(basename "$USER_APP") can now be edited manually, to add, remove or change options, do you want to do this now?
+"The created $(basename "$USER_APP") can now be edited manually, to add, remove or change options, do you want to do this now?
-This file should work as is, so you can safely cancel this operation, but advanced users may want to edit options to their liking. But due to a bug this editor cannot handle '%' charachters and replaces them with garbage."
+This file should work as is, so you can safely cancel this operation, but advanced users may want to edit options to their liking. But due to a bug this editor cannot handle '%' characters and replaces them with garbage."
VAL=$?
if [ "$VAL" == 0 ]
- then
+ then
DT_FILE="$APP"
dtfedit
update
- else
+ else
update
fi
zenity --info --text "$APP is now registered to handle: $MTPE"
@@ -248,7 +250,7 @@
}
#
-# Update the users mime chache and set the defaults
+# Update the users mime chache and set the defaults
# first from the defaults.list file
#
function update (){
@@ -268,36 +270,36 @@
}
#
-# Give the user a helping hand.
+# Give the user a helping hand.
#
function showhelp (){
echo
echo "Usage: $(basename $0) [ARGUMENT]"
echo '''
- -h, -?, --help Show this help and exit.
+ -h, -?, --help Show this help and exit.
DESCRIPTION
- This script is dependent on zenity for creating its GUI. It is
- to be used as a tool for choosing the default application or to
- run for different type of files (mimetypes). It modifies or add
- files in "$HOME/.local/share/applications"
-
- When passed a valid filename it checks its mimetype as interpreted
- by gnomevfs, it will show a list of already registered applications
- able to handle the mimetype in question, the user can change default
- application in this list. The list also contains an option to add
- the Name and command of a program that is not registered to be able
- to open files of the mimetype. After any changes this script will
- run the update-desktop-database to update the users mime cache.
-
- When executed without any argument, the script will list all
- applications associated with a mimetype. When selecting an item from
- this list, the user will be able to edit the options for the selected
- application. The edited file will be saved in the above path and the
+ This script is dependent on zenity for creating its GUI. It is to be
+ used as a tool for choosing the default application or to run for
+ different type of files (mimetypes). It modifies or adds files in
+ "$HOME/.local/share/applications"
+
+ When passed a valid filename, it checks its mimetype as interpreted by
+ gnomevfs, it will show a list of already registered applications able
+ to handle the mimetype in question, the user can change default application
+ in this list. The list also contains an option to add the Name and
+ command of a program that is not registered to be able to open files
+ of the mimetype. After any changes this script will run the
+ update-desktop-database to update the users mime cache.
+
+ When executed without any argument, the script will list all
+ applications associated with a mimetype. When selecting an item from
+ this list, the user will be able to edit the options for the selected
+ application. The edited file will be saved in the above path and the
update-desktop-database is executed.
- When given an invalid argument or any of the options -h -? --help,
- this text is shown.
+ When given an invalid argument or any of the options -h -? --help,
+ this text is shown.
'''
}
@@ -305,8 +307,8 @@
# Remove tempfiles.
#
function cleanup (){
- rm -f "$UTMP.avail"
- rm -f "$UTMP.chosen"
+ rm -f $TMP_AVAIL
+ rm -f $TMP_CHOSEN
}
#
@@ -314,11 +316,11 @@
#
function selfile (){
DT_FILE=$(for i in $GDATA_DIR/*.desktop $DATA_DIR/*.desktop; do
- if grep -q "MimeType" $i
+ if grep -q "MimeType" $i
then
BNME=$(basename $i | sed 's/\.desktop//;s/-usercreated//')
- if [ -e $DATA_DIR/$BNME-$EXT ]
- then
+ if [ -e $DATA_DIR/$BNME-$EXT ]
+ then
i="$DATA_DIR/$BNME-$EXT"
fi
CMD=$(grep -m 1 "^Exec" $i | sed "s/^Exec=//")
@@ -327,50 +329,58 @@
fi
done | sort -u | sed 's/---/\n/g' | zenity --list --width="550" --height="400" \
--column="Base name" --column="Program name" --column="Program command" \
- --print-column="1" --text "Select item below.
+ --print-column="1" --text "Select item below.
-By selecting an item in this list and klick OK, you will get another window where
-you can edit the file that contains the options of the selected application. The
-edited file will end up in your: $DATA_DIR
-
-Pressing "Esc", click Cancel or use the window close (X) button will close without
-any changes in this or the following editor window. Be aware that the editor do
-have problems with the (%)percent charachter and may replace it by garbage.")
+By selecting an item in this list and klick OK, you will get another window where
+you can edit the file that contains the options of the selected application. The
+edited file will end up in your: $DATA_DIR
+
+Pressing "Esc", click Cancel or use the window close (X) button will close without
+any changes in this or the following editor window. Be aware that the editor do
+have problems with the (%) percent character and may replace it by garbage.")
}
#
# The .desktop file editor
#
-function dtfedit (){
+function dtfedit (){
+ TMPFILE=`mktemp /tmp/gnome-commander.XXXXXX`
USER_DTF="$DT_FILE-$EXT"
if [ -n "$DT_FILE" ]
- then
+ then
# Chose to edit users own file if exist
if [ -e $DATA_DIR/$USER_DTF ]
then
TO_EDIT="$DATA_DIR/$USER_DTF"
else
- TO_EDIT="$GDATA_DIR/$DT_FILE.desktop"
+ DT_FILE_PREFIX=$(echo $DT_FILE | sed -e 's|-[0-9][0-9]*||')
+ DT_FILE_SUFFIX=$(echo $DT_FILE | sed -n -e 's|^.*-\([0-9][0-9]*\)$|\1|p')
+ if [ -e $DATA_DIR/${DT_FILE_PREFIX}-usercreated-$DT_FILE_SUFFIX.desktop ]
+ then
+ TO_EDIT="$DATA_DIR/${DT_FILE_PREFIX}-usercreated-$DT_FILE_SUFFIX.desktop"
+ else
+ TO_EDIT="$GDATA_DIR/$DT_FILE.desktop"
+ fi
fi
cat "$TO_EDIT" | zenity --height="350" --width="550" --text-info --editable \
- --title "Edititng the file: $USER_DTF" > $UTMP.$USER_DTF
- if [ -s $UTMP.$USER_DTF ]
- then
- mv $UTMP.$USER_DTF $DATA_DIR/$USER_DTF
- else
- rm -f $UTMP.$USER_DTF
+ --title "Edititng the file: $USER_DTF" > $TMPFILE
+ if [ -s $TMPFILE ]
+ then
+ mv $TMPFILE $DATA_DIR/$USER_DTF
+ else
+ rm -f $TMPFILE
DT_FILE=""
fi
fi
-}
+}
#
# Check if we have zenity installed then start this mess.
#
-if which zenity >&/dev/null
+if which zenity >&/dev/null
then
- checkarg
-else
+ checkarg
+else
echo "Error: zenity not found!"
fi
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]