large strc{py,at}_truncate -> strlc{py,at} replacement

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@6984 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
1999-09-16 20:41:57 +00:00
parent 8e441f1158
commit bf75fac82a
42 changed files with 176 additions and 171 deletions

View File

@@ -119,16 +119,16 @@ setpeer(int argc, char **argv)
/*
* Set up defaults for FTP.
*/
strcpy_truncate(typename, "ascii", sizeof(typename));
strlcpy(typename, "ascii", sizeof(typename));
type = TYPE_A;
curtype = TYPE_A;
strcpy_truncate(formname, "non-print", sizeof(formname));
strlcpy(formname, "non-print", sizeof(formname));
form = FORM_N;
strcpy_truncate(modename, "stream", sizeof(modename));
strlcpy(modename, "stream", sizeof(modename));
mode = MODE_S;
strcpy_truncate(structname, "file", sizeof(structname));
strlcpy(structname, "file", sizeof(structname));
stru = STRU_F;
strcpy_truncate(bytename, "8", sizeof(bytename));
strlcpy(bytename, "8", sizeof(bytename));
bytesize = 8;
if (autologin)
login(argv[1]);
@@ -170,7 +170,7 @@ setpeer(int argc, char **argv)
* for text files unless changed by the user.
*/
type = 0;
strcpy_truncate(typename, "binary", sizeof(typename));
strlcpy(typename, "binary", sizeof(typename));
if (overbose)
printf("Using %s mode to transfer files.\n",
typename);
@@ -243,7 +243,7 @@ settype(int argc, char **argv)
else
comret = command("TYPE %s", p->t_mode);
if (comret == COMPLETE) {
strcpy_truncate(typename, p->t_name, sizeof(typename));
strlcpy(typename, p->t_name, sizeof(typename));
curtype = type = p->t_type;
}
}
@@ -784,7 +784,7 @@ remglob(char **argv, int doswitch)
}
if (ftemp == NULL) {
int fd;
strcpy_truncate(temp, _PATH_TMP_XXX, sizeof(temp));
strlcpy(temp, _PATH_TMP_XXX, sizeof(temp));
fd = mkstemp(temp);
if(fd < 0){
warn("unable to create temporary file %s", temp);
@@ -1419,11 +1419,11 @@ quote1(char *initial, int argc, char **argv)
int i;
char buf[BUFSIZ]; /* must be >= sizeof(line) */
strcpy_truncate(buf, initial, sizeof(buf));
strlcpy(buf, initial, sizeof(buf));
for(i = 1; i < argc; i++) {
if(i > 1)
strcat_truncate(buf, " ", sizeof(buf));
strcat_truncate(buf, argv[i], sizeof(buf));
strlcat(buf, " ", sizeof(buf));
strlcat(buf, argv[i], sizeof(buf));
}
if (command("%s", buf) == PRELIM) {
while (getreply(0) == PRELIM)
@@ -1575,11 +1575,11 @@ account(int argc, char **argv)
if (argc > 1) {
++argv;
--argc;
strcpy_truncate (acct, *argv, sizeof(acct));
strlcpy (acct, *argv, sizeof(acct));
while (argc > 1) {
--argc;
++argv;
strcat_truncate(acct, *argv, sizeof(acct));
strlcat(acct, *argv, sizeof(acct));
}
}
else {
@@ -1691,12 +1691,12 @@ setntrans(int argc, char **argv)
}
ntflag++;
code = ntflag;
strcpy_truncate (ntin, argv[1], 17);
strlcpy (ntin, argv[1], 17);
if (argc == 2) {
ntout[0] = '\0';
return;
}
strcpy_truncate (ntout, argv[2], 17);
strlcpy (ntout, argv[2], 17);
}
char *
@@ -1753,10 +1753,10 @@ setnmap(int argc, char **argv)
cp = strchr(altarg, ' ');
}
*cp = '\0';
strcpy_truncate(mapin, altarg, MaxPathLen);
strlcpy(mapin, altarg, MaxPathLen);
while (*++cp == ' ')
continue;
strcpy_truncate(mapout, cp, MaxPathLen);
strlcpy(mapout, cp, MaxPathLen);
}
char *
@@ -2008,7 +2008,7 @@ macdef(int argc, char **argv)
if (interactive) {
printf("Enter macro line by line, terminating it with a null line\n");
}
strcpy_truncate(macros[macnum].mac_name,
strlcpy(macros[macnum].mac_name,
argv[1],
sizeof(macros[macnum].mac_name));
if (macnum == 0) {

View File

@@ -56,7 +56,7 @@ domacro(int argc, char **argv)
code = -1;
return;
}
strcpy_truncate(line2, line, sizeof(line2));
strlcpy(line2, line, sizeof(line2));
TOP:
cp1 = macros[i].mac_start;
while (cp1 != macros[i].mac_end) {

View File

@@ -75,7 +75,7 @@ hookup (const char *host, int port)
code = -1;
return NULL;
}
strcpy_truncate (hostnamebuf, hp->h_name, sizeof(hostnamebuf));
strlcpy (hostnamebuf, hp->h_name, sizeof(hostnamebuf));
hostname = hostnamebuf;
af = hisctladdr->sa_family = hp->h_addrtype;
@@ -99,7 +99,7 @@ hookup (const char *host, int port)
if (inet_ntop (af, socket_get_address(hisctladdr),
addr, sizeof(addr)) == NULL)
strcpy_truncate (addr, "unknown address",
strlcpy (addr, "unknown address",
sizeof(addr));
warn ("connect %s", addr);
close (s);
@@ -200,7 +200,7 @@ login (char *host)
else
user = tmp;
}
strcpy_truncate(username, user, sizeof(username));
strlcpy(username, user, sizeof(username));
n = command("USER %s", user);
if (n == CONTINUE) {
if(sec_complete)
@@ -240,7 +240,7 @@ login (char *host)
return (1);
for (n = 0; n < macnum; ++n) {
if (!strcmp("init", macros[n].mac_name)) {
strcpy_truncate (line, "$init", sizeof (line));
strlcpy (line, "$init", sizeof (line));
makeargv();
domacro(margc, margv);
break;
@@ -1471,7 +1471,7 @@ pswitch (int flag)
ip->connect = connected;
connected = op->connect;
if (hostname) {
strcpy_truncate (ip->name, hostname, sizeof (ip->name));
strlcpy (ip->name, hostname, sizeof (ip->name));
} else
ip->name[0] = 0;
hostname = op->name;
@@ -1497,16 +1497,16 @@ pswitch (int flag)
mcase = op->mcse;
ip->ntflg = ntflag;
ntflag = op->ntflg;
strcpy_truncate (ip->nti, ntin, sizeof (ip->nti));
strcpy_truncate (ntin, op->nti, 17);
strcpy_truncate (ip->nto, ntout, sizeof (ip->nto));
strcpy_truncate (ntout, op->nto, 17);
strlcpy (ip->nti, ntin, sizeof (ip->nti));
strlcpy (ntin, op->nti, 17);
strlcpy (ip->nto, ntout, sizeof (ip->nto));
strlcpy (ntout, op->nto, 17);
ip->mapflg = mapflag;
mapflag = op->mapflg;
strcpy_truncate (ip->mi, mapin, MaxPathLen);
strcpy_truncate (mapin, op->mi, MaxPathLen);
strcpy_truncate (ip->mo, mapout, MaxPathLen);
strcpy_truncate (mapout, op->mo, MaxPathLen);
strlcpy (ip->mi, mapin, MaxPathLen);
strlcpy (mapin, op->mi, MaxPathLen);
strlcpy (ip->mo, mapout, MaxPathLen);
strlcpy (mapout, op->mo, MaxPathLen);
signal(SIGINT, oldintr);
if (abrtflag) {
abrtflag = 0;
@@ -1680,7 +1680,7 @@ gunique (char *local)
warn ("local: %s", local);
return NULL;
}
strcpy_truncate (new, local, sizeof(new));
strlcpy (new, local, sizeof(new));
cp = new + strlen(new);
*cp++ = '.';
while (!d) {

View File

@@ -152,9 +152,9 @@ krb4_adat(void *app_data, void *buf, size_t len)
memcpy(d->key, auth_dat.session, sizeof(d->key));
des_set_key(&d->key, d->schedule);
strcpy_truncate(d->name, auth_dat.pname, sizeof(d->name));
strcpy_truncate(d->instance, auth_dat.pinst, sizeof(d->instance));
strcpy_truncate(d->realm, auth_dat.prealm, sizeof(d->instance));
strlcpy(d->name, auth_dat.pname, sizeof(d->name));
strlcpy(d->instance, auth_dat.pinst, sizeof(d->instance));
strlcpy(d->realm, auth_dat.prealm, sizeof(d->instance));
cs = auth_dat.checksum + 1;
{
@@ -213,15 +213,15 @@ mk_auth(struct krb4_data *d, KTEXT adat,
CREDENTIALS cred;
char sname[SNAME_SZ], inst[INST_SZ], realm[REALM_SZ];
strcpy_truncate(sname, service, sizeof(sname));
strcpy_truncate(inst, krb_get_phost(host), sizeof(inst));
strcpy_truncate(realm, krb_realmofhost(host), sizeof(realm));
strlcpy(sname, service, sizeof(sname));
strlcpy(inst, krb_get_phost(host), sizeof(inst));
strlcpy(realm, krb_realmofhost(host), sizeof(realm));
ret = krb_mk_req(adat, sname, inst, realm, checksum);
if(ret)
return ret;
strcpy_truncate(sname, service, sizeof(sname));
strcpy_truncate(inst, krb_get_phost(host), sizeof(inst));
strcpy_truncate(realm, krb_realmofhost(host), sizeof(realm));
strlcpy(sname, service, sizeof(sname));
strlcpy(inst, krb_get_phost(host), sizeof(inst));
strlcpy(realm, krb_realmofhost(host), sizeof(realm));
ret = krb_get_cred(sname, inst, realm, &cred);
memmove(&d->key, &cred.session, sizeof(des_cblock));
des_key_sched(&d->key, d->schedule);

View File

@@ -107,7 +107,7 @@ main(int argc, char **argv)
*/
pw = k_getpwuid(getuid());
if (pw != NULL) {
strcpy_truncate(homedir, pw->pw_dir, sizeof(homedir));
strlcpy(homedir, pw->pw_dir, sizeof(homedir));
home = homedir;
}
if (argc > 0) {
@@ -246,7 +246,7 @@ cmdscanner(int top)
p = readline("ftp> ");
if(p == NULL)
quit(0, 0);
strcpy_truncate(line, p, sizeof(line));
strlcpy(line, p, sizeof(line));
add_history(p);
free(p);
} else{

View File

@@ -77,7 +77,7 @@ guess_domain (char *hostname, size_t sz)
char **aliases;
if (gethostname (hostname, sz) < 0) {
strcpy_truncate (hostname, "", sz);
strlcpy (hostname, "", sz);
return "";
}
dot = strchr (hostname, '.');
@@ -90,13 +90,13 @@ guess_domain (char *hostname, size_t sz)
dot = strchr (he->h_name, '.');
if (dot != NULL) {
strcpy_truncate (hostname, he->h_name, sz);
strlcpy (hostname, he->h_name, sz);
return dot + 1;
}
for (aliases = he->h_aliases; (a = *aliases) != NULL; ++aliases) {
dot = strchr (a, '.');
if (dot != NULL) {
strcpy_truncate (hostname, a, sz);
strlcpy (hostname, a, sz);
return dot + 1;
}
}

View File

@@ -1023,7 +1023,7 @@ ftpd_getline(char *s, int n)
cs = s;
/* tmpline may contain saved command from urgent mode interruption */
if(ftp_command){
strcpy_truncate(s, ftp_command, n);
strlcpy(s, ftp_command, n);
if (debug)
syslog(LOG_DEBUG, "command: %s", s);
#ifdef XXX
@@ -1362,7 +1362,7 @@ help(struct tab *ctab, char *s)
columns = 1;
lines = (NCMDS + columns - 1) / columns;
for (i = 0; i < lines; i++) {
strcpy_truncate (buf, " ", sizeof(buf));
strlcpy (buf, " ", sizeof(buf));
for (j = 0; j < columns; j++) {
c = ctab + j * lines + i;
snprintf (buf + strlen(buf),
@@ -1374,7 +1374,7 @@ help(struct tab *ctab, char *s)
break;
w = strlen(c->name) + 1;
while (w < width) {
strcat_truncate (buf,
strlcat (buf,
" ",
sizeof(buf));
w++;

View File

@@ -153,7 +153,7 @@ curdir(void)
if (getcwd(path, sizeof(path)-1) == NULL)
return ("");
if (path[1] != '\0') /* special case for root dir. */
strcat_truncate(path, "/", sizeof(path));
strlcat(path, "/", sizeof(path));
/* For guest account, skip / since it's chrooted */
return (guest ? path+1 : path);
}
@@ -526,7 +526,7 @@ user(char *name)
if (inet_ntop (his_addr->sa_family,
socket_get_address(his_addr),
data_addr, sizeof(data_addr)) == NULL)
strcpy_truncate (data_addr, "unknown address",
strlcpy (data_addr, "unknown address",
sizeof(data_addr));
syslog(LOG_NOTICE,
@@ -556,7 +556,7 @@ user(char *name)
socket_get_address(his_addr),
data_addr,
sizeof(data_addr)) == NULL)
strcpy_truncate (data_addr,
strlcpy (data_addr,
"unknown address",
sizeof(data_addr));
@@ -571,7 +571,7 @@ user(char *name)
}
}
if (logging)
strcpy_truncate(curname, name, sizeof(curname));
strlcpy(curname, name, sizeof(curname));
if(sec_complete) {
if(sec_userok(name) == 0)
do_login(232, name);
@@ -786,7 +786,7 @@ int do_login(int code, char *passwd)
if (inet_ntop (his_addr->sa_family,
socket_get_address(his_addr),
data_addr, sizeof(data_addr)) == NULL)
strcpy_truncate (data_addr, "unknown address",
strlcpy (data_addr, "unknown address",
sizeof(data_addr));
syslog(LOG_INFO, "ANONYMOUS FTP LOGIN FROM %s(%s), %s",
@@ -807,7 +807,7 @@ int do_login(int code, char *passwd)
if (inet_ntop (his_addr->sa_family,
socket_get_address(his_addr),
data_addr, sizeof(data_addr)) == NULL)
strcpy_truncate (data_addr, "unknown address",
strlcpy (data_addr, "unknown address",
sizeof(data_addr));
syslog(LOG_INFO, "FTP LOGIN FROM %s(%s) as %s",
@@ -898,7 +898,7 @@ pass(char *passwd)
if (inet_ntop (his_addr->sa_family,
socket_get_address(his_addr),
data_addr, sizeof(data_addr)) == NULL)
strcpy_truncate (data_addr, "unknown address",
strlcpy (data_addr, "unknown address",
sizeof(data_addr));
reply(530, "Login incorrect.");
@@ -1242,7 +1242,7 @@ dataconn(char *name, off_t size, char *mode)
if (inet_ntop (data_source->sa_family,
socket_get_address(data_source),
data_addr, sizeof(data_addr)) == NULL)
strcpy_truncate (data_addr, "unknown address",
strlcpy (data_addr, "unknown address",
sizeof(data_addr));
reply(425, "Can't create data socket (%s,%d): %s.",
@@ -1781,7 +1781,7 @@ dolog(struct sockaddr *sa)
if (inet_ntop (his_addr->sa_family,
socket_get_address(his_addr),
data_addr, sizeof(data_addr)) == NULL)
strcpy_truncate (data_addr, "unknown address",
strlcpy (data_addr, "unknown address",
sizeof(data_addr));

View File

@@ -85,7 +85,7 @@ store_ticket(KTEXT cip)
return(INTK_BADPW);
/* extract server's name */
strcpy_truncate(sp.name, ptr, sizeof(sp.name));
strlcpy(sp.name, ptr, sizeof(sp.name));
ptr += len + 1;
left -= len + 1;
@@ -94,7 +94,7 @@ store_ticket(KTEXT cip)
return(INTK_BADPW);
/* extract server's instance */
strcpy_truncate(sp.instance, ptr, sizeof(sp.instance));
strlcpy(sp.instance, ptr, sizeof(sp.instance));
ptr += len + 1;
left -= len + 1;
@@ -103,7 +103,7 @@ store_ticket(KTEXT cip)
return(INTK_BADPW);
/* extract server's realm */
strcpy_truncate(sp.realm, ptr, sizeof(sp.realm));
strlcpy(sp.realm, ptr, sizeof(sp.realm));
ptr += len + 1;
left -= len + 1;
@@ -304,12 +304,12 @@ klist(void)
" Issued", " Expires", " Principal (kvno)");
header = 0;
}
strcpy_truncate(buf1, short_date(c.issue_date), sizeof(buf1));
strlcpy(buf1, short_date(c.issue_date), sizeof(buf1));
c.issue_date = krb_life_to_time(c.issue_date, c.lifetime);
if (time(0) < (unsigned long) c.issue_date)
strcpy_truncate(buf2, short_date(c.issue_date), sizeof(buf2));
strlcpy(buf2, short_date(c.issue_date), sizeof(buf2));
else
strcpy_truncate(buf2, ">>> Expired <<< ", sizeof(buf2));
strlcpy(buf2, ">>> Expired <<< ", sizeof(buf2));
lreply(200, "%s %s %s (%d)", buf1, buf2,
krb_unparse_name_long(c.service, c.instance, c.realm), c.kvno);
}

View File

@@ -89,10 +89,10 @@ ftp_rooted(const char *path)
if(!home[0])
if((pwd = k_getpwnam("ftp")))
strcpy_truncate(home, pwd->pw_dir, sizeof(home));
strlcpy(home, pwd->pw_dir, sizeof(home));
snprintf(newpath, sizeof(newpath), "%s/%s", home, path);
if(access(newpath, X_OK))
strcpy_truncate(newpath, path, sizeof(newpath));
strlcpy(newpath, path, sizeof(newpath));
return newpath;
}

View File

@@ -416,7 +416,7 @@ create_and_write_cookie (char *xauthfile,
auth.data = (char*)cookie;
des_rand_data (cookie, cookie_sz);
strcpy_truncate(xauthfile, "/tmp/AXXXXXX", xauthfile_size);
strlcpy(xauthfile, "/tmp/AXXXXXX", xauthfile_size);
fd = mkstemp(xauthfile);
if(fd < 0) {
saved_errno = errno;

View File

@@ -89,7 +89,7 @@ renew (int argc, char **argv, OtpAlgorithm *alg, char *user)
newctx.alg = alg;
newctx.user = user;
newctx.n = atoi (argv[0]);
strcpy_truncate (newctx.seed, argv[1], sizeof(newctx.seed));
strlcpy (newctx.seed, argv[1], sizeof(newctx.seed));
strlwr(newctx.seed);
snprintf (prompt, sizeof(prompt),
"[ otp-%s %u %s ]",
@@ -155,7 +155,7 @@ set (int argc, char **argv, OtpAlgorithm *alg, char *user)
err (1, "out of memory");
ctx.n = atoi (argv[0]);
strcpy_truncate (ctx.seed, argv[1], sizeof(ctx.seed));
strlcpy (ctx.seed, argv[1], sizeof(ctx.seed));
strlwr(ctx.seed);
do {
if (des_read_pw_string (pw, sizeof(pw), "Pass-phrase: ", 1))

View File

@@ -56,7 +56,7 @@ loop(int s)
if(FD_ISSET(0, &fds)){
fgets(cmd, sizeof(cmd), stdin);
cmd[strlen(cmd) - 1] = '\0';
strcat_truncate (cmd, "\r\n", sizeof(cmd));
strlcat (cmd, "\r\n", sizeof(cmd));
write(s, cmd, strlen(cmd));
}
if(FD_ISSET(s, &fds)){

View File

@@ -73,7 +73,7 @@ pop_dropcopy(POP *p, struct passwd *pwp)
* running as root.
*/
strcpy_truncate(template, POP_TMPDROP, sizeof(template));
strlcpy(template, POP_TMPDROP, sizeof(template));
if ((tf_fd = mkstemp(template)) < 0 ||
(tf = fdopen(tf_fd, "w+")) == NULL) {
pop_log(p,POP_PRIORITY,

View File

@@ -196,7 +196,7 @@ pop_dropinfo(POP *p)
"Msg %d at offset %ld being added to list",
mp->number, mp->offset);
#endif /* DEBUG */
}else if(in_header)
} else if(in_header)
parse_header(mp, buffer);
blank_line = (strncmp(buffer, "\n", nchar) == 0);
if(blank_line) {

View File

@@ -49,7 +49,7 @@ pop_get_command(POP *p, char *mp)
/* Save a copy of the original client line */
#ifdef DEBUG
if(p->debug) strcpy_truncate (buf, mp, sizeof(buf));
if(p->debug) strlcpy (buf, mp, sizeof(buf));
#endif /* DEBUG */
/* Parse the message into the parameter array */

View File

@@ -319,7 +319,7 @@ pop_init(POP *p,int argcount,char **argmessage)
if (ch == NULL){
pop_log(p,POP_PRIORITY,
"Unable to get canonical name of client, err = %d",error);
strcpy_truncate (p->client, p->ipaddr, sizeof(p->client));
strlcpy (p->client, p->ipaddr, sizeof(p->client));
}
/* Save the cannonical name of the client host in
the POP parameter block */
@@ -339,12 +339,12 @@ pop_init(POP *p,int argcount,char **argmessage)
pop_log(p,POP_PRIORITY,
"Client at \"%s\" resolves to an unknown host name \"%s\"",
p->ipaddr,ch->h_name);
strcpy_truncate (p->client, p->ipaddr, sizeof(p->client));
strlcpy (p->client, p->ipaddr, sizeof(p->client));
}
else {
/* Save the host name (the previous value was
destroyed by gethostbyname) */
strcpy_truncate (p->client, ch->h_name, sizeof(p->client));
strlcpy (p->client, ch->h_name, sizeof(p->client));
/* Look for the client's IP address in the list returned
for its name */
@@ -358,7 +358,7 @@ pop_init(POP *p,int argcount,char **argmessage)
pop_log (p,POP_PRIORITY,
"Client address \"%s\" not listed for its host name \"%s\"",
p->ipaddr,ch->h_name);
strcpy_truncate (p->client, p->ipaddr, sizeof(p->client));
strlcpy (p->client, p->ipaddr, sizeof(p->client));
}
}
freehostent (ch_again);

View File

@@ -46,7 +46,7 @@ pop_msg(POP *p, int stat, char *format, ...)
pop_log(p,POP_PRIORITY,"%s",message);
/* Append the <CR><LF> */
strcat_truncate(message, "\r\n", sizeof(message));
strlcat(message, "\r\n", sizeof(message));
/* Send the message to the client */
fputs(message, p->output);

View File

@@ -16,7 +16,7 @@ pop_user (POP *p)
{
char ss[256];
strcpy_truncate(p->user, p->pop_parm[1], sizeof(p->user));
strlcpy(p->user, p->pop_parm[1], sizeof(p->user));
#ifdef OTP
if (otp_challenge (&p->otp_ctx, p->user, ss, sizeof(ss)) == 0) {

View File

@@ -1,3 +1,8 @@
1999-09-16 Assar Westerlund <assar@sics.se>
* telnet/commands.c: revert 1.54, get_default_username should DTRT
now
1999-09-05 Assar Westerlund <assar@sics.se>
* telnetd/utility.c (ttloop): make it return 1 if interrupted by a

View File

@@ -180,7 +180,7 @@ kerberos4_send(char *name, Authenticator *ap)
memset(instance, 0, sizeof(instance));
strcpy_truncate (instance,
strlcpy (instance,
krb_get_phost(RemoteHostName),
INST_SZ);
@@ -521,7 +521,7 @@ kerberos4_status(Authenticator *ap, char *name, size_t name_sz, int level)
return(level);
if (UserNameRequested && !kuserok(&adat, UserNameRequested)) {
strcpy_truncate(name, UserNameRequested, name_sz);
strlcpy(name, UserNameRequested, name_sz);
return(AUTH_VALID);
} else
return(AUTH_USER);
@@ -540,11 +540,11 @@ kerberos4_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
switch(data[3]) {
case KRB_REJECT: /* Rejected (reason might follow) */
strcpy_truncate((char *)buf, " REJECT ", buflen);
strlcpy((char *)buf, " REJECT ", buflen);
goto common;
case KRB_ACCEPT: /* Accepted (name might follow) */
strcpy_truncate((char *)buf, " ACCEPT ", buflen);
strlcpy((char *)buf, " ACCEPT ", buflen);
common:
BUMP(buf, buflen);
if (cnt <= 4)
@@ -557,15 +557,15 @@ kerberos4_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
break;
case KRB_AUTH: /* Authentication data follows */
strcpy_truncate((char *)buf, " AUTH", buflen);
strlcpy((char *)buf, " AUTH", buflen);
goto common2;
case KRB_CHALLENGE:
strcpy_truncate((char *)buf, " CHALLENGE", buflen);
strlcpy((char *)buf, " CHALLENGE", buflen);
goto common2;
case KRB_RESPONSE:
strcpy_truncate((char *)buf, " RESPONSE", buflen);
strlcpy((char *)buf, " RESPONSE", buflen);
goto common2;
default:

View File

@@ -587,7 +587,7 @@ kerberos5_status(Authenticator *ap, char *name, size_t name_sz, int level)
ticket->client,
UserNameRequested))
{
strcpy_truncate(name, UserNameRequested, name_sz);
strlcpy(name, UserNameRequested, name_sz);
return(AUTH_VALID);
} else
return(AUTH_USER);
@@ -606,11 +606,11 @@ kerberos5_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
switch(data[3]) {
case KRB_REJECT: /* Rejected (reason might follow) */
strcpy_truncate((char *)buf, " REJECT ", buflen);
strlcpy((char *)buf, " REJECT ", buflen);
goto common;
case KRB_ACCEPT: /* Accepted (name might follow) */
strcpy_truncate((char *)buf, " ACCEPT ", buflen);
strlcpy((char *)buf, " ACCEPT ", buflen);
common:
BUMP(buf, buflen);
if (cnt <= 4)
@@ -624,24 +624,24 @@ kerberos5_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
case KRB_AUTH: /* Authentication data follows */
strcpy_truncate((char *)buf, " AUTH", buflen);
strlcpy((char *)buf, " AUTH", buflen);
goto common2;
case KRB_RESPONSE:
strcpy_truncate((char *)buf, " RESPONSE", buflen);
strlcpy((char *)buf, " RESPONSE", buflen);
goto common2;
case KRB_FORWARD: /* Forwarded credentials follow */
strcpy_truncate((char *)buf, " FORWARD", buflen);
strlcpy((char *)buf, " FORWARD", buflen);
goto common2;
case KRB_FORWARD_ACCEPT: /* Forwarded credentials accepted */
strcpy_truncate((char *)buf, " FORWARD_ACCEPT", buflen);
strlcpy((char *)buf, " FORWARD_ACCEPT", buflen);
goto common2;
case KRB_FORWARD_REJECT: /* Forwarded credentials rejected */
/* (reason might follow) */
strcpy_truncate((char *)buf, " FORWARD_REJECT", buflen);
strlcpy((char *)buf, " FORWARD_REJECT", buflen);
goto common2;
default:

View File

@@ -308,7 +308,7 @@ krb4encpwd_reply(ap, data, cnt)
des_read_pw_string(user_passwd, sizeof(user_passwd)-1, "Password: ", 0);
UserPassword = user_passwd;
Challenge = challenge;
strcpy_truncate(instance, RemoteHostName, sizeof(instance));
strlcpy(instance, RemoteHostName, sizeof(instance));
if ((cp = strchr(instance, '.')) != 0) *cp = '\0';
if (r = krb_mk_encpwd_req(&krb_token, KRB_SERVICE_NAME, instance, realm, Challenge, UserNameRequested, user_passwd)) {
@@ -338,7 +338,7 @@ krb4encpwd_status(ap, name, name_sz, level)
return(level);
if (UserNameRequested && passwdok(UserNameRequested, UserPassword)) {
strcpy_truncate(name, UserNameRequested, name_sz);
strlcpy(name, UserNameRequested, name_sz);
return(AUTH_VALID);
} else {
return(AUTH_USER);
@@ -360,11 +360,11 @@ krb4encpwd_printsub(data, cnt, buf, buflen)
switch(data[3]) {
case KRB4_ENCPWD_REJECT: /* Rejected (reason might follow) */
strcpy_truncate((char *)buf, " REJECT ", buflen);
strlcpy((char *)buf, " REJECT ", buflen);
goto common;
case KRB4_ENCPWD_ACCEPT: /* Accepted (name might follow) */
strcpy_truncate((char *)buf, " ACCEPT ", buflen);
strlcpy((char *)buf, " ACCEPT ", buflen);
common:
BUMP(buf, buflen);
if (cnt <= 4)
@@ -377,15 +377,15 @@ krb4encpwd_printsub(data, cnt, buf, buflen)
break;
case KRB4_ENCPWD_AUTH: /* Authentication data follows */
strcpy_truncate((char *)buf, " AUTH", buflen);
strlcpy((char *)buf, " AUTH", buflen);
goto common2;
case KRB4_ENCPWD_CHALLENGE:
strcpy_truncate((char *)buf, " CHALLENGE", buflen);
strlcpy((char *)buf, " CHALLENGE", buflen);
goto common2;
case KRB4_ENCPWD_ACK:
strcpy_truncate((char *)buf, " ACK", buflen);
strlcpy((char *)buf, " ACK", buflen);
goto common2;
default:

View File

@@ -260,7 +260,7 @@ rsaencpwd_is(ap, data, cnt)
snprintf(challenge, sizeof(challenge), "%x", now);
challenge_len = strlen(challenge);
} else {
strcpy_truncate(challenge, "randchal", sizeof(challenge));
strlcpy(challenge, "randchal", sizeof(challenge));
challenge_len = 8;
}
@@ -392,7 +392,7 @@ rsaencpwd_status(ap, name, name_sz, level)
return(level);
if (UserNameRequested && rsaencpwd_passwdok(UserNameRequested, UserPassword)) {
strcpy_truncate(name, UserNameRequested, name_sz);
strlcpy(name, UserNameRequested, name_sz);
return(AUTH_VALID);
} else {
return(AUTH_USER);
@@ -414,11 +414,11 @@ rsaencpwd_printsub(data, cnt, buf, buflen)
switch(data[3]) {
case RSA_ENCPWD_REJECT: /* Rejected (reason might follow) */
strcpy_truncate((char *)buf, " REJECT ", buflen);
strlcpy((char *)buf, " REJECT ", buflen);
goto common;
case RSA_ENCPWD_ACCEPT: /* Accepted (name might follow) */
strcpy_truncate((char *)buf, " ACCEPT ", buflen);
strlcpy((char *)buf, " ACCEPT ", buflen);
common:
BUMP(buf, buflen);
if (cnt <= 4)
@@ -431,11 +431,11 @@ rsaencpwd_printsub(data, cnt, buf, buflen)
break;
case RSA_ENCPWD_AUTH: /* Authentication data follows */
strcpy_truncate((char *)buf, " AUTH", buflen);
strlcpy((char *)buf, " AUTH", buflen);
goto common2;
case RSA_ENCPWD_CHALLENGEKEY:
strcpy_truncate((char *)buf, " CHALLENGEKEY", buflen);
strlcpy((char *)buf, " CHALLENGEKEY", buflen);
goto common2;
default:

View File

@@ -514,7 +514,7 @@ spx_status(ap, name, name_sz, level)
&acl_file_buffer);
if (major_status == GSS_S_COMPLETE) {
strcpy_truncate(name, UserNameRequested, name_sz);
strlcpy(name, UserNameRequested, name_sz);
return(AUTH_VALID);
} else {
return(AUTH_USER);
@@ -537,11 +537,11 @@ spx_printsub(data, cnt, buf, buflen)
switch(data[3]) {
case SPX_REJECT: /* Rejected (reason might follow) */
strcpy_truncate((char *)buf, " REJECT ", buflen);
strlcpy((char *)buf, " REJECT ", buflen);
goto common;
case SPX_ACCEPT: /* Accepted (name might follow) */
strcpy_truncate((char *)buf, " ACCEPT ", buflen);
strlcpy((char *)buf, " ACCEPT ", buflen);
common:
BUMP(buf, buflen);
if (cnt <= 4)
@@ -554,7 +554,7 @@ spx_printsub(data, cnt, buf, buflen)
break;
case SPX_AUTH: /* Authentication data follows */
strcpy_truncate((char *)buf, " AUTH", buflen);
strlcpy((char *)buf, " AUTH", buflen);
goto common2;
default:

View File

@@ -82,7 +82,7 @@ telnet_gets(char *prompt, char *result, int length, int echo)
printf("%s", prompt);
res = fgets(result, length, stdin);
} else if ((res = getpass(prompt))) {
strcpy_truncate(result, res, length);
strlcpy(result, res, length);
res = result;
}
TerminalNewMode(om);

View File

@@ -67,7 +67,7 @@ makeargv()
cp = line;
if (*cp == '!') { /* Special case shell escape */
/* save for shell command */
strcpy_truncate(saveline, line, sizeof(saveline));
strlcpy(saveline, line, sizeof(saveline));
*argp++ = "!"; /* No room in string to get this */
margc++;
cp++;
@@ -1583,7 +1583,7 @@ env_init(void)
if (strchr(hbuf, '.') == 0) {
struct hostent *he = roken_gethostbyname(hbuf);
if (he != NULL)
strcpy_truncate(hbuf, he->h_name, 256);
strlcpy(hbuf, he->h_name, 256);
}
asprintf (&cp, "%s%s", hbuf, cp2);
@@ -1981,7 +1981,7 @@ cmdrc(char *m1, char *m2)
if (skiprc)
return;
strcpy_truncate(m1save, m1, sizeof(m1save));
strlcpy(m1save, m1, sizeof(m1save));
m1 = m1save;
if (rcname[0] == 0) {
@@ -2075,7 +2075,7 @@ tn(int argc, char **argv)
return 0;
}
if (argc < 2) {
strcpy_truncate(line, "open ", sizeof(line));
strlcpy(line, "open ", sizeof(line));
printf("(to) ");
fgets(&line[strlen(line)], sizeof(line) - strlen(line), stdin);
makeargv();
@@ -2146,7 +2146,7 @@ tn(int argc, char **argv)
sin6.sin6_family = family = AF_INET6;
sa = (struct sockaddr *)&sin6;
sa_size = sizeof(sin6);
strcpy_truncate(_hostname, hostp, sizeof(_hostname));
strlcpy(_hostname, hostp, sizeof(_hostname));
hostname =_hostname;
} else
#endif
@@ -2154,7 +2154,7 @@ tn(int argc, char **argv)
sin.sin_family = family = AF_INET;
sa = (struct sockaddr *)&sin;
sa_size = sizeof(sin);
strcpy_truncate(_hostname, hostp, sizeof(_hostname));
strlcpy(_hostname, hostp, sizeof(_hostname));
hostname = _hostname;
} else {
#ifdef HAVE_GETHOSTBYNAME2
@@ -2167,7 +2167,7 @@ tn(int argc, char **argv)
host = roken_gethostbyname(hostp);
#endif
if (host) {
strcpy_truncate(_hostname, host->h_name, sizeof(_hostname));
strlcpy(_hostname, host->h_name, sizeof(_hostname));
family = host->h_addrtype;
addr_list = host->h_addr_list;

View File

@@ -263,7 +263,7 @@ main(int argc, char **argv)
extern char *dest_realm, dst_realm_buf[];
extern int dst_realm_sz;
dest_realm = dst_realm_buf;
strcpy_truncate(dest_realm, optarg, dst_realm_sz);
strlcpy(dest_realm, optarg, dst_realm_sz);
}
#else
fprintf(stderr,

View File

@@ -82,13 +82,13 @@ SetNetTrace(char *file)
if (file && (strcmp(file, "-") != 0)) {
NetTrace = fopen(file, "w");
if (NetTrace) {
strcpy_truncate(NetTraceFile, file, sizeof(NetTraceFile));
strlcpy(NetTraceFile, file, sizeof(NetTraceFile));
return;
}
fprintf(stderr, "Cannot open %s.\n", file);
}
NetTrace = stdout;
strcpy_truncate(NetTraceFile, "(standard output)", sizeof(NetTraceFile));
strlcpy(NetTraceFile, "(standard output)", sizeof(NetTraceFile));
}
void

View File

@@ -388,7 +388,7 @@ int getpty(int *ptynum)
p = _getpty(&master, O_RDWR, 0600, 1);
if(p == NULL)
return -1;
strcpy_truncate(line, p, sizeof(Xline));
strlcpy(line, p, sizeof(Xline));
return master;
#else
@@ -420,7 +420,7 @@ int getpty(int *ptynum)
#ifdef HAVE_UNLOCKPT
unlockpt(p);
#endif
strcpy_truncate(line, ptsname(p), sizeof(Xline));
strlcpy(line, ptsname(p), sizeof(Xline));
really_stream = 1;
return p;
}

View File

@@ -594,12 +594,12 @@ getterminaltype(char *name, size_t name_sz)
* we have to just go with what we (might) have already gotten.
*/
if (his_state_is_will(TELOPT_TTYPE) && !terminaltypeok(terminaltype)) {
strcpy_truncate(first, terminaltype, sizeof(first));
strlcpy(first, terminaltype, sizeof(first));
for(;;) {
/*
* Save the unknown name, and request the next name.
*/
strcpy_truncate(last, terminaltype, sizeof(last));
strlcpy(last, terminaltype, sizeof(last));
_gettermname();
if (terminaltypeok(terminaltype))
break;
@@ -731,7 +731,7 @@ Please contact your net administrator");
tmp = inet_ntop(af, addr, host_addr, sizeof(host_addr));
if (tmp == NULL)
strcpy_truncate (host_addr, "unknown address", sizeof(host_addr));
strlcpy (host_addr, "unknown address", sizeof(host_addr));
if (host == NULL)
host = host_addr;
@@ -740,7 +740,7 @@ Please contact your net administrator");
* We must make a copy because Kerberos is probably going
* to also do a gethost* and overwrite the static data...
*/
strcpy_truncate(remote_host_name, host, sizeof(remote_host_name));
strlcpy(remote_host_name, host, sizeof(remote_host_name));
if (hp != NULL)
freehostent (hp);
host = remote_host_name;
@@ -762,7 +762,7 @@ Please contact your net administrator");
* If hostname still doesn't fit utmp, use ipaddr.
*/
if (strlen(remote_host_name) > abs(utmp_len))
strcpy_truncate(remote_host_name,
strlcpy(remote_host_name,
host_addr,
sizeof(remote_host_name));

View File

@@ -400,7 +400,7 @@ void edithost(char *pat, char *host)
pat++;
}
if (*host)
strcpy_truncate (res, host,
strlcpy (res, host,
sizeof editedhost - (res - editedhost));
else
*res = '\0';

View File

@@ -251,8 +251,8 @@ init_words (int argc, char **argv)
errx (1, "cannot allocate memory for message");
appres.text[0] = 0;
for(; i < j; i++){
strcat_truncate(appres.text, argv[i], len);
strcat_truncate(appres.text, " ", len);
strlcat(appres.text, argv[i], len);
strlcat(appres.text, " ", len);
}
}
}
@@ -799,7 +799,7 @@ talk(int force_erase)
XSetForeground(dpy, gc, White);
talking = 1;
walk(FRONT);
strcpy_truncate (buf, words, sizeof(buf));
strlcpy (buf, words, sizeof(buf));
p = buf;
/* possibly avoid a lot of work here
@@ -834,7 +834,7 @@ talk(int force_erase)
if ((w = XTextWidth(font, p, p2 - p)) > width)
width = w;
total += p2 - p; /* total chars; count to determine reading time */
strcpy_truncate(args[height], p, sizeof(args[height]));
strlcpy(args[height], p, sizeof(args[height]));
if (height == MAXLINES - 1) {
puts("Message too long!");
break;
@@ -929,14 +929,14 @@ main (int argc, char **argv)
struct passwd *pw;
if (!(pw = k_getpwuid(0)))
errx (1, "can't get root's passwd!");
strcpy_truncate(root_cpass, pw->pw_passwd, sizeof(root_cpass));
strlcpy(root_cpass, pw->pw_passwd, sizeof(root_cpass));
if (!(pw = k_getpwuid(getuid())))
errx (1, "Can't get your password entry!");
strcpy_truncate(user_cpass, pw->pw_passwd, sizeof(user_cpass));
strlcpy(user_cpass, pw->pw_passwd, sizeof(user_cpass));
setuid(getuid());
/* Now we're no longer running setuid root. */
strcpy_truncate(login, pw->pw_name, sizeof(login));
strlcpy(login, pw->pw_name, sizeof(login));
}
srand(getpid());

View File

@@ -150,10 +150,10 @@ auth_su(pam_handle_t *pamh, int flags, char *user, struct pam_conv *conv)
pw = getpwuid(getuid());
if(strcmp(user, "root") == 0){
strcpy_truncate(pr.name, pw->pw_name, sizeof(pr.name));
strcpy_truncate(pr.instance, "root", sizeof(pr.instance));
strlcpy(pr.name, pw->pw_name, sizeof(pr.name));
strlcpy(pr.instance, "root", sizeof(pr.instance));
}else{
strcpy_truncate(pr.name, user, sizeof(pr.name));
strlcpy(pr.name, user, sizeof(pr.name));
pr.instance[0] = 0;
}
pmsg = &msg;

View File

@@ -141,10 +141,10 @@ lex.c: $(srcdir)/lex.l
snprintf.c:
$(LN_S) $(srcdir)/../roken/snprintf.c .
strcat_truncate.c:
$(LN_S) $(srcdir)/../roken/strcat_truncate.c .
strlcat.c:
$(LN_S) $(srcdir)/../roken/strlcat.c .
strcpy_truncate.c:
$(LN_S) $(srcdir)/../roken/strcpy_truncate.c .
strlcpy.c:
$(LN_S) $(srcdir)/../roken/strlcpy.c .
.PHONY: all Wall install uninstall clean mostlyclean distclean realclean

View File

@@ -84,7 +84,7 @@ pwd_dialog(char *buf, int size)
switch(DialogBox(hInst,MAKEINTRESOURCE(IDD_PASSWD_DIALOG),wnd,pwd_dialog_proc))
{
case IDOK:
strcpy_truncate(buf, passwd, size);
strlcpy(buf, passwd, size);
memset (passwd, 0, sizeof(passwd));
return 0;
case IDCANCEL:

View File

@@ -41,9 +41,9 @@ LIB = $(LIBNAME).$(LIBEXT) $(AFS_EXTRA_LIBS)
SOURCES = afssys.c afskrb.c common.c afslib.c
EXTRA_SOURCE = issuid.c strcpy_truncate.c strcat_truncate.c
EXTRA_SOURCE = issuid.c strlcpy.c strlcat.c
EXTRA_OBJECT = issuid.o strcpy_truncate.o strcat_truncate.o
EXTRA_OBJECT = issuid.o strlcpy.o strlcat.o
OBJECTS = afssys.o afskrb.o common.o $(EXTRA_OBJECT) $(AFS_EXTRA_OBJS)
@@ -109,9 +109,9 @@ roken_rename.h:
issuid.c:
$(LN_S) $(srcdir)/../roken/issuid.c .
strcat_truncate.c:
$(LN_S) $(srcdir)/../roken/strcat_truncate.c .
strlcat.c:
$(LN_S) $(srcdir)/../roken/strlcat.c .
strcpy_truncate.c:
$(LN_S) $(srcdir)/../roken/strcpy_truncate.c .
strlcpy.c:
$(LN_S) $(srcdir)/../roken/strlcpy.c .

View File

@@ -77,7 +77,7 @@ try_aix(void)
* If we are root or running setuid don't trust AFSLIBPATH!
*/
if (getuid() != 0 && !issuid() && (p = getenv("AFSLIBPATH")) != NULL)
strcpy_truncate(path, p, sizeof(path));
strlcpy(path, p, sizeof(path));
else
snprintf(path, sizeof(path), "%s/afslib.so", LIBDIR);

View File

@@ -155,7 +155,7 @@ dns_find_cell(const char *cell, char *dbserver, size_t len)
struct resource_record *rr = r->head;
while(rr){
if(rr->type == T_AFSDB && rr->u.afsdb->preference == 1){
strcpy_truncate(dbserver,
strlcpy(dbserver,
rr->u.afsdb->domain,
len);
ok = 0;

View File

@@ -142,7 +142,7 @@ void *dlopen(const char *path, int mode)
if (errno == ENOEXEC) {
char *tmp[BUFSIZ/sizeof(char *)];
if (loadquery(L_GETMESSAGES, tmp, sizeof(tmp)) == -1)
strcpy_truncate(errbuf,
strlcpy(errbuf,
strerror(errno),
sizeof(errbuf));
else {
@@ -151,7 +151,7 @@ void *dlopen(const char *path, int mode)
caterr(*p);
}
} else
strcat_truncate(errbuf,
strlcat(errbuf,
strerror(errno),
sizeof(errbuf));
return NULL;
@@ -231,29 +231,29 @@ static void caterr(char *s)
p++;
switch(atoi(s)) {
case L_ERROR_TOOMANY:
strcat_truncate(errbuf, "to many errors", sizeof(errbuf));
strlcat(errbuf, "to many errors", sizeof(errbuf));
break;
case L_ERROR_NOLIB:
strcat_truncate(errbuf, "can't load library", sizeof(errbuf));
strcat_truncate(errbuf, p, sizeof(errbuf));
strlcat(errbuf, "can't load library", sizeof(errbuf));
strlcat(errbuf, p, sizeof(errbuf));
break;
case L_ERROR_UNDEF:
strcat_truncate(errbuf, "can't find symbol", sizeof(errbuf));
strcat_truncate(errbuf, p, sizeof(errbuf));
strlcat(errbuf, "can't find symbol", sizeof(errbuf));
strlcat(errbuf, p, sizeof(errbuf));
break;
case L_ERROR_RLDBAD:
strcat_truncate(errbuf, "bad RLD", sizeof(errbuf));
strcat_truncate(errbuf, p, sizeof(errbuf));
strlcat(errbuf, "bad RLD", sizeof(errbuf));
strlcat(errbuf, p, sizeof(errbuf));
break;
case L_ERROR_FORMAT:
strcat_truncate(errbuf, "bad exec format in", sizeof(errbuf));
strcat_truncate(errbuf, p, sizeof(errbuf));
strlcat(errbuf, "bad exec format in", sizeof(errbuf));
strlcat(errbuf, p, sizeof(errbuf));
break;
case L_ERROR_ERRNO:
strcat_truncate(errbuf, strerror(atoi(++p)), sizeof(errbuf));
strlcat(errbuf, strerror(atoi(++p)), sizeof(errbuf));
break;
default:
strcat_truncate(errbuf, s, sizeof(errbuf));
strlcat(errbuf, s, sizeof(errbuf));
break;
}
}
@@ -519,7 +519,7 @@ static int readExports(ModulePtr mp)
* must copy the first SYMNMLEN chars and make
* sure we have a zero byte at the end.
*/
strcpy_truncate (tmpsym, ls->l_name,
strlcpy (tmpsym, ls->l_name,
SYMNMLEN + 1);
symname = tmpsym;
}

View File

@@ -145,7 +145,7 @@ otp_get_internal (void *v, OtpContext *ctx, int lockp)
p += 4;
memcpy (ctx->key, p, OTPKEYSIZE);
p += OTPKEYSIZE;
strcpy_truncate (ctx->seed, p, sizeof(ctx->seed));
strlcpy (ctx->seed, p, sizeof(ctx->seed));
if (lockp)
return dbm_store (dbm, key, dat, DBM_REPLACE);
else

View File

@@ -88,7 +88,7 @@ otp_print_hex (OtpKey key, char *str, size_t sz)
void
otp_print_hex_extended (OtpKey key, char *str, size_t sz)
{
strcpy_truncate (str, OTP_HEXPREFIX, sz);
strlcpy (str, OTP_HEXPREFIX, sz);
otp_print_hex (key,
str + strlen(OTP_HEXPREFIX),
sz - strlen(OTP_HEXPREFIX));
@@ -97,7 +97,7 @@ otp_print_hex_extended (OtpKey key, char *str, size_t sz)
void
otp_print_stddict_extended (OtpKey key, char *str, size_t sz)
{
strcpy_truncate (str, OTP_WORDPREFIX, sz);
strlcpy (str, OTP_WORDPREFIX, sz);
otp_print_stddict (key,
str + strlen(OTP_WORDPREFIX),
sz - strlen(OTP_WORDPREFIX));