ANSIfy, WARNSify, CONSTify. Bit of style(9)-ify.
This commit is contained in:
parent
804b0f979a
commit
547fa0d9b7
@ -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;
|
||||
|
@ -47,9 +47,7 @@ static int isescaped(const char *, const char *, int);
|
||||
* that starts in *sp, is escaped by the escape character esc.
|
||||
*/
|
||||
static int
|
||||
isescaped(sp, p, esc)
|
||||
const char *sp, *p;
|
||||
int esc;
|
||||
isescaped(const char *sp, const char *p, int esc)
|
||||
{
|
||||
const char *cp;
|
||||
size_t ne;
|
||||
@ -78,12 +76,7 @@ isescaped(sp, p, esc)
|
||||
* the comment char.
|
||||
*/
|
||||
char *
|
||||
fparseln(fp, size, lineno, str, flags)
|
||||
FILE *fp;
|
||||
size_t *size;
|
||||
size_t *lineno;
|
||||
const char str[3];
|
||||
int flags;
|
||||
fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
|
||||
{
|
||||
static const char dstr[3] = { '\\', '\\', '#' };
|
||||
|
||||
@ -199,12 +192,8 @@ fparseln(fp, size, lineno, str, flags)
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
int main(int, char **);
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char *ptr;
|
||||
size_t size, line;
|
||||
|
@ -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);
|
||||
|
@ -52,8 +52,7 @@ static char sccsid[] = "@(#)login.c 8.1 (Berkeley) 6/4/93";
|
||||
#include <utmp.h>
|
||||
|
||||
void
|
||||
login(ut)
|
||||
struct utmp *ut;
|
||||
login(struct utmp *ut)
|
||||
{
|
||||
struct ttyent *ty;
|
||||
int fd;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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 *);
|
||||
|
@ -217,7 +217,7 @@ setclassenvironment(login_cap_t *lc, const struct passwd * pwd, int paths)
|
||||
* which the admin and/or user may set an arbitrary set of env vars.
|
||||
*/
|
||||
if (!paths) {
|
||||
char **set_env = login_getcaplist(lc, "setenv", ",");
|
||||
const char **set_env = login_getcaplist(lc, "setenv", ",");
|
||||
|
||||
if (set_env != NULL) {
|
||||
while (*set_env != NULL) {
|
||||
|
@ -48,7 +48,7 @@ __FBSDID("$FreeBSD$");
|
||||
*/
|
||||
|
||||
int
|
||||
login_strinlist(char **list, char const *str, int flags)
|
||||
login_strinlist(const char **list, char const *str, int flags)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
@ -68,7 +68,7 @@ login_strinlist(char **list, char const *str, int flags)
|
||||
*/
|
||||
|
||||
int
|
||||
login_str2inlist(char **ttlst, const char *str1, const char *str2, int flags)
|
||||
login_str2inlist(const char **ttlst, const char *str1, const char *str2, int flags)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
@ -93,7 +93,7 @@ login_timelist(login_cap_t *lc, char const *cap, int *ltno,
|
||||
{
|
||||
int j = 0;
|
||||
struct login_time *lt = NULL;
|
||||
char **tl;
|
||||
const char **tl;
|
||||
|
||||
if ((tl = login_getcaplist(lc, cap, NULL)) != NULL) {
|
||||
|
||||
@ -133,7 +133,7 @@ login_ttyok(login_cap_t *lc, const char *tty, const char *allowcap,
|
||||
if (lc != NULL && tty != NULL && *tty != '\0') {
|
||||
struct ttyent *te;
|
||||
char *grp;
|
||||
char **ttl;
|
||||
const char **ttl;
|
||||
|
||||
te = getttynam(tty); /* Need group name */
|
||||
grp = te ? te->ty_group : NULL;
|
||||
@ -181,7 +181,7 @@ login_hostok(login_cap_t *lc, const char *host, const char *ip,
|
||||
|
||||
if (lc != NULL &&
|
||||
((host != NULL && *host != '\0') || (ip != NULL && *ip != '\0'))) {
|
||||
char **hl;
|
||||
const char **hl;
|
||||
|
||||
hl = login_getcaplist(lc, allowcap, NULL);
|
||||
if (hl != NULL && !login_str2inlist(hl, host, ip, FNM_CASEFOLD))
|
||||
|
@ -48,8 +48,7 @@ static char sccsid[] = "@(#)login_tty.c 8.1 (Berkeley) 6/4/93";
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
login_tty(fd)
|
||||
int fd;
|
||||
login_tty(int fd)
|
||||
{
|
||||
(void) setsid();
|
||||
if (ioctl(fd, TIOCSCTTY, (char *)NULL) == -1)
|
||||
|
@ -54,8 +54,7 @@ static char sccsid[] = "@(#)logout.c 8.1 (Berkeley) 6/4/93";
|
||||
typedef struct utmp UTMP;
|
||||
|
||||
int
|
||||
logout(line)
|
||||
const char *line;
|
||||
logout(const char *line)
|
||||
{
|
||||
int fd;
|
||||
UTMP ut;
|
||||
|
@ -61,10 +61,7 @@ static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93";
|
||||
|
||||
|
||||
void
|
||||
logwtmp(line, name, host)
|
||||
const char *line;
|
||||
const char *name;
|
||||
const char *host;
|
||||
logwtmp(const char *line, const char *name, const char *host)
|
||||
{
|
||||
struct utmp ut;
|
||||
struct stat buf;
|
||||
|
@ -54,11 +54,7 @@ static char sccsid[] = "@(#)pty.c 8.3 (Berkeley) 5/16/94";
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
openpty(amaster, aslave, name, termp, winp)
|
||||
int *amaster, *aslave;
|
||||
char *name;
|
||||
struct termios *termp;
|
||||
struct winsize *winp;
|
||||
openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct winsize *winp)
|
||||
{
|
||||
char line[] = "/dev/ptyXX";
|
||||
const char *cp1, *cp2;
|
||||
@ -105,11 +101,7 @@ openpty(amaster, aslave, name, termp, winp)
|
||||
}
|
||||
|
||||
int
|
||||
forkpty(amaster, name, termp, winp)
|
||||
int *amaster;
|
||||
char *name;
|
||||
struct termios *termp;
|
||||
struct winsize *winp;
|
||||
forkpty(int *amaster, char *name, struct termios *termp, struct winsize *winp)
|
||||
{
|
||||
int master, slave, pid;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -58,7 +58,7 @@ realhostname(char *host, size_t hsize, const struct in_addr *ip)
|
||||
struct hostent *hp;
|
||||
|
||||
result = HOSTNAME_INVALIDADDR;
|
||||
hp = gethostbyaddr((char *)ip, sizeof(*ip), AF_INET);
|
||||
hp = gethostbyaddr((const char *)ip, sizeof(*ip), AF_INET);
|
||||
|
||||
if (hp != NULL) {
|
||||
strlcpy(trimmed, hp->h_name, sizeof(trimmed));
|
||||
@ -94,7 +94,7 @@ realhostname_sa(char *host, size_t hsize, struct sockaddr *addr, int addrlen)
|
||||
{
|
||||
int result, error;
|
||||
char buf[NI_MAXHOST];
|
||||
struct sockaddr_in sin;
|
||||
struct sockaddr_in lsin;
|
||||
|
||||
result = HOSTNAME_INVALIDADDR;
|
||||
|
||||
@ -107,14 +107,14 @@ realhostname_sa(char *host, size_t hsize, struct sockaddr *addr, int addrlen)
|
||||
|
||||
sin6 = (struct sockaddr_in6 *)addr;
|
||||
|
||||
memset(&sin, 0, sizeof(sin));
|
||||
sin.sin_len = sizeof(struct sockaddr_in);
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_port = sin6->sin6_port;
|
||||
memcpy(&sin.sin_addr, &sin6->sin6_addr.s6_addr[12],
|
||||
memset(&lsin, 0, sizeof(lsin));
|
||||
lsin.sin_len = sizeof(struct sockaddr_in);
|
||||
lsin.sin_family = AF_INET;
|
||||
lsin.sin_port = sin6->sin6_port;
|
||||
memcpy(&lsin.sin_addr, &sin6->sin6_addr.s6_addr[12],
|
||||
sizeof(struct in_addr));
|
||||
addr = (struct sockaddr *)&sin;
|
||||
addrlen = sin.sin_len;
|
||||
addr = (struct sockaddr *)&lsin;
|
||||
addrlen = lsin.sin_len;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -29,14 +29,16 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*
|
||||
* Stub out what's in -lcrypt.
|
||||
*/
|
||||
|
||||
#pragma weak crypt_set_format
|
||||
/* ARGSUSED */
|
||||
int
|
||||
crypt_set_format(const char *f) {
|
||||
crypt_set_format(const char *f __unused) {
|
||||
|
||||
if (getenv("CRYPT_DEBUG") != NULL)
|
||||
fprintf(stderr, "crypt_set_format: eek, stub called!\n");
|
||||
|
@ -75,7 +75,7 @@ trimdomain(char *fullhost, int hostsize)
|
||||
|
||||
s = fullhost;
|
||||
end = s + hostsize + 1;
|
||||
for (; (s = memchr(s, '.', end - s)) != NULL; s++) {
|
||||
for (; (s = memchr(s, '.', (size_t)(end - s))) != NULL; s++) {
|
||||
if (strncasecmp(s + 1, domain, dlen) == 0) {
|
||||
if (s[dlen + 1] == '\0') {
|
||||
/* Found -- lose the domain. */
|
||||
@ -83,7 +83,7 @@ trimdomain(char *fullhost, int hostsize)
|
||||
break;
|
||||
} else if (s[dlen + 1] == ':' &&
|
||||
isDISP(s + dlen + 2) &&
|
||||
(len = strlen(s + dlen + 1)) < end - s) {
|
||||
(len = strlen(s + dlen + 1)) < (size_t)(end - s)) {
|
||||
/* Found -- shuffle the DISPLAY back. */
|
||||
memmove(s, s + dlen + 1, len + 1);
|
||||
break;
|
||||
@ -98,7 +98,8 @@ trimdomain(char *fullhost, int hostsize)
|
||||
static int
|
||||
isDISP(const char *disp)
|
||||
{
|
||||
int res, w;
|
||||
size_t w;
|
||||
int res;
|
||||
|
||||
w = strspn(disp, "0123456789");
|
||||
res = 0;
|
||||
|
@ -67,7 +67,7 @@ static pid_t get_pid (int fd,int *err);
|
||||
*/
|
||||
|
||||
int
|
||||
uu_lock(const char *ttyname)
|
||||
uu_lock(const char *tty_name)
|
||||
{
|
||||
int fd, tmpfd, i;
|
||||
pid_t pid, pid_old;
|
||||
@ -79,7 +79,7 @@ uu_lock(const char *ttyname)
|
||||
(void)snprintf(lcktmpname, sizeof(lcktmpname), _PATH_UUCPLOCK LOCKTMP,
|
||||
pid);
|
||||
(void)snprintf(lckname, sizeof(lckname), _PATH_UUCPLOCK LOCKFMT,
|
||||
ttyname);
|
||||
tty_name);
|
||||
if ((tmpfd = creat(lcktmpname, 0664)) < 0)
|
||||
GORET(0, UU_LOCK_CREAT_ERR);
|
||||
|
||||
@ -129,19 +129,19 @@ ret0:
|
||||
}
|
||||
|
||||
int
|
||||
uu_lock_txfr(const char *ttyname, pid_t pid)
|
||||
uu_lock_txfr(const char *tty_name, pid_t pid)
|
||||
{
|
||||
int fd, err;
|
||||
char lckname[sizeof(_PATH_UUCPLOCK) + MAXNAMLEN];
|
||||
|
||||
snprintf(lckname, sizeof(lckname), _PATH_UUCPLOCK LOCKFMT, ttyname);
|
||||
snprintf(lckname, sizeof(lckname), _PATH_UUCPLOCK LOCKFMT, tty_name);
|
||||
|
||||
if ((fd = open(lckname, O_RDWR)) < 0)
|
||||
return UU_LOCK_OWNER_ERR;
|
||||
if (get_pid(fd, &err) != getpid())
|
||||
err = UU_LOCK_OWNER_ERR;
|
||||
else {
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
lseek(fd, (off_t)0, SEEK_SET);
|
||||
err = put_pid(fd, pid) ? 0 : UU_LOCK_WRITE_ERR;
|
||||
}
|
||||
close(fd);
|
||||
@ -150,11 +150,11 @@ uu_lock_txfr(const char *ttyname, pid_t pid)
|
||||
}
|
||||
|
||||
int
|
||||
uu_unlock(const char *ttyname)
|
||||
uu_unlock(const char *tty_name)
|
||||
{
|
||||
char tbuf[sizeof(_PATH_UUCPLOCK) + MAXNAMLEN];
|
||||
|
||||
(void)snprintf(tbuf, sizeof(tbuf), _PATH_UUCPLOCK LOCKFMT, ttyname);
|
||||
(void)snprintf(tbuf, sizeof(tbuf), _PATH_UUCPLOCK LOCKFMT, tty_name);
|
||||
return unlink(tbuf);
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ const char *
|
||||
uu_lockerr(int uu_lockresult)
|
||||
{
|
||||
static char errbuf[128];
|
||||
char *fmt;
|
||||
const char *fmt;
|
||||
|
||||
switch (uu_lockresult) {
|
||||
case UU_LOCK_INUSE:
|
||||
@ -206,7 +206,7 @@ put_pid(int fd, pid_t pid)
|
||||
int len;
|
||||
|
||||
len = sprintf (buf, "%10d\n", (int)pid);
|
||||
return write (fd, buf, len) == len;
|
||||
return write (fd, buf, (size_t)len) == len;
|
||||
}
|
||||
|
||||
static pid_t
|
||||
@ -219,7 +219,7 @@ get_pid(int fd, int *err)
|
||||
bytes_read = read (fd, buf, sizeof (buf) - 1);
|
||||
if (bytes_read > 0) {
|
||||
buf[bytes_read] = '\0';
|
||||
pid = strtol (buf, (char **) NULL, 10);
|
||||
pid = (pid_t)strtol (buf, (char **) NULL, 10);
|
||||
} else {
|
||||
pid = -1;
|
||||
*err = bytes_read ? errno : EINVAL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user