Add krb5_{ret,store}_stringnl functions, stores/retrieves a \n
terminated string. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@17883 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -440,6 +440,76 @@ krb5_ret_stringz(krb5_storage *sp,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
krb5_error_code KRB5_LIB_FUNCTION
|
||||||
|
krb5_store_stringnl(krb5_storage *sp, const char *s)
|
||||||
|
{
|
||||||
|
size_t len = strlen(s);
|
||||||
|
ssize_t ret;
|
||||||
|
|
||||||
|
ret = sp->store(sp, s, len);
|
||||||
|
if(ret != len) {
|
||||||
|
if(ret < 0)
|
||||||
|
return ret;
|
||||||
|
else
|
||||||
|
return sp->eof_code;
|
||||||
|
}
|
||||||
|
ret = sp->store(sp, "\n", 1);
|
||||||
|
if(ret != 1) {
|
||||||
|
if(ret < 0)
|
||||||
|
return ret;
|
||||||
|
else
|
||||||
|
return sp->eof_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
krb5_error_code KRB5_LIB_FUNCTION
|
||||||
|
krb5_ret_stringnl(krb5_storage *sp,
|
||||||
|
char **string)
|
||||||
|
{
|
||||||
|
int expect_nl = 0;
|
||||||
|
char c;
|
||||||
|
char *s = NULL;
|
||||||
|
size_t len = 0;
|
||||||
|
ssize_t ret;
|
||||||
|
|
||||||
|
while((ret = sp->fetch(sp, &c, 1)) == 1){
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
if (c == '\r') {
|
||||||
|
expect_nl = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (expect_nl && c != '\n') {
|
||||||
|
free(s);
|
||||||
|
return KRB5_BADMSGTYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
len++;
|
||||||
|
tmp = realloc (s, len);
|
||||||
|
if (tmp == NULL) {
|
||||||
|
free (s);
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
|
s = tmp;
|
||||||
|
if(c == '\n') {
|
||||||
|
s[len - 1] = '\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
s[len - 1] = c;
|
||||||
|
}
|
||||||
|
if(ret != 1){
|
||||||
|
free(s);
|
||||||
|
if(ret == 0)
|
||||||
|
return sp->eof_code;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
*string = s;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
krb5_error_code KRB5_LIB_FUNCTION
|
krb5_error_code KRB5_LIB_FUNCTION
|
||||||
krb5_store_principal(krb5_storage *sp,
|
krb5_store_principal(krb5_storage *sp,
|
||||||
|
Reference in New Issue
Block a user