suricata
util-path.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SCFstatFn(fd, statbuf)   fstat((fd), (statbuf))
 
#define SCStatFn(pathname, statbuf)   stat((pathname), (statbuf))
 
#define PATH_SEPARATOR_SIZE   1
 
#define SCMkDir(a, b)   mkdir(a, b)
 

Typedefs

typedef struct stat SCStat
 

Functions

int PathIsAbsolute (const char *)
 Check if a path is absolute. More...
 
int PathIsRelative (const char *)
 Check if a path is relative. More...
 
int PathMerge (char *out_buf, size_t buf_size, const char *const dir, const char *const fname)
 
char * PathMergeAlloc (const char *const dir, const char *const fname)
 
int PathJoin (char *out_buf, size_t buf_len, const char *const dir, const char *const fname)
 Wrapper to join a directory and filename and resolve using realpath _fullpath is used for WIN32. More...
 
int SCDefaultMkDir (const char *path)
 Wrapper around SCMkDir with default mode arguments. More...
 
int SCCreateDirectoryTree (const char *path, const bool final)
 Recursively create a directory. More...
 
bool SCPathExists (const char *path)
 Check if a path exists. More...
 
bool SCIsRegularDirectory (const struct dirent *const dir_entry)
 OS independent wrapper for directory check. More...
 
bool SCIsRegularFile (const struct dirent *const dir_entry)
 OS independent to check for regular file. More...
 
char * SCRealPath (const char *path, char *resolved_path)
 OS independent wrapper for realpath. More...
 
const char * SCBasename (const char *path)
 
bool SCPathContainsTraversal (const char *path)
 Check for directory traversal. More...
 

Detailed Description

Author
Victor Julien victo.nosp@m.r@in.nosp@m.linia.nosp@m.c.ne.nosp@m.t

Definition in file util-path.h.

Macro Definition Documentation

◆ PATH_SEPARATOR_SIZE

#define PATH_SEPARATOR_SIZE   1

Definition at line 42 of file util-path.h.

◆ SCFstatFn

#define SCFstatFn (   fd,
  statbuf 
)    fstat((fd), (statbuf))

Definition at line 35 of file util-path.h.

◆ SCMkDir

#define SCMkDir (   a,
 
)    mkdir(a, b)

Definition at line 46 of file util-path.h.

◆ SCStatFn

#define SCStatFn (   pathname,
  statbuf 
)    stat((pathname), (statbuf))

Definition at line 36 of file util-path.h.

Typedef Documentation

◆ SCStat

typedef struct stat SCStat

Definition at line 1 of file util-path.h.

Function Documentation

◆ PathIsAbsolute()

int PathIsAbsolute ( const char *  path)

Check if a path is absolute.

Parameters
pathstring with the path
Return values
1absolute
0not absolute

Definition at line 44 of file util-path.c.

Referenced by ConfYamlHandleInclude(), PathIsRelative(), and SCConfLogOpenGeneric().

Here is the caller graph for this function:

◆ PathIsRelative()

int PathIsRelative ( const char *  path)

Check if a path is relative.

Parameters
pathstring with the path
Return values
1relative
0not relative

Definition at line 69 of file util-path.c.

References PathIsAbsolute().

Referenced by DetectLoadCompleteSigPath().

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

◆ PathJoin()

int PathJoin ( char *  out_buf,
size_t  buf_size,
const char *const  dir,
const char *const  fname 
)

Wrapper to join a directory and filename and resolve using realpath _fullpath is used for WIN32.

Parameters
out_bufoutput buffer. Up to PATH_MAX will be written. Unchanged on exit failure.
buf_sizelength of output buffer, must be PATH_MAX
dirthe directory
fnamethe filename
Return values
0on success
-1on failure

Definition at line 132 of file util-path.c.

References PathMerge(), SCEnter, SCLogError, SCRealPath(), and strlcpy().

Here is the call graph for this function:

◆ PathMerge()

int PathMerge ( char *  out_buf,
size_t  buf_size,
const char *const  dir,
const char *const  fname 
)

Definition at line 74 of file util-path.c.

References strlcat(), and strlcpy().

Referenced by PathJoin(), and PathMergeAlloc().

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

◆ PathMergeAlloc()

char* PathMergeAlloc ( const char *const  dir,
const char *const  fname 
)

Definition at line 107 of file util-path.c.

References PathMerge(), and SCStrdup.

Referenced by DetectLoadCompleteSigPath().

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

◆ SCBasename()

const char* SCBasename ( const char *  path)

Definition at line 285 of file util-path.c.

References DIRECTORY_SEPARATOR.

◆ SCCreateDirectoryTree()

int SCCreateDirectoryTree ( const char *  path,
const bool  final 
)

Recursively create a directory.

Parameters
pathPath to create
finaltrue will create the final path component, false will not
Return values
0on success
-1on error

Definition at line 173 of file util-path.c.

References len, SCDefaultMkDir(), and strlcpy().

Here is the call graph for this function:

◆ SCDefaultMkDir()

int SCDefaultMkDir ( const char *  path)

Wrapper around SCMkDir with default mode arguments.

Definition at line 159 of file util-path.c.

References SCMkDir.

Referenced by SCCreateDirectoryTree().

Here is the caller graph for this function:

◆ SCIsRegularDirectory()

bool SCIsRegularDirectory ( const struct dirent *const  dir_entry)

OS independent wrapper for directory check.

Parameters
dir_entryobject to check
Return values
Trueif the object is a regular directory, otherwise false. This directory and parent directory will return false.

Definition at line 236 of file util-path.c.

◆ SCIsRegularFile()

bool SCIsRegularFile ( const struct dirent *const  dir_entry)

OS independent to check for regular file.

Parameters
dir_entryobject to check
Return values
Trueif the object is a regular file. Otherwise false.

Definition at line 254 of file util-path.c.

◆ SCPathContainsTraversal()

bool SCPathContainsTraversal ( const char *  path)

Check for directory traversal.

Parameters
pathThe path string to check for traversal
Return values
trueif directory traversal is found, otherwise false

Definition at line 307 of file util-path.c.

◆ SCPathExists()

bool SCPathExists ( const char *  path)

Check if a path exists.

Parameters
Pathto check for existence
Return values
trueif path exists
falseif path does not exist

Definition at line 219 of file util-path.c.

◆ SCRealPath()

char* SCRealPath ( const char *  path,
char *  resolved_path 
)

OS independent wrapper for realpath.

Parameters
paththe path to resolve
resolved_paththe resolved path; if null, a buffer will be allocated
Return values
theresolved_path; or a pointer to a new resolved_path buffer

Definition at line 270 of file util-path.c.

Referenced by PathJoin().

Here is the caller graph for this function: