* limitations under the License.
*/
-#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
*/
#define DIR_PERMISSION 0777
-static struct tzplatform_context* sdk_user_context = NULL;
-
void init_sdk_sync_permit_rule_regx(void)
{
int ret;
return;
}
-static void deinit_sdk_user_context(void) {
- if (sdk_user_context != NULL) {
- tzplatform_context_destroy(sdk_user_context);
- sdk_user_context = NULL;
- }
-}
-
-// return 0 if success to initialize
-// return negative value otherwise
-static int init_sdk_user_context() {
- if (sdk_user_context == NULL) {
- int ret = tzplatform_context_create(&sdk_user_context);
- if (ret < 0) {
- D ("failed to create tzplatform context by error (%d)\n", ret);
- return ret;
- }
-
- ret = tzplatform_context_set_user(sdk_user_context, g_sdk_user_id);
- if (ret < 0) {
- D ("failed to set user to sdk_user_context\n");
- return ret;
- }
-
- atexit(deinit_sdk_user_context);
- }
-
- return 0;
-}
-
-// return 1 if given directory is writable by others
-// return 0 otherwise
-static int is_writable_by_others(char* path) {
- int ret = 0;
-
- if ( init_sdk_user_context() == 0 ) {
- const char* content_path = tzplatform_context_getenv(sdk_user_context, TZ_USER_CONTENT);
- char* abpath = realpath(path, NULL);
- D ("tzplatform getenv : %s\n", content_path);
-
- if (abpath != NULL) {
- if (strncmp(abpath, content_path, strlen(content_path)) == 0) {
- D("path (%s) is writable by others\n", path);
- ret = 1;
- }
- free(abpath);
- } else {
- D("failed to get realpath of (%s)\n", path);
- }
- } else {
- // do nothing
- // no directory is writable by others
- }
-
- return ret;
-}
-
static int handle_send_file(int s, int noti_fd, char *path, mode_t mode, char *buffer)
{
syncmsg msg;
return -1;
}
- D("send path (%s)\n", path);
-
tmp = strrchr(path,',');
if(tmp) {
*tmp = 0;
#endif
// extracts file permission from stat.mode. (ex 100644 & 0777 = 644);
mode &= 0777; // combination of (S_IRWXU | S_IRWXG | S_IRWXO)
+ mode |= S_IWOTH; // SDK requirement from N_SE-43337
}
if(!tmp || errno) {
mode = 0644; // set default permission value in most of unix system.
// sdb does not allow to check that file exists or not. After deleting old file and creating new file again unconditionally.
sdb_unlink(path);
+
#ifdef HAVE_SYMLINKS
if(is_link)
ret = handle_send_link(s, noti_fd, path, buffer);
//mode |= ((mode >> 3) & 0070);
//mode |= ((mode >> 3) & 0007);
ret = handle_send_file(s, noti_fd, path, mode, buffer);
- if (is_writable_by_others(path)) {
- mode_t realmode = mode & ~(SDBD_UMASK);
- realmode |= S_IWOTH;
- if (chmod(path, realmode) != 0) {
- D ("failed to chmod of writable path by others\n");
- }
- }
}
return ret;