403Webshell
Server IP : 172.67.216.182  /  Your IP : 172.68.164.10
Web Server : Apache
System : Linux krdc-ubuntu-s-2vcpu-4gb-amd-blr1-01.localdomain 5.15.0-142-generic #152-Ubuntu SMP Mon May 19 10:54:31 UTC 2025 x86_64
User : www ( 1000)
PHP Version : 7.4.33
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /www/server/mysql/src/client/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /www/server/mysql/src/client/path.cc
/*
   Copyright (c) 2012, 2023, Oracle and/or its affiliates.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2.0,
   as published by the Free Software Foundation.

   This program is also distributed with certain software (including
   but not limited to OpenSSL) that is licensed under separate terms,
   as designated in a particular file or component or in included license
   documentation.  The authors of MySQL hereby grant you an additional
   permission to link the program and your derivative works with the
   separately licensed software that they have included with MySQL.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License, version 2.0, for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
*/
#include "path.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "my_sys.h"
#include "my_global.h"
#include "my_dir.h"

#ifndef _WIN32
#include <pwd.h>
#endif

Path::Path() {}

Path::Path(const std::string &s)
{
  path(s);
}

Path::Path(const Path &p)
{
  m_filename= p.m_filename;
  m_path= p.m_path;
}

bool Path::path_getcwd()
{
  char path[FN_REFLEN];
  if (my_getwd(path, FN_REFLEN-1, MYF(MY_WME)))
     return false;
  m_path.clear();
  m_path.append(path);
  trim();
  return true;
}

void Path::trim()
{
  if (m_path.length() <= 1)
    return;
  std::string::iterator it= m_path.end();
  --it;

  while((*it) == FN_LIBCHAR && m_path.length() > 1)
  {
    m_path.erase(it--);
  }
}

void Path::parent_directory(Path *out)
{
  size_t idx= m_path.rfind(FN_DIRSEP);
  if (idx == std::string::npos)
  {
    out->path("");
  }
  else
    out->path(m_path.substr(0, idx));
}

Path &Path::up()
{
  size_t idx= m_path.rfind(FN_DIRSEP);
  if (idx == std::string::npos)
  {
    m_path.clear();
  }
  else
    m_path.assign(m_path.substr(0, idx));
  return *this;
}

Path &Path::append(const std::string &path)
{
  if (m_path.length() > 1 && path[0] != FN_LIBCHAR)
    m_path.append(FN_DIRSEP);
  m_path.append(path);
  trim();
  return *this;
}

Path &Path::filename_append(const std::string &ext)
{
  m_filename.append(ext);
  trim();
  return *this;
}

void Path::path(const std::string &p)
{
  m_path.clear();
  m_path.append(p);
  trim();
}

void Path::filename(const std::string &f)
{
  m_filename= f;
}

void Path::path(const Path &p)
{
  path(p.m_path);
}

void Path::filename(const Path &p)
{
  path(p.m_filename);
}

bool Path::qpath(const std::string &qp)
{
  size_t idx= qp.rfind(FN_DIRSEP);
  if (idx == std::string::npos)
  {
    m_filename= qp;
    m_path.clear();
  }
  else
  {
    filename(qp.substr(idx + 1, qp.size() - idx));
    path(qp.substr(0, idx));
  }
  if (is_qualified_path())
    return true;
  else
    return false;
}

bool Path::normalize_path()
{
  if (!m_path.length())
    return false;

  char real_path[FN_REFLEN];
  size_t real_path_len;

  real_path_len= cleanup_dirname(real_path,m_path.c_str());
  if (real_path_len > FN_REFLEN)
    return false;

  if (my_realpath(real_path, real_path, MYF(0)))
    return false;

  m_path.clear();
  m_path.append(real_path);
  trim();

  return true;
}

bool Path::is_qualified_path()
{
  return m_filename.length() > 0;
}

bool Path::exists()
{
  if (!is_qualified_path())
  {
    MY_DIR *dir= my_dir(m_path.c_str(), MY_WANT_STAT|MY_DONT_SORT);
    if (dir == 0)
      return false;
    my_dirend(dir);
    return true;
  }
  else
  {
    MY_STAT s;
    std::string qpath(m_path);
    qpath.append(FN_DIRSEP).append(m_filename);
    if (my_stat(qpath.c_str(), &s, MYF(0)) == NULL)
      return false;
    if (!MY_S_ISREG(s.st_mode))
      return false;
    return true;
  }
}

const std::string Path::to_str()
{
  std::string qpath(m_path);
  if (m_filename.length() != 0)
  {
    qpath.append(FN_DIRSEP);
    qpath.append(m_filename);
  }
  return qpath;
}

bool Path::empty()
{
  if (!exists())
    return true;
  MY_DIR *dir;
  bool ret= false;
  if (!(dir= my_dir(m_path.c_str(), MY_WANT_STAT|MY_DONT_SORT)))
    ret= false;
  else
  {
    if (dir->number_off_files == 2)
     ret= true;
  }
  my_dirend(dir);
  return ret;
}

#ifndef _WIN32
void Path::get_homedir()
{
  struct passwd *pwd;
  pwd= getpwuid(geteuid());
  if (pwd == NULL)
    return;
  if (pwd->pw_dir != 0)
    path(pwd->pw_dir);
  else
    path("");
}
#endif

std::ostream &operator<<(std::ostream &op, const Path &p)
{
  std::string qpath(p.m_path);
  if (p.m_filename.length() != 0)
  {
    qpath.append(FN_DIRSEP);
    qpath.append(p.m_filename);
  }
  return op << qpath;
}


Youez - 2016 - github.com/yon3zu
LinuXploit