aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/securecoreutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/securecoreutils.c')
-rw-r--r--src/securecoreutils.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/securecoreutils.c b/src/securecoreutils.c
index 75cbdd0..233694e 100644
--- a/src/securecoreutils.c
+++ b/src/securecoreutils.c
@@ -289,7 +289,7 @@ const char * scu_basename(const char * path)
289 289
290 290
291/// checks paths 291/// checks paths
292int scu_pathcheck(const char * path, int isdir) 292int scu_pathcheck(const char * path, int opts)
293{ 293{
294 int c; 294 int c;
295 size_t s; 295 size_t s;
@@ -320,13 +320,19 @@ int scu_pathcheck(const char * path, int isdir)
320 320
321 // verify file is not a symbolic link 321 // verify file is not a symbolic link
322 if ((c = lstat(path, &sb)) == -1) 322 if ((c = lstat(path, &sb)) == -1)
323 return(SCU_ERRNO); 323 {
324 if (isdir == 0) 324 if ( ((opts & SCU_ONOTEXISTS) == 0) || (errno != ENOENT) )
325 if ((sb.st_mode & S_IFMT) != S_IFREG) 325 return(SCU_ERRNO);
326 return(SCU_EFILE); 326 }
327 if (isdir != 0) 327 else
328 if ((sb.st_mode & S_IFMT) != S_IFDIR) 328 {
329 return(SCU_EDIR); 329 if ((opts & SCU_ODIR) == 0)
330 if ((sb.st_mode & S_IFMT) != S_IFREG)
331 return(SCU_EFILE);
332 if ((opts & SCU_ODIR) != 0)
333 if ((sb.st_mode & S_IFMT) != S_IFDIR)
334 return(SCU_EDIR);
335 };
330 336
331 // check path for symlinks 337 // check path for symlinks
332 if ((str = strdup(path)) == NULL) 338 if ((str = strdup(path)) == NULL)
@@ -339,7 +345,9 @@ int scu_pathcheck(const char * path, int isdir)
339 if ((c = lstat(str, &sb)) == -1) 345 if ((c = lstat(str, &sb)) == -1)
340 { 346 {
341 free(str); 347 free(str);
342 return(SCU_ERRNO); 348 if ( ((opts & SCU_ONOTEXISTS) == 0) || (errno != ENOENT) )
349 return(SCU_ERRNO);
350 return(0);
343 }; 351 };
344 if ((sb.st_mode & S_IFMT) == S_IFLNK) 352 if ((sb.st_mode & S_IFMT) == S_IFLNK)
345 { 353 {