MCPcopy Create free account
hub / github.com/F-Stack/f-stack / _secure_path

Function _secure_path

tools/libutil/_secure_path.c:45–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43 */
44
45int
46_secure_path(const char *path, uid_t uid, gid_t gid)
47{
48 int r = -1;
49 struct stat sb;
50 const char *msg = NULL;
51
52 if (lstat(path, &sb) < 0) {
53 if (errno == ENOENT) /* special case */
54 r = -2; /* if it is just missing, skip the log entry */
55 else
56 msg = "%s: cannot stat %s: %m";
57 }
58 else if (!S_ISREG(sb.st_mode))
59 msg = "%s: %s is not a regular file";
60 else if (sb.st_mode & S_IWOTH)
61 msg = "%s: %s is world writable";
62 else if ((int)uid != -1 && sb.st_uid != uid && sb.st_uid != 0) {
63 if (uid == 0)
64 msg = "%s: %s is not owned by root";
65 else
66 msg = "%s: %s is not owned by uid %d";
67 } else if ((int)gid != -1 && sb.st_gid != gid && (sb.st_mode & S_IWGRP))
68 msg = "%s: %s is group writeable by non-authorised groups";
69 else
70 r = 0;
71 if (msg != NULL)
72 syslog(LOG_ERR, msg, "_secure_path", path, uid);
73 return r;
74}

Callers 1

login_getclassbynameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected