コード例 #1
0
ファイル: vfs_python.c プロジェクト: jeagle/win_fuse_smb
static int python_rename(vfs_handle_struct *handle,
			   const struct smb_filename *smb_fname_src,
			   const struct smb_filename *smb_fname_dst)
{
	struct pyfuncs *pf = handle->data;
	PyObject *pArgs, *pRet, *pValue;
	char full_path_buf[PY_MAXPATH];
	const char *full_path;
	int i;

	if (!pf->pFuncRename) {
		errno = ENOSYS;
		return -1;
	}

	PY_TUPLE_NEW(2);
	full_path = make_full_path(handle, smb_fname_src->base_name, (char *) &full_path_buf);
	PY_ADD_TO_TUPLE((char *) &full_path_buf, PyString_FromString, 0);
	full_path = make_full_path(handle, smb_fname_dst->base_name, (char *) &full_path_buf);
	PY_ADD_TO_TUPLE((char *) &full_path_buf, PyString_FromString, 1);
	PY_CALL_WITH_ARGS(Rename);

	i = PyInt_AsLong(pRet);

	Py_DECREF(pRet);
	return i;
}
コード例 #2
0
ファイル: vfs_python.c プロジェクト: jeagle/win_fuse_smb
static int python_link(vfs_handle_struct *handle,  const char *oldpath, const char *newpath)
{
	struct pyfuncs *pf = handle->data;
	PyObject *pArgs, *pRet, *pValue;
	char full_path_buf[PY_MAXPATH];
	const char *full_path;
	int i;

	if (!pf->pFuncLink) {
		errno = ENOSYS;
		return -1;
	}

	PY_TUPLE_NEW(2);
	full_path = make_full_path(handle, oldpath, (char *) &full_path_buf);
	PY_ADD_TO_TUPLE((char *) &full_path_buf, PyString_FromString, 0);
	full_path = make_full_path(handle, newpath, (char *) &full_path_buf);
	PY_ADD_TO_TUPLE((char *) &full_path_buf, PyString_FromString, 1);
	PY_CALL_WITH_ARGS(Link);

	i = PyInt_AsLong(pRet);

	Py_DECREF(pRet);
	return i;
}
コード例 #3
0
ファイル: main.c プロジェクト: Telegram-FFOS/tg
void parse_config (void) {
  config_filename = make_full_path (config_filename);
  
  config_t conf;
  config_init (&conf);
  if (config_read_file (&conf, config_filename) != CONFIG_TRUE) {
    fprintf (stderr, "Can not read config '%s': error '%s' on the line %d\n", config_filename, config_error_text (&conf), config_error_line (&conf));
    exit (2);
  }

  if (!prefix) {
    config_lookup_string (&conf, "default_profile", (void *)&prefix);
  }

  static char buf[1000];
  int l = 0;
  if (prefix) {
    l = strlen (prefix);
    memcpy (buf, prefix, l);
    buf[l ++] = '.';
  }
  test_dc = 0;
  strcpy (buf + l, "test");
  config_lookup_bool (&conf, buf, &test_dc);
  
  strcpy (buf + l, "log_level");
  long long t = log_level;
  config_lookup_int (&conf, buf, (void *)&t);
  log_level = t;
  
  if (!msg_num_mode) {
    strcpy (buf + l, "msg_num");
    config_lookup_bool (&conf, buf, &msg_num_mode);
  }

  parse_config_val (&conf, &config_directory, "config_directory", CONFIG_DIRECTORY, 0);
  config_directory = make_full_path (config_directory);

  parse_config_val (&conf, &auth_file_name, "auth_file", AUTH_KEY_FILE, config_directory);
  parse_config_val (&conf, &state_file_name, "state_file", STATE_FILE, config_directory);
  parse_config_val (&conf, &secret_chat_file_name, "secret", SECRET_CHAT_FILE, config_directory);
  parse_config_val (&conf, &downloads_directory, "downloads", DOWNLOADS_DIRECTORY, config_directory);
  parse_config_val (&conf, &binlog_file_name, "binlog", BINLOG_FILE, config_directory);
  
  strcpy (buf + l, "binlog_enabled");
  config_lookup_bool (&conf, buf, &binlog_enabled);
  
  if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) {
    printf ("[%s] created\n", config_directory);
  }
  if (!mkdir (downloads_directory, CONFIG_DIRECTORY_MODE)) {
    printf ("[%s] created\n", downloads_directory);
  }
}
コード例 #4
0
ファイル: vfs_python.c プロジェクト: jeagle/win_fuse_smb
static int python_stat_or_lstat(vfs_handle_struct *handle, struct smb_filename *smb_fname, long do_lstat)
{
	PyObject *pArgs, *pValue, *pRet;
	struct pyfuncs *pf = handle->data;
	char full_path_buf[PY_MAXPATH];
	const char *full_path;

	/* We don't support streams (yet?) */
	if (smb_fname->stream_name) {
		errno = ENOENT;
		return -1;
	}

	PY_TUPLE_NEW(2);
	full_path = make_full_path(handle, smb_fname->base_name, (char *) &full_path_buf);
	PY_ADD_TO_TUPLE(full_path, PyString_FromString, 0);
	PY_ADD_TO_TUPLE(do_lstat, PyInt_FromLong, 1);
	PY_CALL_WITH_ARGS(Stat);

	if (!PyMapping_Check(pRet)) {
		Py_DECREF(pRet);
		errno = ENOENT;
		return -1;
	}

	return python_stat_helper(pRet, &smb_fname->st);
}
コード例 #5
0
ファイル: vfs_python.c プロジェクト: jeagle/win_fuse_smb
static int python_open(vfs_handle_struct *handle, struct smb_filename *smb_fname,
			 files_struct *fsp, int flags, mode_t mode)
{
	struct pyfuncs *pf = handle->data;
	PyObject *pArgs, *pRet, *pValue;
	char full_path_buf[PY_MAXPATH];
	const char *full_path;
	int r;

	PY_TUPLE_NEW(3);
	full_path = make_full_path(handle, smb_fname->base_name, (char *) &full_path_buf);
	PY_ADD_TO_TUPLE((char *) &full_path_buf, PyString_FromString, 0);
	PY_ADD_TO_TUPLE(flags, PyInt_FromLong, 1);
	PY_ADD_TO_TUPLE(mode, PyInt_FromLong, 2);
	PY_CALL_WITH_ARGS(OpenFile);

	if (PyInt_AS_LONG(pRet) < 0) {
		errno = -1 * PyInt_AS_LONG(pRet);
		Py_DECREF(pRet);
		return -1;
	}

	r = PyInt_AS_LONG(pRet);
	Py_DECREF(pRet);
	return r;
}
コード例 #6
0
ファイル: vfs_python.c プロジェクト: jeagle/win_fuse_smb
static int python_vfs_readlink(vfs_handle_struct *handle, const char *path, char *buf, size_t bufsiz)
{
	struct pyfuncs *pf = handle->data;
	PyObject *pArgs, *pRet, *pValue;
	char full_path_buf[PY_MAXPATH];
	const char *full_path;
	char *dest;

	if (!pf->pFuncReadLink) {
		errno = ENOSYS;
		return -1;
	}

	PY_TUPLE_NEW(1);
	full_path = make_full_path(handle, path, (char *) &full_path_buf);
	PY_ADD_TO_TUPLE(full_path, PyString_FromString, 0);
	PY_CALL_WITH_ARGS(ReadLink);

	dest = PyString_AsString(pRet);
	/* bufsz includes the NULL terminator, so even if the lengths are equal
	   it's not enough space. */
	if (strlen(dest) >= bufsiz) {
		errno = ENOMEM;
		return -1;
	}
	strncpy(buf, dest, bufsiz);
	return 0;
}
コード例 #7
0
dbus_bool_t
bus_config_parser_trivial_test (const DBusString *test_data_dir)
{
  DBusString full_path;
  dbus_bool_t retval;

  retval = FALSE;

  if (test_data_dir == NULL ||
      _dbus_string_get_length (test_data_dir) == 0)
    {
      printf ("No test data\n");
      return TRUE;
    }
  
  /* We already test default_session_servicedirs and default_system_servicedirs
   * in bus_config_parser_test() */
  if (!process_test_valid_subdir (test_data_dir, "valid-config-files", VALID))
    goto finish;

  /* we don't process all the invalid files, as the trivial parser can't hope
   * to validate them all for all different syntaxes. We just check one broken
   * file to see if junk is received */
  if (!make_full_path (test_data_dir, "invalid-config-files", "not-well-formed.conf", &full_path))
    goto finish;
  if (!check_file_valid (&full_path, INVALID))
    goto finish;
  _dbus_string_free (&full_path);

  /* just test if the check_file_valid works okay and we got sane values */
  if (!make_full_path (test_data_dir, "valid-config-files", "system.conf", &full_path))
    goto finish;
  if (!check_file_valid (&full_path, VALID))
    goto finish;
  /* check to see if we got the correct values from the parser */
  if (!check_return_values (&full_path))
    goto finish;

  /* woot! */
  retval = TRUE;

finish:
  _dbus_string_free (&full_path);

  /* we don't process equiv-config-files as we don't handle <include> */
  return retval;
}
コード例 #8
0
ファイル: fileapi.cpp プロジェクト: Aerodynamic/rhodes
static bool need_emulate_dir(std::string const &path)
{
    std::string fpath = make_full_path(path);
    std::string const &root_path = rho_root_path();
    if (fpath.size() < root_path.size())
        return false;
    return ::strncmp(fpath.c_str(), root_path.c_str(), root_path.size()) == 0;
}
コード例 #9
0
ファイル: fileapi.cpp プロジェクト: croteb/rhodes
static rho_stat_t *rho_stat(const char *path)
{
    std::string relpath = make_rel_path(make_full_path(path));
    rho_stat_map_t::iterator it = rho_stat_map.find(relpath);
    if (it == rho_stat_map.end())
        return NULL;
    return &(it->second);
}
コード例 #10
0
ファイル: fileapi.cpp プロジェクト: melvinsembrano/rhodes
inline bool need_emulate_dir(std::string const &path)
{
    if (rho_fs_mode != RHO_FS_TRANSPARRENT) return false;

    std::string fpath = make_full_path(path);
    std::string const &root_path = rho_root_path();
    if (fpath.size() < root_path.size())
        return false;
    return ::strncmp(fpath.c_str(), root_path.c_str(), root_path.size()) == 0;
}
コード例 #11
0
ファイル: check_exist.c プロジェクト: v3t3a/42_projects
int				file_exist(char *file, char *path)
{
	char	*full;
	int		exist;

	if (!file || !path || file[0] == '\0' || path[0] == '\0')
		return (0);
	full = make_full_path(file, path);
	exist = (access(full, F_OK)) ? 0 : 1;
	ft_strdel(&full);
	return (exist);
}
コード例 #12
0
ファイル: main.c プロジェクト: analani/tg
void running_for_first_time (void) {
  check_type_sizes ();
  if (config_filename) {
    return; // Do not create custom config file
  }
  tasprintf (&config_filename, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, CONFIG_FILE);
  config_filename = make_full_path (config_filename);

  int config_file_fd;
  char *config_directory = get_config_directory ();
  //char *downloads_directory = get_downloads_directory ();

  if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) {
    if (!disable_output) {
      printf ("[%s] created\n", config_directory);
    }
  }

  tfree_str (config_directory);
  config_directory = NULL;
  // see if config file is there
  if (access (config_filename, R_OK) != 0) {
    // config file missing, so touch it
    config_file_fd = open (config_filename, O_CREAT | O_RDWR, 0600);
    if (config_file_fd == -1)  {
      perror ("open[config_file]");
      exit (EXIT_FAILURE);
    }
    if (write (config_file_fd, DEFAULT_CONFIG_CONTENTS, strlen (DEFAULT_CONFIG_CONTENTS)) <= 0) {
      perror ("write[config_file]");
      exit (EXIT_FAILURE);
    }
    close (config_file_fd);
    /*int auth_file_fd = open (get_auth_key_filename (), O_CREAT | O_RDWR, 0600);
    int x = -1;
    assert (write (auth_file_fd, &x, 4) == 4);
    close (auth_file_fd);

    printf ("[%s] created\n", config_filename);*/
  
    /* create downloads directory */
    /*if (mkdir (downloads_directory, 0755) !=0) {
      perror ("creating download directory");
      exit (EXIT_FAILURE);
    }*/
  }
}
コード例 #13
0
ファイル: fcgi_util.c プロジェクト: ceph/mod_fastcgi
/*******************************************************************************
 * Return absolute path to file in either "regular" FCGI socket directory or
 * the dynamic directory.  Result is allocated in pool p.
 */
const char *
fcgi_util_socket_make_path_absolute(pool * const p, 
        const char *const file, const int dynamic)
{
#ifdef APACHE2
    if (ap_os_is_path_absolute(p, (char *) file))
#else
    if (ap_os_is_path_absolute(file))
#endif
    {
	    return file;
    }
    else
    {
        const char * parent_dir = dynamic ? fcgi_dynamic_dir : fcgi_socket_dir;
        return (const char *) make_full_path(p, parent_dir, file);
    }
}
コード例 #14
0
ファイル: main.c プロジェクト: pwrtelegram/tg
void running_for_first_time (void) {
  check_type_sizes ();
  if (!str_empty (config_filename)) {
    return; // Do not create custom config file
  }
  if (str_empty (config_directory)) {
    config_directory = get_config_directory ();
  }
  tasprintf (&config_filename, "%s/%s", config_directory, CONFIG_FILE);
  config_filename = make_full_path (config_filename);
  if (!disable_output) {
    printf ("I: config dir=[%s]\n", config_directory);
  }
  // printf ("I: config file=[%s]\n", config_filename);

  int config_file_fd;
  //char *config_directory = get_config_directory ();
  //char *downloads_directory = get_downloads_directory ();

  if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) {
    if (!disable_output) {
      printf ("[%s] created\n", config_directory);
    }
  }

  tfree_str (config_directory);
  config_directory = NULL;
  // see if config file is there
  if (access (config_filename, R_OK) != 0) {
    // config file missing, so touch it
    config_file_fd = open (config_filename, O_CREAT | O_RDWR, 0600);
    if (config_file_fd == -1)  {
      perror ("open[config_file]");
      printf ("I: config_file=[%s]\n", config_filename);
      exit (EXIT_FAILURE);
    }
    if (write (config_file_fd, DEFAULT_CONFIG_CONTENTS, strlen (DEFAULT_CONFIG_CONTENTS)) <= 0) {
      perror ("write[config_file]");
      exit (EXIT_FAILURE);
    }
    close (config_file_fd);
  }
}
コード例 #15
0
ファイル: execute.c プロジェクト: MItsutoshiNAKANO/sj3
void
exec_openstdy()
{
	char	filename[MAXPATHLEN];
	char	password[PASSWORDLEN];
	StdyFile *stdy;

	get_nstring(filename, sizeof(filename));
	get_nstring(password, sizeof(password));

	if (cur_cli -> stdy)
		longjmp(error_ret, SJ3_StdyAlreadyOpened);
	if (make_full_path(filename, sizeof(filename)))
		longjmp(error_ret, SJ3_TooLongParameter);

	if (!(stdy = openstdy(filename, password)))
		longjmp(error_ret, serv_errno);
	cur_cli -> stdy = stdy;

	put_int(SJ3_NormalEnd);
}
コード例 #16
0
ファイル: fileapi.cpp プロジェクト: Aerodynamic/rhodes
static bool need_emulate(std::string const &path)
{
    //RHO_LOG("need_emulate: %s", path.c_str());
    std::string fpath = make_full_path(path);
    //RHO_LOG("need_emulate: (1): %s", fpath.c_str());
    std::string const &root_path = rho_root_path();
    if (::strncmp(fpath.c_str(), root_path.c_str(), root_path.size()) == 0)
    {
        //RHO_LOG("need_emulate: (2)");
        struct stat st;
        if (real_stat(fpath.c_str(), &st) == -1)
        {
            //RHO_LOG("need_emulate: (3)");
            if (errno == ENOENT)
            {
                //RHO_LOG("No such file or directory: %s, need to read it from Android package", fpath.substr(root_path.size()).c_str());
                rho_stat_t *rst = rho_stat(fpath);
                return rst != NULL;
            }

        }
        else if (S_ISREG(st.st_mode))
        {
            //RHO_LOG("need_emulate: (4)");
            rho_stat_t *rst = rho_stat(fpath);
            //RHO_LOG("need_emulate: (5)");
            if (rst && rst->mtime > st.st_mtime)
            {
                //RHO_LOG("need_emulate: %s, st.st_mtime: %lu", fpath.c_str(), st.st_mtime);
                //RHO_LOG("need_emulate: %s, rst->mtime: %lu", fpath.c_str(), rst ? rst->mtime : -1);
                //RHO_LOG("need_emulate: file %s in Android package is newer than one located on FS, unlink FS one", fpath.c_str());
                real_unlink(fpath.c_str());
                return true;
            }
        }
    }

    //RHO_LOG("need_emulate: return false");
    return false;
}
コード例 #17
0
ファイル: vfs_python.c プロジェクト: jeagle/win_fuse_smb
static bool python_is_offline(struct vfs_handle_struct *handle, const struct smb_filename *fname, SMB_STRUCT_STAT *sbuf)
{
	struct pyfuncs *pf = handle->data;
	PyObject *pArgs, *pRet, *pValue;
	char full_path_buf[PY_MAXPATH];
	const char *full_path;
	int i;

	if (!pf->pFuncIsOffline) {
		errno = ENOSYS;
		return 0;
	}

	PY_TUPLE_NEW(1);
	full_path = make_full_path(handle, fname->base_name, (char *) &full_path_buf);
	PY_ADD_TO_TUPLE(full_path, PyString_FromString, 0);
	PY_CALL_WITH_ARGS(IsOffline);

	i = PyInt_AsLong(pRet);

	return (i != 0);
}
コード例 #18
0
ファイル: fileapi.cpp プロジェクト: melvinsembrano/rhodes
static bool need_emulate(std::string const &path)
{
    if (rho_fs_mode != RHO_FS_TRANSPARRENT) return false;

    std::string fpath = make_full_path(path);
    std::string const &root_path = rho_root_path();
    if (::strncmp(fpath.c_str(), root_path.c_str(), root_path.size()) == 0)
    {
        struct stat st;
        if (real_stat(fpath.c_str(), &st) == -1)
        {
            if (errno == ENOENT)
            {
                rho_stat_t *rst = rho_stat(fpath);
                return rst != NULL;
            }

        }
    }

    return false;
}
コード例 #19
0
ファイル: vfs_python.c プロジェクト: jeagle/win_fuse_smb
static int python_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
{
	struct pyfuncs *pf = handle->data;
	PyObject *pArgs, *pRet, *pValue;
	char full_path_buf[PY_MAXPATH];
	const char *full_path;
	int i;

	if (!pf->pFuncChmod) {
		errno = ENOSYS;
		return -1;
	}

	PY_TUPLE_NEW(2);
	full_path = make_full_path(handle, path, (char *) &full_path_buf);
	PY_ADD_TO_TUPLE(full_path, PyString_FromString, 0);
	PY_ADD_TO_TUPLE(mode, PyInt_FromLong, 1);
	PY_CALL_WITH_ARGS(Chmod);

	i = PyInt_AsLong(pRet);

	Py_DECREF(pRet);
	return i;
}
コード例 #20
0
ファイル: fallback.c プロジェクト: Acidburn0zzz/shim
EFI_STATUS
try_boot_csv(EFI_FILE_HANDLE fh, CHAR16 *dirname, CHAR16 *filename)
{
	CHAR16 *fullpath = NULL;
	UINT64 pathlen = 0;
	EFI_STATUS rc;

	rc = make_full_path(dirname, filename, &fullpath, &pathlen);
	if (EFI_ERROR(rc))
		return rc;

#ifdef DEBUG_FALLBACK
	Print(L"Found file \"%s\"\n", fullpath);
#endif

	CHAR16 *buffer;
	UINT64 bs;
	rc = read_file(fh, fullpath, &buffer, &bs);
	if (EFI_ERROR(rc)) {
		Print(L"Could not read file \"%s\": %d\n", fullpath, rc);
		FreePool(fullpath);
		return rc;
	}
	FreePool(fullpath);

#ifdef DEBUG_FALLBACK
	Print(L"File looks like:\n%s\n", buffer);
#endif

	CHAR16 *start = buffer;
	/* The file may or may not start with the Unicode byte order marker.
	 * Sadness ensues.  Since UEFI is defined as LE, I'm going to decree
	 * that these files must also be LE.
	 *
	 * IT IS THUS SO.
	 *
	 * But if we find the LE byte order marker, just skip it.
	 */
	if (*start == 0xfeff)
		start++;
	while (*start) {
		while (*start == L'\r' || *start == L'\n')
			start++;
		UINTN l = StrCSpn(start, L"\r\n");
		if (l == 0) {
			if (start[l] == L'\0')
				break;
			start++;
			continue;
		}
		CHAR16 c = start[l];
		start[l] = L'\0';

		populate_stanza(fh, dirname, filename, start);

		start[l] = c;
		start += l;
	}

	FreePool(buffer);
	return EFI_SUCCESS;
}
コード例 #21
0
ファイル: fallback.c プロジェクト: Acidburn0zzz/shim
EFI_STATUS
add_to_boot_list(EFI_FILE_HANDLE fh, CHAR16 *dirname, CHAR16 *filename, CHAR16 *label, CHAR16 *arguments)
{
	CHAR16 *fullpath = NULL;
	UINT64 pathlen = 0;
	EFI_STATUS rc = EFI_SUCCESS;

	rc = make_full_path(dirname, filename, &fullpath, &pathlen);
	if (EFI_ERROR(rc))
		return rc;
	
	EFI_DEVICE_PATH *dph = NULL;
	EFI_DEVICE_PATH *file = NULL;
	EFI_DEVICE_PATH *full_device_path = NULL;
	EFI_DEVICE_PATH *dp = NULL;
	
	dph = DevicePathFromHandle(this_image->DeviceHandle);
	if (!dph) {
		rc = EFI_OUT_OF_RESOURCES;
		goto err;
	}

	file = FileDevicePath(fh, fullpath);
	if (!file) {
		rc = EFI_OUT_OF_RESOURCES;
		goto err;
	}

	full_device_path = AppendDevicePath(dph, file);
	if (!full_device_path) {
		rc = EFI_OUT_OF_RESOURCES;
		goto err;
	}

	rc = FindSubDevicePath(full_device_path,
				MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP, &dp);
	if (EFI_ERROR(rc)) {
		if (rc == EFI_NOT_FOUND) {
			dp = full_device_path;
		} else {
			rc = EFI_OUT_OF_RESOURCES;
			goto err;
		}
	}

#ifdef DEBUG_FALLBACK
	{
	UINTN s = DevicePathSize(dp);
	UINTN i;
	UINT8 *dpv = (void *)dp;
	for (i = 0; i < s; i++) {
		if (i > 0 && i % 16 == 0)
			Print(L"\n");
		Print(L"%02x ", dpv[i]);
	}
	Print(L"\n");

	CHAR16 *dps = DevicePathToStr(dp);
	Print(L"device path: \"%s\"\n", dps);
	}
#endif

	UINT16 option;
	rc = find_boot_option(dp, full_device_path, fullpath, label, arguments, &option);
	if (EFI_ERROR(rc)) {
		add_boot_option(dp, full_device_path, fullpath, label, arguments);
	} else if (option != 0) {
		CHAR16 *newbootorder;
		newbootorder = AllocateZeroPool(sizeof (CHAR16) * nbootorder);
		if (!newbootorder)
			return EFI_OUT_OF_RESOURCES;

		newbootorder[0] = bootorder[option];
		CopyMem(newbootorder + 1, bootorder, sizeof (CHAR16) * option);
		CopyMem(newbootorder + option + 1, bootorder + option + 1,
			sizeof (CHAR16) * (nbootorder - option - 1));
		FreePool(bootorder);
		bootorder = newbootorder;
	}

err:
	if (file)
		FreePool(file);
	if (full_device_path)
		FreePool(full_device_path);
	if (dp)
		FreePool(dp);
	if (fullpath)
		FreePool(fullpath);
	return rc;
}
コード例 #22
0
ファイル: fileapi.cpp プロジェクト: croteb/rhodes
RHO_GLOBAL int open(const char *path, int oflag, ...)
{
    std::string fpath;
    if (path)
        fpath = path;

    if (fpath.empty())
    {
        RHO_LOG("open: path is empty");
        errno = EFAULT;
        return -1;
    }

    RHO_LOG("open: %s...", path);
    fpath = make_full_path(fpath);
    //RHO_LOG("open: %s: fpath: %s", path, fpath.c_str());

    bool java_way = need_java_way(fpath);
    if (java_way && has_pending_exception())
    {
        errno = EFAULT;
        return -1;
    }
    if (java_way && (oflag & (O_WRONLY | O_RDWR)))
    {
        //RHO_LOG("open: %s: copy from Android package", path);
        JNIEnv *env = jnienv();
        jstring relPathObj = rho_cast<jstring>(env, make_rel_path(fpath).c_str());
        env->CallStaticBooleanMethod(clsFileApi, midCopy, relPathObj);
        env->DeleteLocalRef(relPathObj);
        if (has_pending_exception())
        {
            errno = EFAULT;
            return -1;
        }

        java_way = false;
    }
    
    int fd;
    if (java_way)
    {
        JNIEnv *env = jnienv();
        jstring relPathObj = rho_cast<jstring>(env, make_rel_path(fpath).c_str());
        jobject is = env->CallStaticObjectMethod(clsFileApi, midOpen, relPathObj);
        env->DeleteLocalRef(relPathObj);

        if (is != NULL)
        {
            scoped_lock_t guard(rho_fd_mtx);
            if (!rho_fd_free.empty())
            {
                fd = rho_fd_free[0];
                rho_fd_free.erase(rho_fd_free.begin());
            }
            else
                fd = rho_fd_counter++;
            rho_fd_data_t d;
            d.is = env->NewGlobalRef(is);
            d.fpath = fpath;
            d.pos = 0;
            rho_fd_map[fd] = d;
        }
        else
        {
            errno = EFAULT;
            fd = -1;
        }

        env->DeleteLocalRef(is);
    }
    else
    {
        mode_t mode = 0;
        if (oflag & O_CREAT)
        {
            va_list vl;
            va_start(vl, oflag);
            mode = va_arg(vl, int);
            va_end(vl);
        }
        fd = real_open(path, oflag, mode);
    }
コード例 #23
0
ファイル: fileapi.cpp プロジェクト: croteb/rhodes
static bool need_java_way(const char *path)
{
    return path ? need_java_way(make_full_path(path)) : false;
}
コード例 #24
0
ファイル: fileapi.cpp プロジェクト: croteb/rhodes
RHO_GLOBAL jstring JNICALL Java_com_rhomobile_rhodes_file_RhoFileApi_makeRelativePath
  (JNIEnv *env, jclass, jstring pathObj)
{
    std::string path = rho_cast<std::string>(env, pathObj);
    return rho_cast<jstring>(env, make_rel_path(make_full_path(path)));
}
コード例 #25
0
ファイル: fileapi.cpp プロジェクト: croteb/rhodes
static std::string make_full_path(std::string const &path)
{
    return make_full_path(path.c_str());
}
コード例 #26
0
ファイル: fileapi.cpp プロジェクト: Aerodynamic/rhodes
RHO_GLOBAL int open(const char *path, int oflag, ...)
{
    std::string fpath;
    if (path)
        fpath = path;

    if (fpath.empty())
    {
        RHO_LOG("open: path is empty");
        errno = EFAULT;
        return -1;
    }

    RHO_LOG("open: %s...", path);
    fpath = make_full_path(fpath);
    RHO_LOG("open: %s: fpath: %s", path, fpath.c_str());

    bool emulate = need_emulate(fpath);
    RHO_LOG("open: %s: emulate: %d", path, (int)emulate);
    if (emulate && has_pending_exception())
    {
        RHO_LOG("open: %s: has_pending_exception, return -1", path);
        errno = EFAULT;
        return -1;
    }
    if (emulate && (oflag & (O_WRONLY | O_RDWR)))
    {
        RHO_LOG("open: %s: copy from Android package", path);
        JNIEnv *env = jnienv();
        jhstring relPathObj = rho_cast<jhstring>(env, make_rel_path(fpath).c_str());
        env->CallStaticBooleanMethod(clsFileApi, midCopy, relPathObj.get());
        if (has_pending_exception())
        {
            RHO_LOG("open: %s: has_pending_exception, return -1", path);
            errno = EFAULT;
            return -1;
        }

        emulate = false;
    }
    RHO_LOG("open: %s: emulate: %d", path, (int)emulate);

    int fd;
    if (emulate)
    {
        RHO_LOG("open: %s: emulate", path);
        JNIEnv *env = jnienv();
        jhstring relPathObj = rho_cast<jhstring>(env, make_rel_path(fpath).c_str());
        jhobject is = jhobject(env->CallStaticObjectMethod(clsFileApi, midOpen, relPathObj.get()));

        if (!is)
        {
            errno = EFAULT;
            fd = -1;
        }
        else
        {
            scoped_lock_t guard(rho_file_mtx);
            if (!rho_fd_free.empty())
            {
                fd = rho_fd_free[0];
                rho_fd_free.erase(rho_fd_free.begin());
            }
            else
                fd = rho_fd_counter++;
            rho_fd_data_t d;
            d.type = rho_type_file;
            d.is = env->NewGlobalRef(is.get());
            d.dirp = NULL;
            d.fpath = fpath;
            d.pos = 0;
            rho_fd_map[fd] = d;
        }
    }
    else
    {
        RHO_LOG("open: %s: native", path);
        mode_t mode = 0;
        if (oflag & O_CREAT)
        {
            va_list vl;
            va_start(vl, oflag);
            mode = va_arg(vl, int);
            va_end(vl);
        }
        fd = real_open(path, oflag, mode);
    }
コード例 #27
0
ファイル: main.c プロジェクト: pwrtelegram/tg
void parse_config (void) {
  //config_filename = make_full_path (config_filename);
  
  config_t conf;
  config_init (&conf);
  if (config_read_file (&conf, config_filename) != CONFIG_TRUE) {
    fprintf (stderr, "Can not read config '%s': error '%s' on the line %d\n", config_filename, config_error_text (&conf), config_error_line (&conf));
    exit (2);
  }

  if (!prefix) {
    config_lookup_string (&conf, "default_profile", (void *)&prefix);
  }

  static char buf[1000];
  int l = 0;
  if (prefix) {
    l = strlen (prefix);
    memcpy (buf, prefix, l);
    buf[l ++] = '.';
  }
  
  int test_mode = 0;
  strcpy (buf + l, "test");
  config_lookup_bool (&conf, buf, &test_mode);
  if (test_mode) {
    tgl_set_test_mode (TLS);
  }
  
  strcpy (buf + l, "log_level");
  long long t = log_level;
  config_lookup_int (&conf, buf, (void *)&t);
  log_level = t;
  
  if (!msg_num_mode) {
    strcpy (buf + l, "msg_num");
    config_lookup_bool (&conf, buf, &msg_num_mode);
  }

  parse_config_val (&conf, &config_directory, "config_directory", CONFIG_DIRECTORY, 0);
  config_directory = make_full_path (config_directory);

  parse_config_val (&conf, &auth_file_name, "auth_file", AUTH_KEY_FILE, config_directory);
  parse_config_val (&conf, &downloads_directory, "downloads", DOWNLOADS_DIRECTORY, config_directory);
  
  if (!lua_file) {
    parse_config_val (&conf, &lua_file, "lua_script", 0, config_directory);
  }
  
  if (!python_file) {
    parse_config_val (&conf, &python_file, "python_script", 0, config_directory);
  }
 
  #if 0
  strcpy (buf + l, "binlog_enabled");
  config_lookup_bool (&conf, buf, &binlog_enabled);
  #else
  binlog_enabled = 0;
  #endif
  
  int pfs_enabled = 0;
  strcpy (buf + l, "pfs_enabled");
  config_lookup_bool (&conf, buf, &pfs_enabled);
  if (pfs_enabled) {
    tgl_enable_pfs (TLS);
  }

  if (binlog_enabled) {
    parse_config_val (&conf, &binlog_file_name, "binlog", BINLOG_FILE, config_directory);
    tgl_set_binlog_mode (TLS, 1);
    tgl_set_binlog_path (TLS, binlog_file_name);
  } else {
    tgl_set_binlog_mode (TLS, 0);
    parse_config_val (&conf, &state_file_name, "state_file", STATE_FILE, config_directory);
    parse_config_val (&conf, &secret_chat_file_name, "secret", SECRET_CHAT_FILE, config_directory);
    //tgl_set_auth_file_path (auth_file_name);
  }
  tgl_set_download_directory (TLS, downloads_directory);
  
  if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) {
    if (!disable_output) {
      printf ("[%s] created\n", config_directory);
    }
  }
  if (!mkdir (downloads_directory, CONFIG_DIRECTORY_MODE)) {
    if (!disable_output) {
      printf ("[%s] created\n", downloads_directory);
    }
  }
  tfree_str (config_directory);
  config_directory = NULL;
  config_destroy (&conf);
}
コード例 #28
0
ファイル: fileapi.cpp プロジェクト: Aerodynamic/rhodes
RHO_GLOBAL jstring JNICALL Java_com_rhomobile_rhodes_file_RhoFileApi_absolutePath
  (JNIEnv *env, jclass, jstring pathObj)
{
    std::string path = rho_cast<std::string>(env, pathObj);
    return rho_cast<jhstring>(env, make_full_path(path)).release();
}
コード例 #29
0
ファイル: fallback.c プロジェクト: samBeanham/shim
EFI_STATUS
add_to_boot_list(EFI_FILE_HANDLE fh, CHAR16 *dirname, CHAR16 *filename, CHAR16 *label, CHAR16 *arguments)
{
	CHAR16 *fullpath = NULL;
	UINT64 pathlen = 0;
	EFI_STATUS rc = EFI_SUCCESS;

	rc = make_full_path(dirname, filename, &fullpath, &pathlen);
	if (EFI_ERROR(rc))
		return rc;
	
	EFI_DEVICE_PATH *dph = NULL, *dpf = NULL, *dp = NULL;
	
	dph = DevicePathFromHandle(this_image->DeviceHandle);
	if (!dph) {
		rc = EFI_OUT_OF_RESOURCES;
		goto err;
	}

	dpf = FileDevicePath(fh, fullpath);
	if (!dpf) {
		rc = EFI_OUT_OF_RESOURCES;
		goto err;
	}

	dp = AppendDevicePath(dph, dpf);
	if (!dp) {
		rc = EFI_OUT_OF_RESOURCES;
		goto err;
	}

#ifdef DEBUG_FALLBACK
	UINTN s = DevicePathSize(dp);
	int i;
	UINT8 *dpv = (void *)dp;
	for (i = 0; i < s; i++) {
		if (i > 0 && i % 16 == 0)
			Print(L"\n");
		Print(L"%02x ", dpv[i]);
	}
	Print(L"\n");

	CHAR16 *dps = DevicePathToStr(dp);
	Print(L"device path: \"%s\"\n", dps);
#endif
	if (!first_new_option) {
		CHAR16 *dps = DevicePathToStr(dp);
		Print(L"device path: \"%s\"\n", dps);
		first_new_option = DuplicateDevicePath(dp);
		first_new_option_args = arguments;
		first_new_option_size = StrLen(arguments) * sizeof (CHAR16);
	}

	add_boot_option(dp, fullpath, label, arguments);

err:
	if (dpf)
		FreePool(dpf);
	if (dp)
		FreePool(dp);
	if (fullpath)
		FreePool(fullpath);
	return rc;
}
コード例 #30
0
void send_file(per_request *reqInfo, struct stat *fi, char allow_options) 
{
    FILE *f;
#ifdef BLACKOUT_CODE
    int isblack = FALSE;
#endif /* BLACKOUT_CODE */    

    if ((reqInfo->method != M_GET) && (reqInfo->method != M_HEAD)) {
	sprintf(error_msg,"%s to non-script",methods[reqInfo->method]);
	die(reqInfo,SC_NOT_IMPLEMENTED,error_msg);
    }
    set_content_type(reqInfo,reqInfo->filename);

    if((allow_options & OPT_INCLUDES) && (!reqInfo->outh_content_encoding[0])) {
#ifdef XBITHACK
        if((fi->st_mode & S_IXUSR) ||
           (!strcmp(reqInfo->outh_content_type,INCLUDES_MAGIC_TYPE))) {
#else
	if(!strcmp(reqInfo->outh_content_type,INCLUDES_MAGIC_TYPE)) {
#endif /* XBITHACK */
	    reqInfo->bytes_sent = 0;
	    send_parsed_file(reqInfo, allow_options & OPT_INCNOEXEC);
	    log_transaction(reqInfo);
	    return;
	}
    }
    if (reqInfo->path_info[0]) {
	strcat(reqInfo->filename,reqInfo->path_info);
	strcat(reqInfo->url,reqInfo->path_info);
	sprintf(error_msg,"No file matching URL: %s",reqInfo->url);
	log_reason(reqInfo, error_msg, reqInfo->filename);
	die(reqInfo,SC_NOT_FOUND,reqInfo->url);
    }
	
    if(!(f=FOpen(reqInfo->filename,"r"))) {
      if (errno == EACCES) {
	log_reason(reqInfo,"(1) file permissions deny server access",
		   reqInfo->filename);
	/* we've already established that it exists */
	die(reqInfo,SC_FORBIDDEN,reqInfo->url); 
      } else {
	/* We know an error occured, of an unexpected variety. 
	 * This could be due to no more file descriptors.  We have this
	 * child exit after this stage so that errors of state are 
	 * swept under the carpet.
	 */
	standalone = 0;
	sprintf(error_msg,"File Open error, errno=%d",errno);
	log_reason(reqInfo,error_msg,reqInfo->filename);
	die(reqInfo,SC_SERVER_ERROR,error_msg);
      }
    }
    reqInfo->bytes_sent = 0;

#ifdef BLACKOUT_CODE
    if (!strcmp(reqInfo->outh_content_type,BLACKOUT_MAGIC_TYPE)) {
      isblack = TRUE;
      strcpy(reqInfo->outh_content_type,"text/html");
    }
#endif /* BLACKOUT_CODE */

    if(reqInfo->http_version != P_HTTP_0_9) {
      /* No length dependent headers since black is parsed */
#ifdef BLACKOUT_CODE
      if (isblack == FALSE) { 
#endif /* BLACKOUT_CODE */
#ifdef CONTENT_MD5
	reqInfo->outh_content_md5 = (unsigned char *)md5digest(f);
#endif /* CONTENT_MD5 */
	set_content_length(reqInfo,fi->st_size);
	if (set_last_modified(reqInfo,fi->st_mtime)) {
	    FClose(f);
	    return;
	}
      }
      if (reqInfo->http_version != P_HTTP_0_9) {
           send_http_header(reqInfo);
      }
#ifdef BLACKOUT_CODE
    }
#endif /* BLACKOUT_CODE */

    if(reqInfo->method != M_HEAD) {
#ifdef BLACKOUT_CODE
      if (isblack == TRUE)
	send_fp_black(reqInfo,f,NULL);
       else
#endif /* BLACKOUT_CODE */
	send_fp(reqInfo,f,NULL);
    }
    log_transaction(reqInfo);
    FClose(f);
}


void send_dir(per_request *reqInfo,struct stat *finfo, char allow_options) {
  char *name_ptr, *end_ptr;
  char *ifile, *temp_name;

  ifile = newString(HUGE_STRING_LEN,STR_TMP);
  temp_name = newString(HUGE_STRING_LEN,STR_TMP);

/* Path Alias (pa) array should now have the trailing slash */
  /*  if (pa[0] != '/') { */
  if ((reqInfo->filename[strlen(reqInfo->filename) - 1] != '/') && 
      (reqInfo->path_info[0] != '/')) {
    strcpy_dir(ifile,reqInfo->url);
    construct_url(temp_name,reqInfo->hostInfo,ifile);
    escape_url(temp_name);
    die(reqInfo,SC_REDIRECT_PERM,temp_name);
  }

  /* Don't allow PATH_INFO to directory indexes as a compromise for 
     error messages for files which don't exist */

  if ((reqInfo->path_info[0] != '\0') || (strlen(reqInfo->path_info) > 1)) {
        strcat(reqInfo->filename,reqInfo->path_info);
        strcat(reqInfo->url,reqInfo->path_info);
        sprintf(error_msg,"No file matching URL: %s",reqInfo->url);
        log_reason(reqInfo, error_msg, reqInfo->filename);
	freeString(temp_name);
	freeString(ifile);
        die(reqInfo,SC_NOT_FOUND,reqInfo->url);
  }
    
  strncpy(temp_name, reqInfo->hostInfo->index_names, HUGE_STRING_LEN-1);
  end_ptr = name_ptr = temp_name;

  while (*name_ptr) {
    
    while (*name_ptr && isspace (*name_ptr)) ++name_ptr;
    end_ptr = name_ptr;
    if (strchr(end_ptr, ' ') ) {
      end_ptr = strchr(name_ptr, ' ');
      *end_ptr = '\0';
      end_ptr++;
    } else
      end_ptr += strlen(end_ptr);
    make_full_path(reqInfo->filename,name_ptr,ifile);
    if(stat(ifile,finfo) == -1) {
      if(! *end_ptr && (allow_options & OPT_INDEXES)) {
        if (reqInfo->path_info[0]) {
          strcat(reqInfo->filename,reqInfo->path_info);
	  strcat(reqInfo->url,reqInfo->path_info);
	  log_reason(reqInfo,"file does not exist",reqInfo->filename);
	  freeString(ifile);
	  freeString(temp_name);
	  die(reqInfo,SC_NOT_FOUND,reqInfo->url);
	}
	if ((reqInfo->method != M_GET) && (reqInfo->method != M_HEAD)) {
	  sprintf(error_msg,"%s to non-script",methods[reqInfo->method]);
	  freeString(ifile);
	  freeString(temp_name);
	  die(reqInfo,SC_NOT_IMPLEMENTED,error_msg);
	}	
	index_directory(reqInfo);
	freeString(ifile);
	freeString(temp_name);
	return;
      } else if (! *end_ptr) {
	log_reason(reqInfo,"(2) file permissions deny server access",
		   reqInfo->filename);
	freeString(ifile);
	freeString(temp_name);
	die(reqInfo,SC_FORBIDDEN,reqInfo->url);
      }
    } else {
      strcpy(reqInfo->filename,ifile);
      probe_content_type(reqInfo,reqInfo->filename);
      if(!strcmp(reqInfo->outh_content_type,CGI_MAGIC_TYPE))
	send_cgi(reqInfo,finfo,allow_options);
      else
	send_file(reqInfo,finfo,allow_options);
      freeString(ifile);
      freeString(temp_name);
      return;
    }
    name_ptr = end_ptr;
  }	 
}