dpkg 1.21.11
Functions
Collaboration diagram for Path handling:

Functions

size_t path_trim_slash_slashdot (char *path)
 Trim ‘/’ and ‘/. More...
 
const char * path_skip_slash_dotslash (const char *path)
 Skip ‘/’ and ‘. More...
 
const char * path_basename (const char *path)
 Return the last component of a pathname. More...
 
char * path_quote_filename (char *dst, const char *src, size_t size)
 Escape characters in a pathname for safe locale printing. More...
 
char * path_make_temp_template (const char *suffix)
 Create a template for a temporary pathname. More...
 
int secure_unlink_statted (const char *pathname, const struct stat *stab)
 
int secure_unlink (const char *pathname)
 Securely unlink a pathname. More...
 
int secure_remove (const char *pathname)
 Securely remove a pathname. More...
 
void path_remove_tree (const char *pathname)
 Remove a pathname and anything below it. More...
 

Detailed Description

Function Documentation

◆ path_basename()

const char * path_basename ( const char *  path)

Return the last component of a pathname.

Parameters
pathThe pathname to get the base name from.
Returns
A pointer to the last component inside pathname.

Referenced by command_init().

Here is the caller graph for this function:

◆ path_make_temp_template()

char * path_make_temp_template ( const char *  suffix)

Create a template for a temporary pathname.

Parameters
suffixThe suffix to use for the template string.
Returns
An allocated string with the created template.

References str_fmt().

Here is the call graph for this function:

◆ path_quote_filename()

char * path_quote_filename ( char *  dst,
const char *  src,
size_t  n 
)

Escape characters in a pathname for safe locale printing.

We need to quote paths so that they do not cause problems when printing them, for example with snprintf(3) which does not work if the format string contains s and an argument has invalid characters for the current locale, it will then return -1.

To simplify things, we just escape all 8 bit characters, instead of just invalid characters.

Parameters
dstThe escaped destination string.
srcThe source string to escape.
nThe size of the destination buffer.
Returns
The destination string.

◆ path_remove_tree()

void path_remove_tree ( const char *  pathname)

Remove a pathname and anything below it.

This function removes pathname and all its contents recursively.

References _, dbg_eachfile, debug(), internerr, ohshite(), path_skip_slash_dotslash(), RM, secure_unlink(), subproc_fork(), and subproc_reap().

Referenced by cu_cidir(), and cu_pathname().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ path_skip_slash_dotslash()

const char * path_skip_slash_dotslash ( const char *  path)

Skip ‘/’ and ‘.

/’ from the beginning of a pathname.

Parameters
pathThe pathname to skip.
Returns
The new beginning of the pathname.

Referenced by dpkg_fsys_get_path(), fsys_hash_find_node(), and path_remove_tree().

Here is the caller graph for this function:

◆ path_trim_slash_slashdot()

size_t path_trim_slash_slashdot ( char *  path)

Trim ‘/’ and ‘/.

’ from the end of a pathname.

The given string will get NUL-terminatd.

Parameters
pathThe pathname to trim.
Returns
The size of the trimmed pathname.

◆ secure_remove()

int secure_remove ( const char *  pathname)

Securely remove a pathname.

This is a secure version of remove(3) using secure_unlink() instead of unlink(2).

Return values
0On success.
-1On failure, just like unlink(2) & rmdir(2).

References dbg_eachfiledetail, debug(), and secure_unlink().

Referenced by cu_installnew().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ secure_unlink()

int secure_unlink ( const char *  pathname)

Securely unlink a pathname.

If the pathname to remove is:

  1. a sticky or set-id file, or
  2. an unknown object (i.e., not a file, link, directory, fifo or socket)

we change its mode so that a malicious user cannot use it, even if it's linked to another file.

References secure_unlink_statted().

Referenced by path_remove_tree(), and secure_remove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ secure_unlink_statted()

int secure_unlink_statted ( const char *  pathname,
const struct stat *  stab 
)

Referenced by secure_unlink().

Here is the caller graph for this function: