Paul Crowley | 1a96526 | 2017-10-13 13:49:50 -0700 | [diff] [blame] | 1 | #!/system/bin/sh |
| 2 | # |
| 3 | # Copyright (C) 2017 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
Paul Crowley | 8e55066 | 2017-10-16 17:01:44 -0700 | [diff] [blame] | 17 | # Set up or tear down subdirectories of vold-created directories. |
| 18 | # |
| 19 | # This is kept separate from vold because under the SELinux rules, it has privileges vold doesn't |
| 20 | # have. In particular, prepare_dir sets SELinux labels on subdirectories based on file_contexts, |
| 21 | # so this script has some relabelling privileges. |
Paul Crowley | 1a96526 | 2017-10-13 13:49:50 -0700 | [diff] [blame] | 22 | |
Paul Crowley | 8e55066 | 2017-10-16 17:01:44 -0700 | [diff] [blame] | 23 | |
| 24 | set -e |
| 25 | action="$1" |
| 26 | dirtype="$2" |
| 27 | volume_uuid="$3" |
| 28 | user_id="$4" |
| 29 | path="$5" |
| 30 | |
| 31 | case "$user_id" in |
| 32 | *[!0-9]* | '') |
| 33 | echo "Invalid user id" |
| 34 | exit -1 |
| 35 | ;; |
Paul Crowley | 1a96526 | 2017-10-13 13:49:50 -0700 | [diff] [blame] | 36 | esac |
| 37 | |
Paul Crowley | 8e55066 | 2017-10-16 17:01:44 -0700 | [diff] [blame] | 38 | if [ x"$volume_uuid" != x ] ; then |
Paul Crowley | 1a96526 | 2017-10-13 13:49:50 -0700 | [diff] [blame] | 39 | echo "Volume must be root volume" |
| 40 | exit -1; |
| 41 | fi |
| 42 | |
Paul Crowley | 8e55066 | 2017-10-16 17:01:44 -0700 | [diff] [blame] | 43 | case "$dirtype" in |
Paul Crowley | 1a96526 | 2017-10-13 13:49:50 -0700 | [diff] [blame] | 44 | misc_de|misc_ce) |
Paul Crowley | 8e55066 | 2017-10-16 17:01:44 -0700 | [diff] [blame] | 45 | computed_path="/data/$dirtype/$user_id" |
| 46 | if [ x"$computed_path" != x"$path" ] ; then |
Paul Crowley | 1a96526 | 2017-10-13 13:49:50 -0700 | [diff] [blame] | 47 | echo "Parameter path didn't match computed path: " $computed_path |
| 48 | exit -1; |
| 49 | fi |
Paul Crowley | 8e55066 | 2017-10-16 17:01:44 -0700 | [diff] [blame] | 50 | case "$action" in |
| 51 | prepare) |
| 52 | /system/bin/prepare_dir --mode 700 --uid 0 --gid 0 -- "$computed_path"/vold |
| 53 | ;; |
| 54 | destroy) |
| 55 | rm -rf "$computed_path"/* |
| 56 | ;; |
| 57 | *) |
| 58 | echo "Unknown action: $action" |
| 59 | exit -1 |
| 60 | ;; |
| 61 | esac |
Paul Crowley | 1a96526 | 2017-10-13 13:49:50 -0700 | [diff] [blame] | 62 | ;; |
| 63 | *) |
Paul Crowley | 8e55066 | 2017-10-16 17:01:44 -0700 | [diff] [blame] | 64 | echo "Unknown type: $dirtype" |
| 65 | exit -1 |
Paul Crowley | 1a96526 | 2017-10-13 13:49:50 -0700 | [diff] [blame] | 66 | ;; |
| 67 | esac |