summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2017-11-05 22:36:02 +0000
committerngie <ngie@FreeBSD.org>2017-11-05 22:36:02 +0000
commit0bfa1effcec434e85c0746616e83c817dc976c4c (patch)
treecb734e0a4d9b5a75cc631adb82a2a9287e0df60a /lib
parent707851a2199b049b79edaa06dfbe0ee62f02aeb8 (diff)
downloadFreeBSD-src-0bfa1effcec434e85c0746616e83c817dc976c4c.zip
FreeBSD-src-0bfa1effcec434e85c0746616e83c817dc976c4c.tar.gz
MFC r324928,r324929:
r324928: Remove dead stores The return value of various snprintf calls was stored in `len` and not used in many functions. r324929: Clean up trailing whitespace
Diffstat (limited to 'lib')
-rw-r--r--lib/libugidfw/Makefile2
-rw-r--r--lib/libugidfw/ugidfw.c120
2 files changed, 54 insertions, 68 deletions
diff --git a/lib/libugidfw/Makefile b/lib/libugidfw/Makefile
index 2df6a24..2fe6384 100644
--- a/lib/libugidfw/Makefile
+++ b/lib/libugidfw/Makefile
@@ -2,7 +2,7 @@
PACKAGE=lib${LIB}
LIB= ugidfw
-SHLIB_MAJOR= 5
+SHLIB_MAJOR= 5
SRCS= ugidfw.c
INCS= ugidfw.h
diff --git a/lib/libugidfw/ugidfw.c b/lib/libugidfw/ugidfw.c
index e533d1e..7cd9ff0 100644
--- a/lib/libugidfw/ugidfw.c
+++ b/lib/libugidfw/ugidfw.c
@@ -194,7 +194,7 @@ bsde_rule_to_string(struct mac_bsdextended_rule *rule, char *buf, size_t buflen)
cur += len;
}
if (rule->mbr_subject.mbs_flags & MBS_PRISON_DEFINED) {
- len = snprintf(cur, left, "jailid %d ",
+ len = snprintf(cur, left, "jailid %d ",
rule->mbr_subject.mbs_prison);
if (len < 0 || len > left)
goto truncated;
@@ -334,7 +334,7 @@ bsde_rule_to_string(struct mac_bsdextended_rule *rule, char *buf, size_t buflen)
&(mntbuf[i].f_fsid),
sizeof(mntbuf[i].f_fsid)) == 0)
break;
- len = snprintf(cur, left, "filesys %s ",
+ len = snprintf(cur, left, "filesys %s ",
i == numfs ? "???" : mntbuf[i].f_mntonname);
if (len < 0 || len > left)
goto truncated;
@@ -512,7 +512,6 @@ bsde_parse_uidrange(char *spec, uid_t *min, uid_t *max,
uid_t uid1, uid2;
char *spec1, *spec2, *endp;
unsigned long value;
- size_t len;
spec2 = spec;
spec1 = strsep(&spec2, ":");
@@ -523,8 +522,7 @@ bsde_parse_uidrange(char *spec, uid_t *min, uid_t *max,
else {
value = strtoul(spec1, &endp, 10);
if (*endp != '\0') {
- len = snprintf(errstr, buflen,
- "invalid uid: '%s'", spec1);
+ snprintf(errstr, buflen, "invalid uid: '%s'", spec1);
return (-1);
}
uid1 = value;
@@ -541,8 +539,7 @@ bsde_parse_uidrange(char *spec, uid_t *min, uid_t *max,
else {
value = strtoul(spec2, &endp, 10);
if (*endp != '\0') {
- len = snprintf(errstr, buflen,
- "invalid uid: '%s'", spec2);
+ snprintf(errstr, buflen, "invalid uid: '%s'", spec2);
return (-1);
}
uid2 = value;
@@ -561,7 +558,6 @@ bsde_parse_gidrange(char *spec, gid_t *min, gid_t *max,
gid_t gid1, gid2;
char *spec1, *spec2, *endp;
unsigned long value;
- size_t len;
spec2 = spec;
spec1 = strsep(&spec2, ":");
@@ -572,8 +568,7 @@ bsde_parse_gidrange(char *spec, gid_t *min, gid_t *max,
else {
value = strtoul(spec1, &endp, 10);
if (*endp != '\0') {
- len = snprintf(errstr, buflen,
- "invalid gid: '%s'", spec1);
+ snprintf(errstr, buflen, "invalid gid: '%s'", spec1);
return (-1);
}
gid1 = value;
@@ -590,8 +585,7 @@ bsde_parse_gidrange(char *spec, gid_t *min, gid_t *max,
else {
value = strtoul(spec2, &endp, 10);
if (*endp != '\0') {
- len = snprintf(errstr, buflen,
- "invalid gid: '%s'", spec2);
+ snprintf(errstr, buflen, "invalid gid: '%s'", spec2);
return (-1);
}
gid2 = value;
@@ -613,7 +607,6 @@ bsde_parse_subject(int argc, char *argv[],
uid_t uid_min, uid_max;
gid_t gid_min, gid_max;
int jid = 0;
- size_t len;
long value;
current = 0;
@@ -630,11 +623,11 @@ bsde_parse_subject(int argc, char *argv[],
while (current < argc) {
if (strcmp(argv[current], "uid") == 0) {
if (current + 2 > argc) {
- len = snprintf(errstr, buflen, "uid short");
+ snprintf(errstr, buflen, "uid short");
return (-1);
}
if (flags & MBS_UID_DEFINED) {
- len = snprintf(errstr, buflen, "one uid only");
+ snprintf(errstr, buflen, "one uid only");
return (-1);
}
if (bsde_parse_uidrange(argv[current+1],
@@ -648,11 +641,11 @@ bsde_parse_subject(int argc, char *argv[],
current += 2;
} else if (strcmp(argv[current], "gid") == 0) {
if (current + 2 > argc) {
- len = snprintf(errstr, buflen, "gid short");
+ snprintf(errstr, buflen, "gid short");
return (-1);
}
if (flags & MBS_GID_DEFINED) {
- len = snprintf(errstr, buflen, "one gid only");
+ snprintf(errstr, buflen, "one gid only");
return (-1);
}
if (bsde_parse_gidrange(argv[current+1],
@@ -666,17 +659,17 @@ bsde_parse_subject(int argc, char *argv[],
current += 2;
} else if (strcmp(argv[current], "jailid") == 0) {
if (current + 2 > argc) {
- len = snprintf(errstr, buflen, "prison short");
+ snprintf(errstr, buflen, "prison short");
return (-1);
}
if (flags & MBS_PRISON_DEFINED) {
- len = snprintf(errstr, buflen, "one jail only");
+ snprintf(errstr, buflen, "one jail only");
return (-1);
}
value = strtol(argv[current+1], &endp, 10);
if (*endp != '\0') {
- len = snprintf(errstr, buflen,
- "invalid jid: '%s'", argv[current+1]);
+ snprintf(errstr, buflen, "invalid jid: '%s'",
+ argv[current+1]);
return (-1);
}
jid = value;
@@ -688,14 +681,13 @@ bsde_parse_subject(int argc, char *argv[],
current += 2;
} else if (strcmp(argv[current], "!") == 0) {
if (nextnot) {
- len = snprintf(errstr, buflen,
- "double negative");
+ snprintf(errstr, buflen, "double negative");
return (-1);
}
nextnot = 1;
current += 1;
} else {
- len = snprintf(errstr, buflen, "'%s' not expected",
+ snprintf(errstr, buflen, "'%s' not expected",
argv[current]);
return (-1);
}
@@ -723,7 +715,6 @@ bsde_parse_subject(int argc, char *argv[],
static int
bsde_parse_type(char *spec, int *type, size_t buflen, char *errstr)
{
- size_t len;
int i;
*type = 0;
@@ -755,10 +746,10 @@ bsde_parse_type(char *spec, int *type, size_t buflen, char *errstr)
*type |= MBO_ALL_TYPE;
break;
default:
- len = snprintf(errstr, buflen, "Unknown type code: %c",
+ snprintf(errstr, buflen, "Unknown type code: %c",
spec[i]);
return (-1);
- }
+ }
}
return (0);
@@ -767,11 +758,10 @@ bsde_parse_type(char *spec, int *type, size_t buflen, char *errstr)
static int
bsde_parse_fsid(char *spec, struct fsid *fsid, size_t buflen, char *errstr)
{
- size_t len;
struct statfs buf;
if (statfs(spec, &buf) < 0) {
- len = snprintf(errstr, buflen, "Unable to get id for %s: %s",
+ snprintf(errstr, buflen, "Unable to get id for %s: %s",
spec, strerror(errno));
return (-1);
}
@@ -791,7 +781,6 @@ bsde_parse_object(int argc, char *argv[],
uid_t uid_min, uid_max;
gid_t gid_min, gid_max;
struct fsid fsid;
- size_t len;
current = 0;
flags = 0;
@@ -808,11 +797,11 @@ bsde_parse_object(int argc, char *argv[],
while (current < argc) {
if (strcmp(argv[current], "uid") == 0) {
if (current + 2 > argc) {
- len = snprintf(errstr, buflen, "uid short");
+ snprintf(errstr, buflen, "uid short");
return (-1);
}
if (flags & MBO_UID_DEFINED) {
- len = snprintf(errstr, buflen, "one uid only");
+ snprintf(errstr, buflen, "one uid only");
return (-1);
}
if (bsde_parse_uidrange(argv[current+1],
@@ -826,11 +815,11 @@ bsde_parse_object(int argc, char *argv[],
current += 2;
} else if (strcmp(argv[current], "gid") == 0) {
if (current + 2 > argc) {
- len = snprintf(errstr, buflen, "gid short");
+ snprintf(errstr, buflen, "gid short");
return (-1);
}
if (flags & MBO_GID_DEFINED) {
- len = snprintf(errstr, buflen, "one gid only");
+ snprintf(errstr, buflen, "one gid only");
return (-1);
}
if (bsde_parse_gidrange(argv[current+1],
@@ -844,11 +833,11 @@ bsde_parse_object(int argc, char *argv[],
current += 2;
} else if (strcmp(argv[current], "filesys") == 0) {
if (current + 2 > argc) {
- len = snprintf(errstr, buflen, "filesys short");
+ snprintf(errstr, buflen, "filesys short");
return (-1);
}
if (flags & MBO_FSID_DEFINED) {
- len = snprintf(errstr, buflen, "one fsid only");
+ snprintf(errstr, buflen, "one fsid only");
return (-1);
}
if (bsde_parse_fsid(argv[current+1], &fsid,
@@ -890,11 +879,11 @@ bsde_parse_object(int argc, char *argv[],
current += 1;
} else if (strcmp(argv[current], "type") == 0) {
if (current + 2 > argc) {
- len = snprintf(errstr, buflen, "type short");
+ snprintf(errstr, buflen, "type short");
return (-1);
}
if (flags & MBO_TYPE_DEFINED) {
- len = snprintf(errstr, buflen, "one type only");
+ snprintf(errstr, buflen, "one type only");
return (-1);
}
if (bsde_parse_type(argv[current+1], &type,
@@ -908,14 +897,14 @@ bsde_parse_object(int argc, char *argv[],
current += 2;
} else if (strcmp(argv[current], "!") == 0) {
if (nextnot) {
- len = snprintf(errstr, buflen,
+ snprintf(errstr, buflen,
"double negative'");
return (-1);
}
nextnot = 1;
current += 1;
} else {
- len = snprintf(errstr, buflen, "'%s' not expected",
+ snprintf(errstr, buflen, "'%s' not expected",
argv[current]);
return (-1);
}
@@ -946,16 +935,15 @@ int
bsde_parse_mode(int argc, char *argv[], mode_t *mode, size_t buflen,
char *errstr)
{
- size_t len;
int i;
if (argc == 0) {
- len = snprintf(errstr, buflen, "mode expects mode value");
+ snprintf(errstr, buflen, "mode expects mode value");
return (-1);
}
if (argc != 1) {
- len = snprintf(errstr, buflen, "'%s' unexpected", argv[1]);
+ snprintf(errstr, buflen, "'%s' unexpected", argv[1]);
return (-1);
}
@@ -981,10 +969,10 @@ bsde_parse_mode(int argc, char *argv[], mode_t *mode, size_t buflen,
/* ignore */
break;
default:
- len = snprintf(errstr, buflen, "Unknown mode letter: %c",
+ snprintf(errstr, buflen, "Unknown mode letter: %c",
argv[0][i]);
return (-1);
- }
+ }
}
return (0);
@@ -998,17 +986,16 @@ bsde_parse_rule(int argc, char *argv[], struct mac_bsdextended_rule *rule,
int object, object_elements, object_elements_length;
int mode, mode_elements, mode_elements_length;
int error, i;
- size_t len;
bzero(rule, sizeof(*rule));
if (argc < 1) {
- len = snprintf(errstr, buflen, "Rule must begin with subject");
+ snprintf(errstr, buflen, "Rule must begin with subject");
return (-1);
}
if (strcmp(argv[0], "subject") != 0) {
- len = snprintf(errstr, buflen, "Rule must begin with subject");
+ snprintf(errstr, buflen, "Rule must begin with subject");
return (-1);
}
subject = 0;
@@ -1022,7 +1009,7 @@ bsde_parse_rule(int argc, char *argv[], struct mac_bsdextended_rule *rule,
object = i;
if (object == -1) {
- len = snprintf(errstr, buflen, "Rule must contain an object");
+ snprintf(errstr, buflen, "Rule must contain an object");
return (-1);
}
@@ -1033,7 +1020,7 @@ bsde_parse_rule(int argc, char *argv[], struct mac_bsdextended_rule *rule,
mode = i;
if (mode == -1) {
- len = snprintf(errstr, buflen, "Rule must contain mode");
+ snprintf(errstr, buflen, "Rule must contain mode");
return (-1);
}
@@ -1112,12 +1099,12 @@ bsde_check_version(size_t buflen, char *errstr)
len = sizeof(version);
error = sysctlbyname(MIB ".rule_version", &version, &len, NULL, 0);
if (error) {
- len = snprintf(errstr, buflen, "version check failed: %s",
+ snprintf(errstr, buflen, "version check failed: %s",
strerror(errno));
return (-1);
}
if (version != MB_VERSION) {
- len = snprintf(errstr, buflen, "module v%d != library v%d",
+ snprintf(errstr, buflen, "module v%d != library v%d",
version, MB_VERSION);
return (-1);
}
@@ -1134,11 +1121,11 @@ bsde_get_rule_count(size_t buflen, char *errstr)
len = sizeof(rule_count);
error = sysctlbyname(MIB ".rule_count", &rule_count, &len, NULL, 0);
if (error) {
- len = snprintf(errstr, buflen, "%s", strerror(errno));
+ snprintf(errstr, buflen, "%s", strerror(errno));
return (-1);
}
if (len != sizeof(rule_count)) {
- len = snprintf(errstr, buflen, "Data error in %s.rule_count",
+ snprintf(errstr, buflen, "Data error in %s.rule_count",
MIB);
return (-1);
}
@@ -1156,12 +1143,11 @@ bsde_get_rule_slots(size_t buflen, char *errstr)
len = sizeof(rule_slots);
error = sysctlbyname(MIB ".rule_slots", &rule_slots, &len, NULL, 0);
if (error) {
- len = snprintf(errstr, buflen, "%s", strerror(errno));
+ snprintf(errstr, buflen, "%s", strerror(errno));
return (-1);
}
if (len != sizeof(rule_slots)) {
- len = snprintf(errstr, buflen, "Data error in %s.rule_slots",
- MIB);
+ snprintf(errstr, buflen, "Data error in %s.rule_slots", MIB);
return (-1);
}
@@ -1187,7 +1173,7 @@ bsde_get_rule(int rulenum, struct mac_bsdextended_rule *rule, size_t errlen,
len = 10;
error = bsde_get_mib(MIB ".rules", name, &len);
if (error) {
- len = snprintf(errstr, errlen, "%s: %s", MIB ".rules",
+ snprintf(errstr, errlen, "%s: %s", MIB ".rules",
strerror(errno));
return (-1);
}
@@ -1199,11 +1185,11 @@ bsde_get_rule(int rulenum, struct mac_bsdextended_rule *rule, size_t errlen,
if (error == -1 && errno == ENOENT)
return (-2);
if (error) {
- len = snprintf(errstr, errlen, "%s.%d: %s", MIB ".rules",
+ snprintf(errstr, errlen, "%s.%d: %s", MIB ".rules",
rulenum, strerror(errno));
return (-1);
} else if (size != sizeof(*rule)) {
- len = snprintf(errstr, errlen, "Data error in %s.%d: %s",
+ snprintf(errstr, errlen, "Data error in %s.%d: %s",
MIB ".rules", rulenum, strerror(errno));
return (-1);
}
@@ -1225,7 +1211,7 @@ bsde_delete_rule(int rulenum, size_t buflen, char *errstr)
len = 10;
error = bsde_get_mib(MIB ".rules", name, &len);
if (error) {
- len = snprintf(errstr, buflen, "%s: %s", MIB ".rules",
+ snprintf(errstr, buflen, "%s: %s", MIB ".rules",
strerror(errno));
return (-1);
}
@@ -1235,7 +1221,7 @@ bsde_delete_rule(int rulenum, size_t buflen, char *errstr)
error = sysctl(name, len, NULL, NULL, &rule, 0);
if (error) {
- len = snprintf(errstr, buflen, "%s.%d: %s", MIB ".rules",
+ snprintf(errstr, buflen, "%s.%d: %s", MIB ".rules",
rulenum, strerror(errno));
return (-1);
}
@@ -1257,7 +1243,7 @@ bsde_set_rule(int rulenum, struct mac_bsdextended_rule *rule, size_t buflen,
len = 10;
error = bsde_get_mib(MIB ".rules", name, &len);
if (error) {
- len = snprintf(errstr, buflen, "%s: %s", MIB ".rules",
+ snprintf(errstr, buflen, "%s: %s", MIB ".rules",
strerror(errno));
return (-1);
}
@@ -1267,7 +1253,7 @@ bsde_set_rule(int rulenum, struct mac_bsdextended_rule *rule, size_t buflen,
error = sysctl(name, len, NULL, NULL, rule, sizeof(*rule));
if (error) {
- len = snprintf(errstr, buflen, "%s.%d: %s", MIB ".rules",
+ snprintf(errstr, buflen, "%s.%d: %s", MIB ".rules",
rulenum, strerror(errno));
return (-1);
}
@@ -1290,14 +1276,14 @@ bsde_add_rule(int *rulenum, struct mac_bsdextended_rule *rule, size_t buflen,
len = 10;
error = bsde_get_mib(MIB ".rules", name, &len);
if (error) {
- len = snprintf(errstr, buflen, "%s: %s", MIB ".rules",
+ snprintf(errstr, buflen, "%s: %s", MIB ".rules",
strerror(errno));
return (-1);
}
rule_slots = bsde_get_rule_slots(BUFSIZ, charstr);
if (rule_slots == -1) {
- len = snprintf(errstr, buflen, "unable to get rule slots: %s",
+ snprintf(errstr, buflen, "unable to get rule slots: %s",
strerror(errno));
return (-1);
}
@@ -1307,7 +1293,7 @@ bsde_add_rule(int *rulenum, struct mac_bsdextended_rule *rule, size_t buflen,
error = sysctl(name, len, NULL, NULL, rule, sizeof(*rule));
if (error) {
- len = snprintf(errstr, buflen, "%s.%d: %s", MIB ".rules",
+ snprintf(errstr, buflen, "%s.%d: %s", MIB ".rules",
rule_slots, strerror(errno));
return (-1);
}
OpenPOWER on IntegriCloud