summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Murray <markm@FreeBSD.org>2003-10-18 10:04:16 +0000
committerMark Murray <markm@FreeBSD.org>2003-10-18 10:04:16 +0000
commit1bb634ce247e398483c157e44c4bd8d2cef73dd0 (patch)
tree2dc8cb8c5a0f6b219c8df70f498efe1353caec6b
parent24078af1d1886060d75aa6da90eaaee07138f5ff (diff)
downloadpw-darwin-1bb634ce247e398483c157e44c4bd8d2cef73dd0.tar.gz
pw-darwin-1bb634ce247e398483c157e44c4bd8d2cef73dd0.tar.zst
pw-darwin-1bb634ce247e398483c157e44c4bd8d2cef73dd0.zip
ANSIfy, WARNSify, CONSTify. Bit of style(9)-ify.
-rw-r--r--libutil/_secure_path.c4
-rw-r--r--libutil/libutil.h10
-rw-r--r--libutil/login_cap.c68
-rw-r--r--libutil/login_cap.h6
-rw-r--r--libutil/pw_util.c65
5 files changed, 79 insertions, 74 deletions
diff --git a/libutil/_secure_path.c b/libutil/_secure_path.c
index 550a092..0411080 100644
--- a/libutil/_secure_path.c
+++ b/libutil/_secure_path.c
@@ -59,12 +59,12 @@ _secure_path(const char *path, uid_t uid, gid_t gid)
msg = "%s: %s is not a regular file";
else if (sb.st_mode & S_IWOTH)
msg = "%s: %s is world writable";
- else if (uid != -1 && sb.st_uid != uid && sb.st_uid != 0) {
+ else if ((int)uid != -1 && sb.st_uid != uid && sb.st_uid != 0) {
if (uid == 0)
msg = "%s: %s is not owned by root";
else
msg = "%s: %s is not owned by uid %d";
- } else if (gid != -1 && sb.st_gid != gid && (sb.st_mode & S_IWGRP))
+ } else if ((int)gid != -1 && sb.st_gid != gid && (sb.st_mode & S_IWGRP))
msg = "%s: %s is group writeable by non-authorised groups";
else
r = 0;
diff --git a/libutil/libutil.h b/libutil/libutil.h
index b3ebc6a..f2c2663 100644
--- a/libutil/libutil.h
+++ b/libutil/libutil.h
@@ -39,8 +39,6 @@
#ifndef _LIBUTIL_H_
#define _LIBUTIL_H_
-#include <sys/cdefs.h>
-
#define PROPERTY_MAX_NAME 64
#define PROPERTY_MAX_VALUE 512
@@ -87,13 +85,13 @@ char *fparseln(FILE *, size_t *, size_t *, const char[3], int);
#endif
#ifdef _PWD_H_
-int pw_copy(int _ffd, int _tfd, struct passwd *_pw, struct passwd *_old_pw);
-struct passwd *pw_dup(struct passwd *_pw);
+int pw_copy(int _ffd, int _tfd, const struct passwd *_pw, struct passwd *_old_pw);
+struct passwd *pw_dup(const struct passwd *_pw);
int pw_edit(int _notsetuid);
-int pw_equal(struct passwd *_pw1, struct passwd *_pw2);
+int pw_equal(const struct passwd *_pw1, const struct passwd *_pw2);
void pw_fini(void);
int pw_init(const char *_dir, const char *_master);
-char *pw_make(struct passwd *_pw);
+char *pw_make(const struct passwd *_pw);
int pw_mkdb(const char *_user);
int pw_lock(void);
struct passwd *pw_scan(const char *_line, int _flags);
diff --git a/libutil/login_cap.c b/libutil/login_cap.c
index b719303..8347b51 100644
--- a/libutil/login_cap.c
+++ b/libutil/login_cap.c
@@ -59,10 +59,10 @@ static int lc_object_count = 0;
static size_t internal_stringsz = 0;
static char * internal_string = NULL;
static size_t internal_arraysz = 0;
-static char ** internal_array = NULL;
+static const char ** internal_array = NULL;
static char *
-allocstr(char *str)
+allocstr(const char *str)
{
char *p;
@@ -77,10 +77,10 @@ allocstr(char *str)
}
-static char **
+static const char **
allocarray(size_t sz)
{
- char **p;
+ static const char **p;
if (sz <= internal_arraysz)
p = internal_array;
@@ -100,12 +100,12 @@ allocarray(size_t sz)
* Free using freearraystr()
*/
-static char **
-arrayize(char *str, const char *chars, int *size)
+static const char **
+arrayize(const char *str, const char *chars, int *size)
{
int i;
- char *ptr;
- char **res = NULL;
+ const char *ptr;
+ const char **res = NULL;
/* count the sub-strings */
for (i = 0, ptr = str; *ptr; i++) {
@@ -191,7 +191,7 @@ login_getclassbyname(char const *name, const struct passwd *pwd)
const char *dir;
char userpath[MAXPATHLEN];
- static char *login_dbarray[] = { NULL, NULL, NULL };
+ static const char *login_dbarray[] = { NULL, NULL, NULL };
me = (name != NULL && strcmp(name, LOGIN_MECLASS) == 0);
dir = (!me || pwd == NULL) ? NULL : pwd->pw_dir;
@@ -224,7 +224,7 @@ login_getclassbyname(char const *name, const struct passwd *pwd)
if (name == NULL || *name == '\0')
name = LOGIN_DEFCLASS;
- switch (cgetent(&lc->lc_cap, login_dbarray, (char*)name)) {
+ switch (cgetent(&lc->lc_cap, login_dbarray, name)) {
case -1: /* Failed, entry does not exist */
if (me)
break; /* Don't retry default on 'me' */
@@ -242,7 +242,7 @@ login_getclassbyname(char const *name, const struct passwd *pwd)
/* fall-back to default class */
name = LOGIN_DEFCLASS;
msg = "%s: no default/fallback class '%s'";
- if (cgetent(&lc->lc_cap, login_dbarray, (char*)name) != 0 && r >= 0)
+ if (cgetent(&lc->lc_cap, login_dbarray, name) != 0 && r >= 0)
break;
/* FALLTHROUGH - just return system defaults */
case 0: /* success! */
@@ -352,7 +352,7 @@ login_getcapstr(login_cap_t *lc, const char *cap, const char *def, const char *e
if (lc == NULL || cap == NULL || lc->lc_cap == NULL || *cap == '\0')
return def;
- if ((ret = cgetstr(lc->lc_cap, (char *)cap, &res)) == -1)
+ if ((ret = cgetstr(lc->lc_cap, cap, &res)) == -1)
return def;
return (ret >= 0) ? res : error;
}
@@ -365,14 +365,14 @@ login_getcapstr(login_cap_t *lc, const char *cap, const char *def, const char *e
* strings.
*/
-char **
+const char **
login_getcaplist(login_cap_t *lc, const char *cap, const char *chars)
{
- char *lstring;
+ const char *lstring;
if (chars == NULL)
chars = ", \t";
- if ((lstring = (char *)login_getcapstr(lc, cap, NULL, NULL)) != NULL)
+ if ((lstring = login_getcapstr(lc, cap, NULL, NULL)) != NULL)
return arrayize(lstring, chars, NULL);
return NULL;
}
@@ -390,18 +390,18 @@ const char *
login_getpath(login_cap_t *lc, const char *cap, const char *error)
{
const char *str;
+ char *ptr;
+ int count;
- if ((str = login_getcapstr(lc, cap, NULL, NULL)) == NULL)
- str = error;
- else {
- char *ptr = (char *)str;
-
- while (*ptr) {
- int count = strcspn(ptr, ", \t");
- ptr += count;
- if (*ptr)
- *ptr++ = ':';
- }
+ str = login_getcapstr(lc, cap, NULL, NULL);
+ if (str == NULL)
+ return error;
+ ptr = __DECONST(char *, str); /* XXXX Yes, very dodgy */
+ while (*ptr) {
+ count = strcspn(ptr, ", \t");
+ ptr += count;
+ if (*ptr)
+ *ptr++ = ':';
}
return str;
}
@@ -535,7 +535,7 @@ login_getcaptime(login_cap_t *lc, const char *cap, rlim_t def, rlim_t error)
* If there's an error, return <error>.
*/
- if ((r = cgetstr(lc->lc_cap, (char *)cap, &res)) == -1)
+ if ((r = cgetstr(lc->lc_cap, cap, &res)) == -1)
return def;
else if (r < 0) {
errno = ERANGE;
@@ -622,10 +622,10 @@ login_getcapnum(login_cap_t *lc, const char *cap, rlim_t def, rlim_t error)
/*
* For BSDI compatibility, try for the tag=<val> first
*/
- if ((r = cgetstr(lc->lc_cap, (char *)cap, &res)) == -1) {
+ if ((r = cgetstr(lc->lc_cap, cap, &res)) == -1) {
long lval;
/* string capability not present, so try for tag#<val> as numeric */
- if ((r = cgetnum(lc->lc_cap, (char *)cap, &lval)) == -1)
+ if ((r = cgetnum(lc->lc_cap, cap, &lval)) == -1)
return def; /* Not there, so return default */
else if (r >= 0)
return (rlim_t)lval;
@@ -671,7 +671,7 @@ login_getcapsize(login_cap_t *lc, const char *cap, rlim_t def, rlim_t error)
if (lc == NULL || lc->lc_cap == NULL)
return def;
- if ((r = cgetstr(lc->lc_cap, (char *)cap, &res)) == -1)
+ if ((r = cgetstr(lc->lc_cap, cap, &res)) == -1)
return def;
else if (r < 0) {
errno = ERANGE;
@@ -739,7 +739,7 @@ login_getcapbool(login_cap_t *lc, const char *cap, int def)
{
if (lc == NULL || lc->lc_cap == NULL)
return def;
- return (cgetcap(lc->lc_cap, (char *)cap, ':') != NULL);
+ return (cgetcap(lc->lc_cap, cap, ':') != NULL);
}
@@ -767,14 +767,14 @@ const char *
login_getstyle(login_cap_t *lc, const char *style, const char *auth)
{
int i;
- char **authtypes = NULL;
+ const char **authtypes = NULL;
char *auths= NULL;
char realauth[64];
- static char *defauthtypes[] = { LOGIN_DEFSTYLE, NULL };
+ static const char *defauthtypes[] = { LOGIN_DEFSTYLE, NULL };
if (auth != NULL && *auth != '\0') {
- if (snprintf(realauth, sizeof realauth, "auth-%s", auth) < sizeof realauth)
+ if (snprintf(realauth, sizeof realauth, "auth-%s", auth) < (int)sizeof(realauth))
authtypes = login_getcaplist(lc, realauth, NULL);
}
diff --git a/libutil/login_cap.h b/libutil/login_cap.h
index f6c6431..a7cb4c6 100644
--- a/libutil/login_cap.h
+++ b/libutil/login_cap.h
@@ -104,7 +104,7 @@ login_cap_t *login_getpwclass(const struct passwd *);
login_cap_t *login_getuserclass(const struct passwd *);
const char *login_getcapstr(login_cap_t*, const char *, const char *, const char *);
-char **login_getcaplist(login_cap_t *, const char *, const char *);
+const char **login_getcaplist(login_cap_t *, const char *, const char *);
const char *login_getstyle(login_cap_t *, const char *, const char *);
rlim_t login_getcaptime(login_cap_t *, const char *, rlim_t, rlim_t);
rlim_t login_getcapnum(login_cap_t *, const char *, rlim_t, rlim_t);
@@ -147,8 +147,8 @@ int in_ltms(const login_time_t *, struct tm *, time_t *);
/* helper functions */
-int login_strinlist(char **, char const *, int);
-int login_str2inlist(char **, const char *, const char *, int);
+int login_strinlist(const char **, char const *, int);
+int login_str2inlist(const char **, const char *, const char *, int);
login_time_t * login_timelist(login_cap_t *, char const *, int *, login_time_t **);
int login_ttyok(login_cap_t *, const char *, const char *, const char *);
int login_hostok(login_cap_t *, const char *, const char *, const char *, const char *);
diff --git a/libutil/pw_util.c b/libutil/pw_util.c
index 114bf72..708583d 100644
--- a/libutil/pw_util.c
+++ b/libutil/pw_util.c
@@ -80,6 +80,7 @@ static char passwd_dir[PATH_MAX];
static char tempname[PATH_MAX];
static int initialized;
+#if 0
void
pw_cont(int sig)
{
@@ -87,6 +88,7 @@ pw_cont(int sig)
if (editpid != -1)
kill(editpid, sig);
}
+#endif
/*
* Initialize statics and set limits, signals & umask to try to avoid
@@ -102,7 +104,7 @@ pw_init(const char *dir, const char *master)
if (dir == NULL) {
strcpy(passwd_dir, _PATH_ETC);
} else {
- if (strlen(dir) >= sizeof passwd_dir) {
+ if (strlen(dir) >= sizeof(passwd_dir)) {
errno = ENAMETOOLONG;
return (-1);
}
@@ -112,13 +114,13 @@ pw_init(const char *dir, const char *master)
if (master == NULL) {
if (dir == NULL) {
strcpy(masterpasswd, _PATH_MASTERPASSWD);
- } else if (snprintf(masterpasswd, sizeof masterpasswd, "%s/%s",
- passwd_dir, _MASTERPASSWD) > sizeof masterpasswd) {
+ } else if (snprintf(masterpasswd, sizeof(masterpasswd), "%s/%s",
+ passwd_dir, _MASTERPASSWD) > (int)sizeof(masterpasswd)) {
errno = ENAMETOOLONG;
return (-1);
}
} else {
- if (strlen(master) >= sizeof masterpasswd) {
+ if (strlen(master) >= sizeof(masterpasswd)) {
errno = ENAMETOOLONG;
return (-1);
}
@@ -216,7 +218,7 @@ int
pw_tmp(int mfd)
{
char buf[8192];
- ssize_t nr, nw;
+ ssize_t nr;
const char *p;
int tfd;
@@ -226,16 +228,16 @@ pw_tmp(int mfd)
++p;
else
p = masterpasswd;
- if (snprintf(tempname, sizeof tempname, "%.*spw.XXXXXX",
- (int)(p - masterpasswd), masterpasswd) >= sizeof tempname) {
+ if (snprintf(tempname, sizeof(tempname), "%.*spw.XXXXXX",
+ (int)(p - masterpasswd), masterpasswd) >= (int)sizeof(tempname)) {
errno = ENAMETOOLONG;
return (-1);
}
if ((tfd = mkstemp(tempname)) == -1)
return (-1);
if (mfd != -1) {
- while ((nr = read(mfd, buf, sizeof buf)) > 0)
- if ((nw = write(tfd, buf, nr)) != nr)
+ while ((nr = read(mfd, buf, sizeof(buf))) > 0)
+ if (write(tfd, buf, (size_t)nr) != nr)
break;
if (nr != 0) {
unlink(tempname);
@@ -269,6 +271,7 @@ pw_mkdb(const char *user)
execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p",
"-d", passwd_dir, "-u", user, tempname, NULL);
_exit(1);
+ /* NOTREACHED */
default:
/* parent */
break;
@@ -381,7 +384,7 @@ pw_fini(void)
* Compares two struct pwds.
*/
int
-pw_equal(struct passwd *pw1, struct passwd *pw2)
+pw_equal(const struct passwd *pw1, const struct passwd *pw2)
{
return (strcmp(pw1->pw_name, pw2->pw_name) == 0 &&
pw1->pw_uid == pw2->pw_uid &&
@@ -398,7 +401,7 @@ pw_equal(struct passwd *pw1, struct passwd *pw2)
* Make a passwd line out of a struct passwd.
*/
char *
-pw_make(struct passwd *pw)
+pw_make(const struct passwd *pw)
{
char *line;
@@ -414,12 +417,12 @@ pw_make(struct passwd *pw)
* a single record on the way.
*/
int
-pw_copy(int ffd, int tfd, struct passwd *pw, struct passwd *old_pw)
+pw_copy(int ffd, int tfd, const struct passwd *pw, struct passwd *old_pw)
{
char buf[8192], *end, *line, *p, *q, *r, t;
struct passwd *fpw;
- ssize_t len;
- int eof;
+ size_t len;
+ int eof, readlen;
if ((line = pw_make(pw)) == NULL)
return (-1);
@@ -437,7 +440,7 @@ pw_copy(int ffd, int tfd, struct passwd *pw, struct passwd *old_pw)
if (q >= end) {
if (eof)
break;
- if (q - p >= sizeof buf) {
+ if ((size_t)(q - p) >= sizeof(buf)) {
warnx("passwd line too long");
errno = EINVAL; /* hack */
goto err;
@@ -448,14 +451,16 @@ pw_copy(int ffd, int tfd, struct passwd *pw, struct passwd *old_pw)
} else {
p = q = end = buf;
}
- len = read(ffd, end, sizeof buf - (end - buf));
- if (len == -1)
+ readlen = read(ffd, end, sizeof(buf) - (end - buf));
+ if (readlen == -1)
goto err;
+ else
+ len = (size_t)readlen;
if (len == 0 && p == buf)
break;
end += len;
len = end - buf;
- if (len < sizeof buf) {
+ if (len < (ssize_t)sizeof(buf)) {
eof = 1;
if (len > 0 && buf[len - 1] != '\n')
++len, *end++ = '\n';
@@ -497,7 +502,7 @@ pw_copy(int ffd, int tfd, struct passwd *pw, struct passwd *old_pw)
/* it is, replace it */
len = strlen(line);
- if (write(tfd, line, len) != len)
+ if (write(tfd, line, len) != (int)len)
goto err;
/* we're done, just copy the rest over */
@@ -505,10 +510,12 @@ pw_copy(int ffd, int tfd, struct passwd *pw, struct passwd *old_pw)
if (write(tfd, q, end - q) != end - q)
goto err;
q = buf;
- len = read(ffd, buf, sizeof buf);
- if (len == 0)
+ readlen = read(ffd, buf, sizeof(buf));
+ if (readlen == 0)
break;
- if (len == -1)
+ else
+ len = (size_t)readlen;
+ if (readlen == -1)
goto err;
end = buf + len;
}
@@ -517,7 +524,7 @@ pw_copy(int ffd, int tfd, struct passwd *pw, struct passwd *old_pw)
/* if we got here, we have a new entry */
len = strlen(line);
- if (write(tfd, line, len) != len ||
+ if ((size_t)write(tfd, line, len) != len ||
write(tfd, "\n", 1) != 1)
goto err;
done:
@@ -542,22 +549,22 @@ pw_tempname(void)
* Duplicate a struct passwd.
*/
struct passwd *
-pw_dup(struct passwd *pw)
+pw_dup(const struct passwd *pw)
{
struct passwd *npw;
- size_t len;
+ ssize_t len;
- len = sizeof *npw +
+ len = sizeof(*npw) +
(pw->pw_name ? strlen(pw->pw_name) + 1 : 0) +
(pw->pw_passwd ? strlen(pw->pw_passwd) + 1 : 0) +
(pw->pw_class ? strlen(pw->pw_class) + 1 : 0) +
(pw->pw_gecos ? strlen(pw->pw_gecos) + 1 : 0) +
(pw->pw_dir ? strlen(pw->pw_dir) + 1 : 0) +
(pw->pw_shell ? strlen(pw->pw_shell) + 1 : 0);
- if ((npw = malloc(len)) == NULL)
+ if ((npw = malloc((size_t)len)) == NULL)
return (NULL);
- memcpy(npw, pw, sizeof *npw);
- len = sizeof *npw;
+ memcpy(npw, pw, sizeof(*npw));
+ len = sizeof(*npw);
if (pw->pw_name) {
npw->pw_name = ((char *)npw) + len;
len += sprintf(npw->pw_name, "%s", pw->pw_name) + 1;