This file is indexed.

/usr/sbin/path2listing is in desktop-profiles 1.4.22.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/bin/sh
# This script is ment to allow you to setup gconf to manage confiuration 
# sources through desktop-profiles.
#
# It will read your a path file (the global gconf one by default) and will:
# - generate the necessary metadata to manage all profiles through 
#   desktop-profiles
# - adapt the global path file to manage all configuration sources with
#   desktop-profiles (unless told not to)
#
# (c) 2005 Bart Cornelis <cobaco AT skolelinux no>
#########################################################################

ROOT_PATH_FILE=/etc/gconf/2/path
CUSTOM_LISTINGS=/etc/desktop-profiles/desktop-profiles_path2listing.listing
DEFAULT_LISTINGS=/etc/desktop-profiles/desktop-profiles.listing

# default distance to leave between 2 successive priority sources
# we're leaving some distance to allow the easy insertion of later profiles
SOURCE_DISTANCE=50;

# we're processing the global path file by default
# -> so unless asked not to we'll want to replace it
GLOBAL_PATH_FILE=true;
REPLACE_PATH_FILE=true;

print_help () {
cat <<EOF
Usage: path2listing [OPTIONS]
  This script facilitates the conversion from:
  - managing gconf configuration sources directly through path files,
  - to managing them with the desktop-profiles package
  and will thus generaly be run only once directly after installing
  desktop-profiles

  It will generate the metadata (listing file) needed by desktop-profiles to
  manage the configuration sources that are activated directly or indirectly
  (i.e. through included path files) by the path file it is run on. 

  After the generation of the metadata the converted path file will be
  replaced by one assuming that desktop-profiles manages activation of
  configuration sources (unless you tell it not to).

Options:
  -d, --distance   : precedence distance between different configuration
                     sources (defaults to $SOURCE_DISTANCE), 
		     The idea is to leave some space between precedences so you
		     can easily insert other configuration sources later on.
  -f, --file       : path file to start conversion from 
                     (defaults to $ROOT_PATH_FILE)
  -o, --output-file: file to put the generated metadata in (defaults to 
                     $CUSTOM_LISTINGS)
  --no-replace-file: don't replace path file from which we start the conversion
                     with one that manages everything through desktop-profiles
  -h, --help    : display this helpmessage
EOF
}

# $1 is the path file to look at
# output is the reverse-priority ordered list of configuration sources that $1
# contains (directly, or indirectly through nested include directives). The 
# output will ignore the hooks for desktop-profiles if present (as we don't 
# need to generate any metadata for them).
#
# Note: not recursing down includes referring to environment variables as we 
#       can't be sure they'll resolve the same way when converting, and when
#       running as $random_user, keep them as includes
# Note: also don't recurse down includes referring to $(HOME) or $(USER), as
#       those are likely user-controlled, keeping as includes
#############################################################################
list_sources_in_path_file () {
  # if it's an existing file, process it, otherwise ignore it
  if (test -r "$1"); then
    # strip out comments & empty lines, leave only config sources and includes
    tac "$1" | sed -e "s/^[[:space:]]*//g" -e "s/[[:space:]]*$//g" | \
    grep -v "^#.*\|^$" | while read CONFIG_SOURCE; do
      # ignore desktop-profiles hooks (both the pre and post 1.4.6 versions) 
      # because we don't want metadata for them to be generated
      if ( (test "$CONFIG_SOURCE" = 'include $(ENV_MANDATORY_PATH)') ||
          (test "$CONFIG_SOURCE" = 'include *\$(ENV_DEFAULTS_PATH)') ||
          (test "$CONFIG_SOURCE" = 'include /var/cache/desktop-profiles/\$(USER)_mandatory.path') ||
          (test "$CONFIG_SOURCE" = 'include /var/cache/desktop-profiles/\$(USER)_defaults.path') ); then
	true;  
      # process nested path files
      elif (echo "$CONFIG_SOURCE" | grep "^include[[:space:]]*" > /dev/null); then
        # check if recursing makes sense (don't recurse when user-controlled or
	# dependend on current environment (which might be influenced by user)
        if (echo "$CONFIG_SOURCE" | grep -e "\$(HOME)" -e "\$(USER)" -e "\$(ENV_.*)" > /dev/null); then
	  echo "$CONFIG_SOURCE";
	else
          list_sources_in_path_file $(echo "$CONFIG_SOURCE" | sed "s/^include[[:space:]]*//");
	fi;  
      # process regular config sources	
      else 
        echo $CONFIG_SOURCE;
      fi;  
    done;  
  fi;  
}

# $1 is the confiuration source that makes up the new profile
# $2 is the precedence value
# $3 is the file where it should be added into
add_as_profile () {
  if (test -r "$3"); then 
    mandatory_number="$(expr $(cat "$3" | grep '^mandatory' | wc -l) + 1)";
    default_number="$(expr $(cat "$3" | grep '^default' | wc -l) + 1)";
  else 
    mandatory_number=1;
    default_number=1;
  fi;  
  
  if (test 0 -lt "$2"); then
    echo "mandatory_$mandatory_number;GCONF;$1;$2;;" >> "$3";
  elif (test 0 -gt "$2");then  
    echo "default_$default_number;GCONF;$1;$2;;" >> "$3";
  else
    echo "gconf-user-settings;GCONF;$1;$2;;Default location of user settings" >> $3;
  fi;  
}

# $1 is the file to backup
# $2 is the reason
make_backup_of () {
  if (test -e "$1"); then
    # tell user what we're doing
    echo "$1 already exists, and this script wil $2 it."
    echo "-> a backup of named $1.$(date --iso-8601=seconds) will be created."
    echo ;

    # make backup of current version
    mv "$1" "$1.$(date --iso-8601=seconds)";
  fi;  
}

#####################
# Parse command line 
#####################
while test $# -ge 1; do
  case $1 in
    -d | --distance)
      # takes positive integer as distance (between configuration sources)
      if (test $# -lt 2) || !(echo "$2" | grep -E '^[0-9]+$' > /dev/null); then
        print_help;
	exit;
      else # valid distance -> set it
        SOURCE_DISTANCE="$2";
      fi;
      shift 2; 
    ;;
    
     # takes path file to be converted as argument
    -f | --file)
      #validate argument, should be a readable path file
      if (test $# -lt 2) || !(test -r $2); then
        print_help;
	exit;	
      else #valid filename -> add to list of files to convert
        ROOT_PATH_FILE="$2";
        if (test "$ROOT_PATH_FILE" != /etc/gconf/2/path) || \
	   (test "$ROOT_PATH_FILE" != /etc/gconf/1/path); then
          GLOBAL_PATH_FILE=false;
        fi;
      fi;
      shift 2; 
    ;;

    # takes name of file that will contain the metada for the
    # converted configuration sources
    -o | --output-file)
      #check for argument
      if (test $# -lt 2); then
        print_help;
	exit;	
      else #Change name of metadata file accordingly
        CUSTOM_LISTINGS="$2";
      fi;
      shift 2; 
    ;;

    # takes boolean value
    --no-replace-file)
      REPLACE_PATH_FILE=false;
      shift;
    ;;

    -h| --help | *)
      print_help;
      exit;
    ;;
  esac;  
done;  

######################################
# Check if we need to do anything, 
# and communicate that with the admin
######################################
  # Check if ROOT_PATH_FILE is equal to ideal path file state
  if (diff $ROOT_PATH_FILE /usr/share/desktop-profiles/path 2>&1 > /dev/null); then
    #equal -> nothing to do 
    echo "$ROOT_PATH_FILE file is already converted to desktop-profiles:";
    echo "  -> nothing to do";
    echo "  -> exiting";
    exit;
  # check for precense of current desktop-profiles hooks
  # if so warn that the precedence might not be correct 
  # they're different -> so we need to convert
  elif 
  (grep 'include *\$(ENV_MANDATORY_PATH)' "$ROOT_PATH_FILE" 2>&1 > /dev/null) ||
  (grep 'include *\$(ENV_DEFAULTS_PATH)' "$ROOT_PATH_FILE" 2>&1 > /dev/null); then
    true;#FIXME;
  # check for precense of old desktop-profiles hooks
  # if so warn that the precedence might not be correct 
  # they're different -> so we need to convert
  elif 
  (grep 'include /var/cache/desktop-profiles/\$(USER)_mandatory.path' "$ROOT_PATH_FILE" 2>&1 > /dev/null) ||
  (grep 'include /var/cache/desktop-profiles/\$(USER)_defaults.path' "$ROOT_PATH_FILE" 2>&1 > /dev/null); then
    true;#FIXME;
  else
    echo "Metadata for all configuration sources contained in $ROOT_PATH_FILE";
    echo "(wether contained directly, or indirectly through includes) will be"
    echo "generated and put in $CUSTOM_LISTINGS."
    echo;
  fi;

################################
# Deal with generating metadata
################################
 USER_SOURCE_RANK=$(list_sources_in_path_file $ROOT_PATH_FILE | nl | \
 grep 'xml:readwrite:\$(HOME)/.gconf' | sed "s/^[[:space:]]*//g" | cut --fields 1);

  # check if file, we'll be messing with already exists, if so create backup
  make_backup_of "$CUSTOM_LISTINGS" regenerate

  # iterate over all configuration sources, listed directly or indirectly by the 
  # $ROOT_PATH_FILE (by default = /etc/gconf/2/path)
  list_sources_in_path_file $ROOT_PATH_FILE | nl | sed "s/^[[:space:]]*//g" | \
  while read ITEM; do
    # the  '- USER_SOURCE_RANK * SOURCE_DISTANCE' at the end is to ensure that
    # the user-source ends up with precedence 0, yielding all mandatory sources
    # with a positive precedence, and all default sources with a negative one
    PRECEDENCE="$(expr $(echo "$ITEM" | cut --fields 1) \* $SOURCE_DISTANCE - $USER_SOURCE_RANK \* $SOURCE_DISTANCE)";
    CONFIG_SOURCE="$(echo "$ITEM" | cut --fields 2)";

    # add a profile-metadata entry for this configuration source
    add_as_profile "$CONFIG_SOURCE" "$PRECEDENCE" "$CUSTOM_LISTINGS";
  done;

######################################
# Deal with changing global path file
######################################
if (test $REPLACE_PATH_FILE = true); then
  # make backup-copy of $ROOT_PATH_FILE, before changing it
  if (test -e "$ROOT_PATH_FILE"); then
    # tell user what we're doing
    echo "The global path file will now be replaced with one assuming all "
    echo "configuration sources are managed by desktop-profiles."
    echo "-> a backup named $ROOT_PATH_FILE.$(date --iso-8601=seconds) will be created."
    echo ;

    # make backup of current version  
    mv "$ROOT_PATH_FILE" "$ROOT_PATH_FILE.$(date --iso-8601=seconds)";
  fi;  

  # actually replace global path file
  cp /usr/share/desktop-profiles/path "$ROOT_PATH_FILE";
fi;