4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jungmin Cho <chivalry.cho@samsung.com>, Gwangho Hwang <gwang.hwang@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
30 static int recurse(const char *path, mode_t mode, int (*fn)(const char *,mode_t, int)) {
37 if (lstat (path, &st) == -1) {
40 if (strrchr(path, '/') != NULL) {
41 int n = strlen(path)-strlen(strrchr(path, '/'));
45 strncpy(dir, path, n);
53 int dlp_chmod(const char *path, mode_t mode, int recursive) {
54 #ifdef HAVE_WIN32_PROC
55 fprintf(stderr, "error: dlp_chmod not implemented on Win32 (%s)\n", path);
59 struct stat lstat_info;
60 struct stat fstat_info;
62 if (lstat (path, &lstat_info) == -1)
65 fd = open(path, O_WRONLY, S_IRWXU);
69 if (fstat (fd, &fstat_info) == -1)
75 // this complex check is required because of 'chmod' security issue.
76 // otherwise hacker can change other file's permission by using race condition and symbolic link.
77 if(lstat_info.st_mode == fstat_info.st_mode &&
78 lstat_info.st_ino == fstat_info.st_ino &&
79 lstat_info.st_dev == fstat_info.st_dev){
80 if (fchmod (fd, mode) == -1) {
89 return recurse(path, mode, dlp_chmod);