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

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@6985 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
1999-09-16 21:39:11 +00:00
parent bf75fac82a
commit d3f5d79294
15 changed files with 52 additions and 48 deletions

View File

@@ -1,3 +1,7 @@
1999-09-16 Assar Westerlund <assar@sics.se>
* configure.in: test for strlcpy, strlcat
1999-09-14 Assar Westerlund <assar@sics.se> 1999-09-14 Assar Westerlund <assar@sics.se>
* lib/krb5/init_creds_pw.c (krb5_get_init_creds_password): return * lib/krb5/init_creds_pw.c (krb5_get_init_creds_password): return

View File

@@ -279,7 +279,7 @@ proto (int sock, const char *service)
goto out; goto out;
} }
strcpy_truncate(krb5_tkfile,ccname,sizeof(krb5_tkfile)); strlcpy(krb5_tkfile,ccname,sizeof(krb5_tkfile));
syslog_and_cont("%s forwarded ticket to %s,%s", syslog_and_cont("%s forwarded ticket to %s,%s",
name, name,
(char *)(remotename.data),ccname); (char *)(remotename.data),ccname);

View File

@@ -467,7 +467,7 @@ do_login(struct passwd *pwd, char *tty, char *ttyn)
/* all kinds of different magic */ /* all kinds of different magic */
#ifdef HAVE_SHADOW_H #ifdef HAVE_SHADOW_H
check_shadow(pwd,sp); check_shadow(pwd, sp);
#endif #endif
if(do_osfc2_magic(pwd->pw_uid)) if(do_osfc2_magic(pwd->pw_uid))
@@ -637,7 +637,7 @@ main(int argc, char **argv)
if(*argv){ if(*argv){
if(strchr(*argv, '=') == NULL && strcmp(*argv, "-") != 0){ if(strchr(*argv, '=') == NULL && strcmp(*argv, "-") != 0){
strcpy_truncate (username, *argv, sizeof(username)); strlcpy (username, *argv, sizeof(username));
ask = 0; ask = 0;
} }
} }

View File

@@ -368,7 +368,7 @@ recv_krb5_auth (int s, u_char *buf,
if (inet_ntop (thataddr->sa_family, if (inet_ntop (thataddr->sa_family,
socket_get_address (thataddr), socket_get_address (thataddr),
addr_str, sizeof(addr_str)) == NULL) addr_str, sizeof(addr_str)) == NULL)
strcpy_truncate (addr_str, "unknown address", strlcpy (addr_str, "unknown address",
sizeof(addr_str)); sizeof(addr_str));
syslog(LOG_INFO|LOG_AUTH, syslog(LOG_INFO|LOG_AUTH,

View File

@@ -116,7 +116,7 @@ add_one_principal (const char *name,
if(rand_key) { if(rand_key) {
princ.attributes |= KRB5_KDB_DISALLOW_ALL_TIX; princ.attributes |= KRB5_KDB_DISALLOW_ALL_TIX;
mask |= KADM5_ATTRIBUTES; mask |= KADM5_ATTRIBUTES;
strcpy_truncate (pwbuf, "hemlig", sizeof(pwbuf)); strlcpy (pwbuf, "hemlig", sizeof(pwbuf));
password = pwbuf; password = pwbuf;
} else if (rand_password) { } else if (rand_password) {
random_password (pwbuf, sizeof(pwbuf)); random_password (pwbuf, sizeof(pwbuf));

View File

@@ -74,7 +74,7 @@ random_password(char *pw, size_t len)
"abcdefghijklmnopqrstuvwxyz", 7, "abcdefghijklmnopqrstuvwxyz", 7,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ", 2, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 2,
"@$%&*()-+=:,/<>1234567890", 1); "@$%&*()-+=:,/<>1234567890", 1);
strcpy_truncate(pw, pass, len); strlcpy(pw, pass, len);
memset(pass, 0, strlen(pass)); memset(pass, 0, strlen(pass));
free(pass); free(pass);
#endif #endif

View File

@@ -85,12 +85,12 @@ ret_vals(krb5_storage *sp, Kadm_vals *vals)
switch(field) { switch(field) {
case KADM_NAME: case KADM_NAME:
krb5_ret_stringz(sp, &tmp_string); krb5_ret_stringz(sp, &tmp_string);
strcpy_truncate(vals->name, tmp_string, sizeof(vals->name)); strlcpy(vals->name, tmp_string, sizeof(vals->name));
free(tmp_string); free(tmp_string);
break; break;
case KADM_INST: case KADM_INST:
krb5_ret_stringz(sp, &tmp_string); krb5_ret_stringz(sp, &tmp_string);
strcpy_truncate(vals->instance, tmp_string, strlcpy(vals->instance, tmp_string,
sizeof(vals->instance)); sizeof(vals->instance));
free(tmp_string); free(tmp_string);
break; break;
@@ -113,13 +113,13 @@ ret_vals(krb5_storage *sp, Kadm_vals *vals)
break; break;
case KADM_MODNAME: case KADM_MODNAME:
krb5_ret_stringz(sp, &tmp_string); krb5_ret_stringz(sp, &tmp_string);
strcpy_truncate(vals->mod_name, tmp_string, strlcpy(vals->mod_name, tmp_string,
sizeof(vals->mod_name)); sizeof(vals->mod_name));
free(tmp_string); free(tmp_string);
break; break;
case KADM_MODINST: case KADM_MODINST:
krb5_ret_stringz(sp, &tmp_string); krb5_ret_stringz(sp, &tmp_string);
strcpy_truncate(vals->mod_instance, tmp_string, strlcpy(vals->mod_instance, tmp_string,
sizeof(vals->mod_instance)); sizeof(vals->mod_instance));
free(tmp_string); free(tmp_string);
break; break;

View File

@@ -262,7 +262,7 @@ main(int argc, char **argv)
socket_get_address (sa), socket_get_address (sa),
addr_name, addr_name,
sizeof(addr_name)) == NULL) sizeof(addr_name)) == NULL)
strcpy_truncate (addr_name, "unknown address", strlcpy (addr_name, "unknown address",
sizeof(addr_name)); sizeof(addr_name));
krb5_log(context, fac, 0, "Connection from %s", addr_name); krb5_log(context, fac, 0, "Connection from %s", addr_name);

View File

@@ -318,13 +318,13 @@ display_tokens(int do_verbose)
cell = r; cell = r;
gettimeofday (&tv, NULL); gettimeofday (&tv, NULL);
strcpy_truncate (buf1, printable_time(ct.BeginTimestamp), strlcpy (buf1, printable_time(ct.BeginTimestamp),
sizeof(buf1)); sizeof(buf1));
if (do_verbose || tv.tv_sec < ct.EndTimestamp) if (do_verbose || tv.tv_sec < ct.EndTimestamp)
strcpy_truncate (buf2, printable_time(ct.EndTimestamp), strlcpy (buf2, printable_time(ct.EndTimestamp),
sizeof(buf2)); sizeof(buf2));
else else
strcpy_truncate (buf2, ">>> Expired <<<", sizeof(buf2)); strlcpy (buf2, ">>> Expired <<<", sizeof(buf2));
printf("%s %s ", buf1, buf2); printf("%s %s ", buf1, buf2);

View File

@@ -124,12 +124,12 @@ hdb_entry2string(krb5_context context, hdb_entry *ent, char **str)
ret = krb5_unparse_name(context, ent->principal, &p); ret = krb5_unparse_name(context, ent->principal, &p);
if(ret) if(ret)
return ret; return ret;
strcat_truncate(buf, p, sizeof(buf)); strlcat(buf, p, sizeof(buf));
strcat_truncate(buf, " ", sizeof(buf)); strlcat(buf, " ", sizeof(buf));
free(p); free(p);
/* --- kvno */ /* --- kvno */
asprintf(&p, "%d", ent->kvno); asprintf(&p, "%d", ent->kvno);
strcat_truncate(buf, p, sizeof(buf)); strlcat(buf, p, sizeof(buf));
free(p); free(p);
/* --- keys */ /* --- keys */
for(i = 0; i < ent->keys.len; i++){ for(i = 0; i < ent->keys.len; i++){
@@ -141,75 +141,75 @@ hdb_entry2string(krb5_context context, hdb_entry *ent, char **str)
else else
asprintf(&p, "::%d:", asprintf(&p, "::%d:",
ent->keys.val[i].key.keytype); ent->keys.val[i].key.keytype);
strcat_truncate(buf, p, sizeof(buf)); strlcat(buf, p, sizeof(buf));
free(p); free(p);
/* --- keydata */ /* --- keydata */
append_hex(buf, &ent->keys.val[i].key.keyvalue); append_hex(buf, &ent->keys.val[i].key.keyvalue);
strcat_truncate(buf, ":", sizeof(buf)); strlcat(buf, ":", sizeof(buf));
/* --- salt */ /* --- salt */
if(ent->keys.val[i].salt){ if(ent->keys.val[i].salt){
asprintf(&p, "%u/", ent->keys.val[i].salt->type); asprintf(&p, "%u/", ent->keys.val[i].salt->type);
strcat_truncate(buf, p, sizeof(buf)); strlcat(buf, p, sizeof(buf));
free(p); free(p);
append_hex(buf, &ent->keys.val[i].salt->salt); append_hex(buf, &ent->keys.val[i].salt->salt);
}else }else
strcat_truncate(buf, "-", sizeof(buf)); strlcat(buf, "-", sizeof(buf));
} }
strcat_truncate(buf, " ", sizeof(buf)); strlcat(buf, " ", sizeof(buf));
/* --- created by */ /* --- created by */
event2string(context, &ent->created_by, &p); event2string(context, &ent->created_by, &p);
strcat_truncate(buf, p, sizeof(buf)); strlcat(buf, p, sizeof(buf));
strcat_truncate(buf, " ", sizeof(buf)); strlcat(buf, " ", sizeof(buf));
free(p); free(p);
/* --- modified by */ /* --- modified by */
event2string(context, ent->modified_by, &p); event2string(context, ent->modified_by, &p);
strcat_truncate(buf, p, sizeof(buf)); strlcat(buf, p, sizeof(buf));
strcat_truncate(buf, " ", sizeof(buf)); strlcat(buf, " ", sizeof(buf));
free(p); free(p);
/* --- valid start */ /* --- valid start */
if(ent->valid_start) if(ent->valid_start)
strcat_truncate(buf, time2str(*ent->valid_start), sizeof(buf)); strlcat(buf, time2str(*ent->valid_start), sizeof(buf));
else else
strcat_truncate(buf, "-", sizeof(buf)); strlcat(buf, "-", sizeof(buf));
strcat_truncate(buf, " ", sizeof(buf)); strlcat(buf, " ", sizeof(buf));
/* --- valid end */ /* --- valid end */
if(ent->valid_end) if(ent->valid_end)
strcat_truncate(buf, time2str(*ent->valid_end), sizeof(buf)); strlcat(buf, time2str(*ent->valid_end), sizeof(buf));
else else
strcat_truncate(buf, "-", sizeof(buf)); strlcat(buf, "-", sizeof(buf));
strcat_truncate(buf, " ", sizeof(buf)); strlcat(buf, " ", sizeof(buf));
/* --- password ends */ /* --- password ends */
if(ent->pw_end) if(ent->pw_end)
strcat_truncate(buf, time2str(*ent->pw_end), sizeof(buf)); strlcat(buf, time2str(*ent->pw_end), sizeof(buf));
else else
strcat_truncate(buf, "-", sizeof(buf)); strlcat(buf, "-", sizeof(buf));
strcat_truncate(buf, " ", sizeof(buf)); strlcat(buf, " ", sizeof(buf));
/* --- max life */ /* --- max life */
if(ent->max_life){ if(ent->max_life){
asprintf(&p, "%d", *ent->max_life); asprintf(&p, "%d", *ent->max_life);
strcat_truncate(buf, p, sizeof(buf)); strlcat(buf, p, sizeof(buf));
free(p); free(p);
}else }else
strcat_truncate(buf, "-", sizeof(buf)); strlcat(buf, "-", sizeof(buf));
strcat_truncate(buf, " ", sizeof(buf)); strlcat(buf, " ", sizeof(buf));
/* --- max renewable life */ /* --- max renewable life */
if(ent->max_renew){ if(ent->max_renew){
asprintf(&p, "%d", *ent->max_renew); asprintf(&p, "%d", *ent->max_renew);
strcat_truncate(buf, p, sizeof(buf)); strlcat(buf, p, sizeof(buf));
free(p); free(p);
}else }else
strcat_truncate(buf, "-", sizeof(buf)); strlcat(buf, "-", sizeof(buf));
strcat_truncate(buf, " ", sizeof(buf)); strlcat(buf, " ", sizeof(buf));
/* --- flags */ /* --- flags */
asprintf(&p, "%d", HDBFlags2int(ent->flags)); asprintf(&p, "%d", HDBFlags2int(ent->flags));
strcat_truncate(buf, p, sizeof(buf)); strlcat(buf, p, sizeof(buf));
free(p); free(p);
*str = strdup(buf); *str = strdup(buf);

View File

@@ -309,8 +309,8 @@ ipv6_print_addr (const krb5_address *addr, char *str, size_t len)
for(i = 0; i < addr->address.length; i++) { for(i = 0; i < addr->address.length; i++) {
snprintf(buf2, sizeof(buf2), "%02x", p[i]); snprintf(buf2, sizeof(buf2), "%02x", p[i]);
if(i > 0 && (i & 1) == 0) if(i > 0 && (i & 1) == 0)
strcat_truncate(buf, ":", sizeof(buf)); strlcat(buf, ":", sizeof(buf));
strcat_truncate(buf, buf2, sizeof(buf)); strlcat(buf, buf2, sizeof(buf));
} }
} }
return snprintf(str, len, "IPv6:%s", buf); return snprintf(str, len, "IPv6:%s", buf);

View File

@@ -251,7 +251,7 @@ fkt_get_name(krb5_context context,
{ {
/* This function is XXX */ /* This function is XXX */
struct fkt_data *d = id->data; struct fkt_data *d = id->data;
strcpy_truncate(name, d->filename, namesize); strlcpy(name, d->filename, namesize);
return 0; return 0;
} }

View File

@@ -168,7 +168,7 @@ akf_get_name(krb5_context context,
{ {
struct akf_data *d = id->data; struct akf_data *d = id->data;
strcpy_truncate (name, d->filename, name_sz); strlcpy (name, d->filename, name_sz);
return 0; return 0;
} }

View File

@@ -70,7 +70,7 @@ krb4_kt_get_name (krb5_context context,
{ {
struct krb4_kt_data *d = id->data; struct krb4_kt_data *d = id->data;
strcpy_truncate (name, d->filename, name_sz); strlcpy (name, d->filename, name_sz);
return 0; return 0;
} }

View File

@@ -70,7 +70,7 @@ krb5_sock_to_principal (krb5_context context,
if (hostent == NULL) if (hostent == NULL)
return h_errno; return h_errno;
strcpy_truncate(hname, hostent->h_name, sizeof(hname)); strlcpy(hname, hostent->h_name, sizeof(hname));
return krb5_sname_to_principal (context, return krb5_sname_to_principal (context,
hname, hname,
sname, sname,