From dbdb412ba0b960e36643e471c16cb430af641ee1 Mon Sep 17 00:00:00 2001 From: Johan Danielsson Date: Sun, 20 Oct 1996 16:47:54 +0000 Subject: [PATCH] Ugh git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@864 ec53bebd-3082-4978-b11e-865c3cabbd6b --- Makefile | 48 +++++ Makefile.in | 8 +- asn1/der_get.c | 1 + asn1/der_put.c | 1 + asn1/gen.c | 5 +- asn1/lex.l | 11 +- asn1/parse.y | 3 + cache.c | 20 +- context.c | 6 + data.c | 5 + krb5.h | 22 +-- lib/asn1/der_get.c | 1 + lib/asn1/der_put.c | 1 + lib/asn1/gen.c | 5 +- lib/asn1/lex.l | 11 +- lib/asn1/parse.y | 3 + lib/krb5/cache.c | 20 +- lib/krb5/context.c | 6 + lib/krb5/data.c | 5 + lib/krb5/krb5.h | 22 +-- lib/krb5/principal.c | 430 +++++++++++++++++++++-------------------- lib/krb5/send_to_kdc.c | 2 +- principal.c | 430 +++++++++++++++++++++-------------------- send_to_kdc.c | 2 +- string2key.c | 6 + 25 files changed, 595 insertions(+), 479 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..d33b86ae9 --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +# Generated automatically from Makefile.in by configure. +CC = cc -std1 +CFLAGS = -g + + +#YACC=bison -y +YACC = yacc + +SOURCES = cache.c principal.c principal_p.c data.c context.c misc.c \ + krbhst.c get_port.c send_to_kdc.c der.c e.c d.c str2key.c \ + get_in_tkt.c get_in_tkt_pw.c der_put.c constants.c get_addrs.c \ + k5_der.c + +OBJECTS = $(SOURCES:%.c=%.o) config_file.o + +all: kinit klist + +%.o: %.c + $(CC) -c $(CFLAGS) -I. -I/usr/athena/include $< -o $@ + +kinit: kinit.o libkrb5.a + $(CC) -o kinit kinit.o libkrb5.a -L/usr/athena/lib -ldes + +klist: klist.o libkrb5.a + $(CC) -o klist klist.o libkrb5.a -L/usr/athena/lib -ldes + +tt: test.o libkrb5.a + $(CC) -o tt test.o libkrb5.a + +test.o: krb5.h + +libkrb5.a: $(OBJECTS) + ar cr libkrb5.a $(OBJECTS) + ranlib libkrb5.a + +config_file.o: config_file.c + +config_file.c: config_file.y + $(YACC) -p __k5cf_ $< + mv -f y.tab.c config_file.c + +clean: + rm -f *.o *~ libkrb5.a tt core \#* config_file.c + + + +$(OBJECTS): krb5_locl.h krb5.h + diff --git a/Makefile.in b/Makefile.in index e9cc7e246..5420d1d07 100644 --- a/Makefile.in +++ b/Makefile.in @@ -9,7 +9,9 @@ CC = @CC@ DEFS = @DEFS@ YACC = @YACC@ -CFLAGS = -g -I$(srcdir) -Iasn1 -I. +CFLAGS = -g -I$(srcdir) -Iasn1 -I. -I/usr/athena/include + +LIBS = -L/usr/athena/lib -ldes SOURCES = cache.c principal.c principal_p.c data.c context.c misc.c \ krbhst.c get_port.c send_to_kdc.c str2key.c \ @@ -21,10 +23,10 @@ OBJECTS = $(SOURCES:%.c=%.o) config_file.o all: kinit klist kinit: kinit.o libkrb5.a - $(CC) -o kinit kinit.o libkrb5.a -Lasn1 -lasn1 -L/usr/local/lib -ldes + $(CC) -o kinit kinit.o libkrb5.a -Lasn1 -lasn1 $(LIBS) klist: klist.o libkrb5.a - $(CC) -o klist klist.o libkrb5.a -L/usr/local/lib -ldes + $(CC) -o klist klist.o libkrb5.a $(LIBS) tt: test.o libkrb5.a $(CC) -o tt test.o libkrb5.a diff --git a/asn1/der_get.c b/asn1/der_get.c index 1ac567e68..61b51d3c5 100644 --- a/asn1/der_get.c +++ b/asn1/der_get.c @@ -3,6 +3,7 @@ #ifdef HAVE_CONFIG_H #include #endif +#include #include #include #include "der.h" diff --git a/asn1/der_put.c b/asn1/der_put.c index b2dccb890..db7a738d4 100644 --- a/asn1/der_put.c +++ b/asn1/der_put.c @@ -3,6 +3,7 @@ #ifdef HAVE_CONFIG_H #include #endif +#include #include #include #include "der.h" diff --git a/asn1/gen.c b/asn1/gen.c index 3b9151ffc..0b029335f 100644 --- a/asn1/gen.c +++ b/asn1/gen.c @@ -19,6 +19,7 @@ init_generate (char *filename) fprintf (codefile, "/* Generated from %s */\n" "/* Do not edit */\n\n" + "#include \n" "#include \n" "#include \n" "#include \n" @@ -222,7 +223,7 @@ encode_type (char *name, Type *t) break; for (m = t->members->prev; m && tag != m->val; m = m->prev) { - char *s = malloc(1 + strlen(name) + 1 + strlen(m->gen_name) + 3); + char *s = malloc(2 + strlen(name) + 1 + strlen(m->gen_name) + 3); sprintf (s, "%s(%s)->%s", m->optional ? "" : "&", name, m->gen_name); if (m->optional) @@ -424,7 +425,7 @@ decode_type (char *name, Type *t) "len = reallen;\n"); for (m = t->members; m && tag != m->val; m = m->next) { - char *s = malloc(1 + strlen(name) + 1 + strlen(m->gen_name) + 3); + char *s = malloc(2 + strlen(name) + 1 + strlen(m->gen_name) + 3); sprintf (s, "%s(%s)->%s", m->optional ? "" : "&", name, m->gen_name); fprintf (codefile, "{\n" diff --git a/asn1/lex.l b/asn1/lex.l index 820d61574..8b9ece52f 100644 --- a/asn1/lex.l +++ b/asn1/lex.l @@ -10,10 +10,15 @@ #include "symbol.h" #include "parse.h" +char *strdup(char *); + +void error_message(char *, ...); + static unsigned lineno = 1; static char filename[256]; %} + %% INTEGER { return INTEGER; } SEQUENCE { return SEQUENCE; } @@ -28,21 +33,23 @@ OPTIONAL { return OPTIONAL; } BEGIN { return TBEGIN; } END { return END; } DEFINITIONS { return DEFINITIONS; } -[][|{},()] { return *yytext; } +,|\{|\}|\(|\)|\[|\]|\| { return *yytext; } ::= { return EEQUAL; } --[^\n]*\n { ; } -?[0-9]+ { yylval.constant = atoi(yytext); return CONSTANT; } [A-Za-z][-A-Za-z0-9_]* { yylval.name = strdup (yytext); return IDENTIFIER; } [ \t] ; \n { lineno++; } -. { fprintf(stderr, "Ignoring char(%c)\n", *yytext); } +. { error_message("Ignoring char(%c)\n", *yytext); } %% +#ifndef yywrap /* XXX */ int yywrap () { return 1; } +#endif void error_message (char *format, ...) diff --git a/asn1/parse.y b/asn1/parse.y index 4983acdfb..8a195b20a 100644 --- a/asn1/parse.y +++ b/asn1/parse.y @@ -12,6 +12,8 @@ static Type *new_type (Typetype t); void yyerror (char *); + +char *strdup(char *); %} %union { @@ -167,6 +169,7 @@ new_type (Typetype tt) t->members = NULL; t->subtype = NULL; t->symbol = NULL; + return t; } static void diff --git a/cache.c b/cache.c index f2937ef57..2b67e7b85 100644 --- a/cache.c +++ b/cache.c @@ -442,16 +442,16 @@ krb5_cc_read_cred (int fd, int8_t dummy8; int32_t dummy32; - return ret_principal (fd, &creds->client) - || ret_principal (fd, &creds->server) - || ret_keyblock (fd, &creds->session) - || ret_times (fd, &creds->times) - || ret_int8 (fd, &dummy8) - || ret_int32 (fd, &dummy32) - || ret_addrs (fd, &creds->addresses) - || ret_authdata (fd, &creds->authdata) - || ret_ticket (fd, &creds->ticket) - || ret_ticket (fd, &creds->second_ticket); + return ret_principal (fd, &creds->client) || + ret_principal (fd, &creds->server) || + ret_keyblock (fd, &creds->session) || + ret_times (fd, &creds->times) || + ret_int8 (fd, &dummy8) || + ret_int32 (fd, &dummy32) || + ret_addrs (fd, &creds->addresses) || + ret_authdata (fd, &creds->authdata) || + ret_ticket (fd, &creds->ticket) || + ret_ticket (fd, &creds->second_ticket); } krb5_error_code diff --git a/context.c b/context.c index 898ad87bf..cc5c5dedf 100644 --- a/context.c +++ b/context.c @@ -1,5 +1,11 @@ #include "krb5_locl.h" +/* XXX */ + +#ifdef sun +#define memmove(a,b,c) bcopy(b,a,c) +#endif + krb5_error_code krb5_init_context(krb5_context *context) { diff --git a/data.c b/data.c index 80234db64..37c1e3bab 100644 --- a/data.c +++ b/data.c @@ -1,5 +1,10 @@ #include "krb5_locl.h" +/* XXX */ + +#ifdef sun +#define memmove(a,b,c) bcopy(b,a,c) +#endif void krb5_data_free(krb5_data *p) diff --git a/krb5.h b/krb5.h index 1c48d7894..82f748d64 100644 --- a/krb5.h +++ b/krb5.h @@ -22,17 +22,17 @@ #endif /* types */ -typedef int32_t krb5_int32; -typedef int16_t krb5_int16; -typedef int8_t krb5_int8; +typedef int int32_t; +typedef short int16_t; +typedef char int8_t; -typedef unsigned int krb5_uint32; -typedef unsigned short krb5_uint16; -typedef unsigned char krb5_uint8; +typedef unsigned int u_int32_t; +typedef unsigned short u_int16_t; +typedef unsigned char u_int8_t; typedef int krb5_boolean; -typedef krb5_int32 krb5_error_code; +typedef int32_t krb5_error_code; @@ -196,7 +196,7 @@ typedef struct krb5_keytab{ typedef struct krb5_auth_context{ - krb5_int32 flags; + int32_t flags; krb5_cksumtype cksumtype; krb5_address local_address; @@ -205,8 +205,8 @@ typedef struct krb5_auth_context{ krb5_keyblock local_subkey; krb5_keyblock remote_subkey; - krb5_int32 local_seqnumber; - krb5_int32 remote_seqnumber; + int32_t local_seqnumber; + int32_t remote_seqnumber; krb5_authenticator authenticator; @@ -217,7 +217,7 @@ typedef struct krb5_auth_context{ }krb5_auth_context; -typedef krb5_uint32 krb5_flags; +typedef u_int32_t krb5_flags; #include diff --git a/lib/asn1/der_get.c b/lib/asn1/der_get.c index 1ac567e68..61b51d3c5 100644 --- a/lib/asn1/der_get.c +++ b/lib/asn1/der_get.c @@ -3,6 +3,7 @@ #ifdef HAVE_CONFIG_H #include #endif +#include #include #include #include "der.h" diff --git a/lib/asn1/der_put.c b/lib/asn1/der_put.c index b2dccb890..db7a738d4 100644 --- a/lib/asn1/der_put.c +++ b/lib/asn1/der_put.c @@ -3,6 +3,7 @@ #ifdef HAVE_CONFIG_H #include #endif +#include #include #include #include "der.h" diff --git a/lib/asn1/gen.c b/lib/asn1/gen.c index 3b9151ffc..0b029335f 100644 --- a/lib/asn1/gen.c +++ b/lib/asn1/gen.c @@ -19,6 +19,7 @@ init_generate (char *filename) fprintf (codefile, "/* Generated from %s */\n" "/* Do not edit */\n\n" + "#include \n" "#include \n" "#include \n" "#include \n" @@ -222,7 +223,7 @@ encode_type (char *name, Type *t) break; for (m = t->members->prev; m && tag != m->val; m = m->prev) { - char *s = malloc(1 + strlen(name) + 1 + strlen(m->gen_name) + 3); + char *s = malloc(2 + strlen(name) + 1 + strlen(m->gen_name) + 3); sprintf (s, "%s(%s)->%s", m->optional ? "" : "&", name, m->gen_name); if (m->optional) @@ -424,7 +425,7 @@ decode_type (char *name, Type *t) "len = reallen;\n"); for (m = t->members; m && tag != m->val; m = m->next) { - char *s = malloc(1 + strlen(name) + 1 + strlen(m->gen_name) + 3); + char *s = malloc(2 + strlen(name) + 1 + strlen(m->gen_name) + 3); sprintf (s, "%s(%s)->%s", m->optional ? "" : "&", name, m->gen_name); fprintf (codefile, "{\n" diff --git a/lib/asn1/lex.l b/lib/asn1/lex.l index 820d61574..8b9ece52f 100644 --- a/lib/asn1/lex.l +++ b/lib/asn1/lex.l @@ -10,10 +10,15 @@ #include "symbol.h" #include "parse.h" +char *strdup(char *); + +void error_message(char *, ...); + static unsigned lineno = 1; static char filename[256]; %} + %% INTEGER { return INTEGER; } SEQUENCE { return SEQUENCE; } @@ -28,21 +33,23 @@ OPTIONAL { return OPTIONAL; } BEGIN { return TBEGIN; } END { return END; } DEFINITIONS { return DEFINITIONS; } -[][|{},()] { return *yytext; } +,|\{|\}|\(|\)|\[|\]|\| { return *yytext; } ::= { return EEQUAL; } --[^\n]*\n { ; } -?[0-9]+ { yylval.constant = atoi(yytext); return CONSTANT; } [A-Za-z][-A-Za-z0-9_]* { yylval.name = strdup (yytext); return IDENTIFIER; } [ \t] ; \n { lineno++; } -. { fprintf(stderr, "Ignoring char(%c)\n", *yytext); } +. { error_message("Ignoring char(%c)\n", *yytext); } %% +#ifndef yywrap /* XXX */ int yywrap () { return 1; } +#endif void error_message (char *format, ...) diff --git a/lib/asn1/parse.y b/lib/asn1/parse.y index 4983acdfb..8a195b20a 100644 --- a/lib/asn1/parse.y +++ b/lib/asn1/parse.y @@ -12,6 +12,8 @@ static Type *new_type (Typetype t); void yyerror (char *); + +char *strdup(char *); %} %union { @@ -167,6 +169,7 @@ new_type (Typetype tt) t->members = NULL; t->subtype = NULL; t->symbol = NULL; + return t; } static void diff --git a/lib/krb5/cache.c b/lib/krb5/cache.c index f2937ef57..2b67e7b85 100644 --- a/lib/krb5/cache.c +++ b/lib/krb5/cache.c @@ -442,16 +442,16 @@ krb5_cc_read_cred (int fd, int8_t dummy8; int32_t dummy32; - return ret_principal (fd, &creds->client) - || ret_principal (fd, &creds->server) - || ret_keyblock (fd, &creds->session) - || ret_times (fd, &creds->times) - || ret_int8 (fd, &dummy8) - || ret_int32 (fd, &dummy32) - || ret_addrs (fd, &creds->addresses) - || ret_authdata (fd, &creds->authdata) - || ret_ticket (fd, &creds->ticket) - || ret_ticket (fd, &creds->second_ticket); + return ret_principal (fd, &creds->client) || + ret_principal (fd, &creds->server) || + ret_keyblock (fd, &creds->session) || + ret_times (fd, &creds->times) || + ret_int8 (fd, &dummy8) || + ret_int32 (fd, &dummy32) || + ret_addrs (fd, &creds->addresses) || + ret_authdata (fd, &creds->authdata) || + ret_ticket (fd, &creds->ticket) || + ret_ticket (fd, &creds->second_ticket); } krb5_error_code diff --git a/lib/krb5/context.c b/lib/krb5/context.c index 898ad87bf..cc5c5dedf 100644 --- a/lib/krb5/context.c +++ b/lib/krb5/context.c @@ -1,5 +1,11 @@ #include "krb5_locl.h" +/* XXX */ + +#ifdef sun +#define memmove(a,b,c) bcopy(b,a,c) +#endif + krb5_error_code krb5_init_context(krb5_context *context) { diff --git a/lib/krb5/data.c b/lib/krb5/data.c index 80234db64..37c1e3bab 100644 --- a/lib/krb5/data.c +++ b/lib/krb5/data.c @@ -1,5 +1,10 @@ #include "krb5_locl.h" +/* XXX */ + +#ifdef sun +#define memmove(a,b,c) bcopy(b,a,c) +#endif void krb5_data_free(krb5_data *p) diff --git a/lib/krb5/krb5.h b/lib/krb5/krb5.h index 1c48d7894..82f748d64 100644 --- a/lib/krb5/krb5.h +++ b/lib/krb5/krb5.h @@ -22,17 +22,17 @@ #endif /* types */ -typedef int32_t krb5_int32; -typedef int16_t krb5_int16; -typedef int8_t krb5_int8; +typedef int int32_t; +typedef short int16_t; +typedef char int8_t; -typedef unsigned int krb5_uint32; -typedef unsigned short krb5_uint16; -typedef unsigned char krb5_uint8; +typedef unsigned int u_int32_t; +typedef unsigned short u_int16_t; +typedef unsigned char u_int8_t; typedef int krb5_boolean; -typedef krb5_int32 krb5_error_code; +typedef int32_t krb5_error_code; @@ -196,7 +196,7 @@ typedef struct krb5_keytab{ typedef struct krb5_auth_context{ - krb5_int32 flags; + int32_t flags; krb5_cksumtype cksumtype; krb5_address local_address; @@ -205,8 +205,8 @@ typedef struct krb5_auth_context{ krb5_keyblock local_subkey; krb5_keyblock remote_subkey; - krb5_int32 local_seqnumber; - krb5_int32 remote_seqnumber; + int32_t local_seqnumber; + int32_t remote_seqnumber; krb5_authenticator authenticator; @@ -217,7 +217,7 @@ typedef struct krb5_auth_context{ }krb5_auth_context; -typedef krb5_uint32 krb5_flags; +typedef u_int32_t krb5_flags; #include diff --git a/lib/krb5/principal.c b/lib/krb5/principal.c index a68b139bf..2735abefe 100644 --- a/lib/krb5/principal.c +++ b/lib/krb5/principal.c @@ -2,12 +2,18 @@ RCSID("$Id$"); +/* XXX */ + +#ifdef sun +#define memmove(a,b,c) bcopy(b,a,c) +#endif + /* Public principal handling functions */ void krb5_free_principal(krb5_principal p) { - krb5_principal_free(p); + krb5_principal_free(p); } krb5_error_code @@ -16,117 +22,117 @@ krb5_parse_name(krb5_context context, krb5_principal *principal) { - krb5_data *comp; - int ncomp; - krb5_data realm; + krb5_data *comp; + int ncomp; + krb5_data realm; - char *p; - char *q; - char *s; - char *start; + char *p; + char *q; + char *s; + char *start; - int n; - char c; - int got_realm = 0; + int n; + char c; + int got_realm = 0; - /* count number of component */ - ncomp = 1; - for(p = (char*)name; *p; p++){ - if(*p=='\\'){ - if(!p[1]) - return KRB5_PARSE_MALFORMED; - p++; - } else if(*p == '/') - ncomp++; - } - comp = ALLOC(ncomp, krb5_data); + /* count number of component */ + ncomp = 1; + for(p = (char*)name; *p; p++){ + if(*p=='\\'){ + if(!p[1]) + return KRB5_PARSE_MALFORMED; + p++; + } else if(*p == '/') + ncomp++; + } + comp = ALLOC(ncomp, krb5_data); - n = 0; - start = q = p = s = strdup(name); - while(*p){ - c = *p++; - if(c == '\\'){ - c = *p++; - if(c == 'n') - c = '\n'; - else if(c == 't') - c = '\t'; - else if(c == 'b') - c = '\b'; - else if(c == '0') - c = '\0'; - }else if(c == '/' || c == '@'){ - if(got_realm){ - while(n>0) - free(comp[--n].data); - free(comp); - free(s); - return KRB5_PARSE_MALFORMED; - }else{ + n = 0; + start = q = p = s = strdup(name); + while(*p){ + c = *p++; + if(c == '\\'){ + c = *p++; + if(c == 'n') + c = '\n'; + else if(c == 't') + c = '\t'; + else if(c == 'b') + c = '\b'; + else if(c == '0') + c = '\0'; + }else if(c == '/' || c == '@'){ + if(got_realm){ + while(n>0) + free(comp[--n].data); + free(comp); + free(s); + return KRB5_PARSE_MALFORMED; + }else{ + comp[n].length = q - start; + comp[n].data = (krb5_pointer)malloc(comp[n].length); + memmove(comp[n].data, start, comp[n].length); + n++; + } + if(c == '@') + got_realm = 1; + start = q; + continue; + } + if(got_realm && (c == ':' || c == '/' || c == '\0')){ + while(n>0) + free(comp[--n].data); + free(comp); + free(s); + return KRB5_PARSE_MALFORMED; + } + *q++ = c; + } + if(got_realm){ + realm.length = q - start; + realm.data = (krb5_pointer)malloc(realm.length); + memmove(realm.data, start, realm.length); + }else{ comp[n].length = q - start; comp[n].data = (krb5_pointer)malloc(comp[n].length); memmove(comp[n].data, start, comp[n].length); n++; - } - if(c == '@') - got_realm = 1; - start = q; - continue; } - if(got_realm && (c == ':' || c == '/' || c == '\0')){ - while(n>0) - free(comp[--n].data); - free(comp); - free(s); - return KRB5_PARSE_MALFORMED; - } - *q++ = c; - } - if(got_realm){ - realm.length = q - start; - realm.data = (krb5_pointer)malloc(realm.length); - memmove(realm.data, start, realm.length); - }else{ - comp[n].length = q - start; - comp[n].data = (krb5_pointer)malloc(comp[n].length); - memmove(comp[n].data, start, comp[n].length); - n++; - } - *principal = ALLOC(1, krb5_principal_data); - (*principal)->type = KRB5_NT_PRINCIPAL; - (*principal)->realm = realm; - (*principal)->comp = comp; - (*principal)->ncomp = n; - free(s); - return 0; + *principal = ALLOC(1, krb5_principal_data); + (*principal)->type = KRB5_NT_PRINCIPAL; + (*principal)->realm = realm; + (*principal)->comp = comp; + (*principal)->ncomp = n; + free(s); + return 0; } static void quote_string(char *s, int len, char **out) { - char *q; - char *p = *out; - int c=0; - for(q = s; q < s + len; q++){ - if(*q == '\n') - c = 'n'; - else if(*q == '\t') - c = 't'; - else if(*q == '\b') - c = 'b'; - else if(*q == '\0') - c = '0'; - else if(*q == '/') - c='/'; - else if(*q == '@') - c = '@'; - if(c){ - *p++ = '\\'; - *p++ = c; - c = 0; - }else - *p++ = *q; - } - *out = p; + char *q; + char *p = *out; + int c=0; + for(q = s; q < s + len; q++){ + if(*q == '\n') + c = 'n'; + else if(*q == '\t') + c = 't'; + else if(*q == '\b') + c = 'b'; + else if(*q == '\0') + c = '0'; + else if(*q == '/') + c='/'; + else if(*q == '@') + c = '@'; + if(c){ + *p++ = '\\'; + *p++ = c; + c = 0; + }else + *p++ = *q; + } + *out = p; } @@ -135,25 +141,25 @@ krb5_unparse_name(krb5_context context, krb5_principal principal, char **name) { - int size = 0; - char *p; - char *s; - int i; - for(i = 0; i < principal->ncomp; i++) - size += 2*principal->comp[i].length + 1; - size += 2*principal->realm.length + 1; - s = ALLOC(size, char); - p = s; - for(i = 0; i < principal->ncomp; i++){ - if(i) *p++ = '/'; - quote_string(principal->comp[i].data, principal->comp[i].length, &p); - } - *p++ = '@'; - quote_string(principal->realm.data, principal->realm.length, &p); - *p = 0; - *name = strdup(s); - free(s); - return 0; + int size = 0; + char *p; + char *s; + int i; + for(i = 0; i < principal->ncomp; i++) + size += 2*principal->comp[i].length + 1; + size += 2*principal->realm.length + 1; + s = ALLOC(size, char); + p = s; + for(i = 0; i < principal->ncomp; i++){ + if(i) *p++ = '/'; + quote_string(principal->comp[i].data, principal->comp[i].length, &p); + } + *p++ = '@'; + quote_string(principal->realm.data, principal->realm.length, &p); + *p = 0; + *name = strdup(s); + free(s); + return 0; } @@ -163,8 +169,8 @@ krb5_unparse_name_ext(krb5_context context, char **name, size_t *size) { - fprintf(stderr, "krb5_unparse_name_ext: not implemented\n"); - abort(); + fprintf(stderr, "krb5_unparse_name_ext: not implemented\n"); + abort(); } @@ -172,7 +178,7 @@ krb5_data* krb5_princ_realm(krb5_context context, krb5_principal principal) { - return &principal->realm; + return &principal->realm; } @@ -181,7 +187,7 @@ krb5_princ_set_realm(krb5_context context, krb5_principal principal, krb5_data *realm) { - principal->realm = *realm; + principal->realm = *realm; } @@ -192,31 +198,31 @@ krb5_build_principal(krb5_context context, const char *realm, ...) { - krb5_error_code ret; - va_list ap; - va_start(ap, realm); - ret = krb5_build_principal_va(context, principal, rlen, realm, ap); - va_end(ap); - return ret; + krb5_error_code ret; + va_list ap; + va_start(ap, realm); + ret = krb5_build_principal_va(context, principal, rlen, realm, ap); + va_end(ap); + return ret; } krb5_error_code krb5_principal_set_component(krb5_principal p, int n, void *data, size_t len) { - krb5_data *tmp; - if(p->ncomp <= n){ - int s = n + 10; - if(p->comp) - tmp = (krb5_data*)realloc(p->comp, s * sizeof(krb5_data)); - else - tmp = ALLOC(s, krb5_data); - if(!tmp) - return ENOMEM; - p->comp = tmp; - p->ncomp = s; - } - krb5_data_copy(&p->comp[n], data, len); - return 0; + krb5_data *tmp; + if(p->ncomp <= n){ + int s = n + 10; + if(p->comp) + tmp = (krb5_data*)realloc(p->comp, s * sizeof(krb5_data)); + else + tmp = ALLOC(s, krb5_data); + if(!tmp) + return ENOMEM; + p->comp = tmp; + p->ncomp = s; + } + krb5_data_copy(&p->comp[n], data, len); + return 0; } @@ -227,30 +233,30 @@ krb5_build_principal_va(krb5_context context, const char *realm, va_list ap) { - krb5_principal p; - int n; - char *s; + krb5_principal p; + int n; + char *s; - if(krb5_principal_alloc(&p)) - return ENOMEM; - p->type = KRB5_NT_PRINCIPAL; + if(krb5_principal_alloc(&p)) + return ENOMEM; + p->type = KRB5_NT_PRINCIPAL; - if(krb5_data_copy(&p->realm, (void*)realm, rlen)){ - free(p); - return ENOMEM; - } + if(krb5_data_copy(&p->realm, (void*)realm, rlen)){ + free(p); + return ENOMEM; + } - n = 0; - while(1){ - s = va_arg(ap, char*); - if(s == NULL) - break; - krb5_principal_set_component(p, n, s, strlen(s)); - n++; - } - p->ncomp = n; - *principal = p; - return 0; + n = 0; + while(1){ + s = va_arg(ap, char*); + if(s == NULL) + break; + krb5_principal_set_component(p, n, s, strlen(s)); + n++; + } + p->ncomp = n; + *principal = p; + return 0; } @@ -261,8 +267,8 @@ krb5_build_principal_ext(krb5_context context, const char *realm, ...) { - fprintf(stderr, "krb5_build_principal_ext: not implemented\n"); - abort(); + fprintf(stderr, "krb5_build_principal_ext: not implemented\n"); + abort(); } @@ -271,32 +277,32 @@ krb5_copy_principal(krb5_context context, krb5_const_principal inprinc, krb5_principal *outprinc) { - krb5_principal p; - int i; - if(krb5_principal_alloc(&p)) - return ENOMEM; - p->type = inprinc->type; - if(krb5_data_copy(&p->realm, inprinc->realm.data, inprinc->realm.length)){ - krb5_free_principal(p); - return ENOMEM; - } - p->comp = ALLOC(inprinc->ncomp, krb5_data); - if(!p->comp){ - krb5_free_principal(p); - return ENOMEM; - } - - for(i=0; incomp; i++){ - p->comp[i].length = 0; - if(krb5_data_copy(&p->comp[i], inprinc->comp[i].data, - inprinc->comp[i].length)){ - krb5_free_principal(p); - return ENOMEM; + krb5_principal p; + int i; + if(krb5_principal_alloc(&p)) + return ENOMEM; + p->type = inprinc->type; + if(krb5_data_copy(&p->realm, inprinc->realm.data, inprinc->realm.length)){ + krb5_free_principal(p); + return ENOMEM; } - p->ncomp = i+1; - } - *outprinc = p; - return 0; + p->comp = ALLOC(inprinc->ncomp, krb5_data); + if(!p->comp){ + krb5_free_principal(p); + return ENOMEM; + } + + for(i=0; incomp; i++){ + p->comp[i].length = 0; + if(krb5_data_copy(&p->comp[i], inprinc->comp[i].data, + inprinc->comp[i].length)){ + krb5_free_principal(p); + return ENOMEM; + } + p->ncomp = i+1; + } + *outprinc = p; + return 0; } @@ -305,19 +311,19 @@ krb5_principal_compare(krb5_context context, krb5_const_principal princ1, krb5_const_principal princ2) { - int i; - if(!krb5_realm_compare(context, princ1, princ2)) - return FALSE; - if(princ1->ncomp != princ2->ncomp) - return FALSE; - for(i=0; incomp; i++){ - if(princ1->comp[i].length != princ2->comp[i].length) - return FALSE; - if(memcmp(princ1->comp[i].data, princ2->comp[i].data, - princ1->comp[i].length)) - return FALSE; - } - return TRUE; + int i; + if(!krb5_realm_compare(context, princ1, princ2)) + return FALSE; + if(princ1->ncomp != princ2->ncomp) + return FALSE; + for(i=0; incomp; i++){ + if(princ1->comp[i].length != princ2->comp[i].length) + return FALSE; + if(memcmp(princ1->comp[i].data, princ2->comp[i].data, + princ1->comp[i].length)) + return FALSE; + } + return TRUE; } @@ -326,11 +332,11 @@ krb5_realm_compare(krb5_context context, krb5_const_principal princ1, krb5_const_principal princ2) { - if(princ1->realm.length != princ2->realm.length) - return FALSE; - if(memcmp(princ1->realm.data, princ2->realm.data, princ1->realm.length)) - return FALSE; - return TRUE; + if(princ1->realm.length != princ2->realm.length) + return FALSE; + if(memcmp(princ1->realm.data, princ2->realm.data, princ1->realm.length)) + return FALSE; + return TRUE; } @@ -341,10 +347,10 @@ krb5_425_conv_principal(krb5_context context, const char *realm, krb5_principal *princ) { - if(!strcmp(name, "rcmd")) - name = "host"; - return krb5_build_principal(context, princ, - strlen(realm), realm, name, instance, 0); + if(!strcmp(name, "rcmd")) + name = "host"; + return krb5_build_principal(context, princ, + strlen(realm), realm, name, instance, 0); } diff --git a/lib/krb5/send_to_kdc.c b/lib/krb5/send_to_kdc.c index 9e564d320..e450daaff 100644 --- a/lib/krb5/send_to_kdc.c +++ b/lib/krb5/send_to_kdc.c @@ -10,7 +10,7 @@ send_and_recv (int fd, struct fd_set fdset; struct timeval timeout; int ret; - long nbytes; + int nbytes; if (sendto (fd, send->data, send->length, 0, (struct sockaddr *)addr, sizeof(*addr)) < 0) diff --git a/principal.c b/principal.c index a68b139bf..2735abefe 100644 --- a/principal.c +++ b/principal.c @@ -2,12 +2,18 @@ RCSID("$Id$"); +/* XXX */ + +#ifdef sun +#define memmove(a,b,c) bcopy(b,a,c) +#endif + /* Public principal handling functions */ void krb5_free_principal(krb5_principal p) { - krb5_principal_free(p); + krb5_principal_free(p); } krb5_error_code @@ -16,117 +22,117 @@ krb5_parse_name(krb5_context context, krb5_principal *principal) { - krb5_data *comp; - int ncomp; - krb5_data realm; + krb5_data *comp; + int ncomp; + krb5_data realm; - char *p; - char *q; - char *s; - char *start; + char *p; + char *q; + char *s; + char *start; - int n; - char c; - int got_realm = 0; + int n; + char c; + int got_realm = 0; - /* count number of component */ - ncomp = 1; - for(p = (char*)name; *p; p++){ - if(*p=='\\'){ - if(!p[1]) - return KRB5_PARSE_MALFORMED; - p++; - } else if(*p == '/') - ncomp++; - } - comp = ALLOC(ncomp, krb5_data); + /* count number of component */ + ncomp = 1; + for(p = (char*)name; *p; p++){ + if(*p=='\\'){ + if(!p[1]) + return KRB5_PARSE_MALFORMED; + p++; + } else if(*p == '/') + ncomp++; + } + comp = ALLOC(ncomp, krb5_data); - n = 0; - start = q = p = s = strdup(name); - while(*p){ - c = *p++; - if(c == '\\'){ - c = *p++; - if(c == 'n') - c = '\n'; - else if(c == 't') - c = '\t'; - else if(c == 'b') - c = '\b'; - else if(c == '0') - c = '\0'; - }else if(c == '/' || c == '@'){ - if(got_realm){ - while(n>0) - free(comp[--n].data); - free(comp); - free(s); - return KRB5_PARSE_MALFORMED; - }else{ + n = 0; + start = q = p = s = strdup(name); + while(*p){ + c = *p++; + if(c == '\\'){ + c = *p++; + if(c == 'n') + c = '\n'; + else if(c == 't') + c = '\t'; + else if(c == 'b') + c = '\b'; + else if(c == '0') + c = '\0'; + }else if(c == '/' || c == '@'){ + if(got_realm){ + while(n>0) + free(comp[--n].data); + free(comp); + free(s); + return KRB5_PARSE_MALFORMED; + }else{ + comp[n].length = q - start; + comp[n].data = (krb5_pointer)malloc(comp[n].length); + memmove(comp[n].data, start, comp[n].length); + n++; + } + if(c == '@') + got_realm = 1; + start = q; + continue; + } + if(got_realm && (c == ':' || c == '/' || c == '\0')){ + while(n>0) + free(comp[--n].data); + free(comp); + free(s); + return KRB5_PARSE_MALFORMED; + } + *q++ = c; + } + if(got_realm){ + realm.length = q - start; + realm.data = (krb5_pointer)malloc(realm.length); + memmove(realm.data, start, realm.length); + }else{ comp[n].length = q - start; comp[n].data = (krb5_pointer)malloc(comp[n].length); memmove(comp[n].data, start, comp[n].length); n++; - } - if(c == '@') - got_realm = 1; - start = q; - continue; } - if(got_realm && (c == ':' || c == '/' || c == '\0')){ - while(n>0) - free(comp[--n].data); - free(comp); - free(s); - return KRB5_PARSE_MALFORMED; - } - *q++ = c; - } - if(got_realm){ - realm.length = q - start; - realm.data = (krb5_pointer)malloc(realm.length); - memmove(realm.data, start, realm.length); - }else{ - comp[n].length = q - start; - comp[n].data = (krb5_pointer)malloc(comp[n].length); - memmove(comp[n].data, start, comp[n].length); - n++; - } - *principal = ALLOC(1, krb5_principal_data); - (*principal)->type = KRB5_NT_PRINCIPAL; - (*principal)->realm = realm; - (*principal)->comp = comp; - (*principal)->ncomp = n; - free(s); - return 0; + *principal = ALLOC(1, krb5_principal_data); + (*principal)->type = KRB5_NT_PRINCIPAL; + (*principal)->realm = realm; + (*principal)->comp = comp; + (*principal)->ncomp = n; + free(s); + return 0; } static void quote_string(char *s, int len, char **out) { - char *q; - char *p = *out; - int c=0; - for(q = s; q < s + len; q++){ - if(*q == '\n') - c = 'n'; - else if(*q == '\t') - c = 't'; - else if(*q == '\b') - c = 'b'; - else if(*q == '\0') - c = '0'; - else if(*q == '/') - c='/'; - else if(*q == '@') - c = '@'; - if(c){ - *p++ = '\\'; - *p++ = c; - c = 0; - }else - *p++ = *q; - } - *out = p; + char *q; + char *p = *out; + int c=0; + for(q = s; q < s + len; q++){ + if(*q == '\n') + c = 'n'; + else if(*q == '\t') + c = 't'; + else if(*q == '\b') + c = 'b'; + else if(*q == '\0') + c = '0'; + else if(*q == '/') + c='/'; + else if(*q == '@') + c = '@'; + if(c){ + *p++ = '\\'; + *p++ = c; + c = 0; + }else + *p++ = *q; + } + *out = p; } @@ -135,25 +141,25 @@ krb5_unparse_name(krb5_context context, krb5_principal principal, char **name) { - int size = 0; - char *p; - char *s; - int i; - for(i = 0; i < principal->ncomp; i++) - size += 2*principal->comp[i].length + 1; - size += 2*principal->realm.length + 1; - s = ALLOC(size, char); - p = s; - for(i = 0; i < principal->ncomp; i++){ - if(i) *p++ = '/'; - quote_string(principal->comp[i].data, principal->comp[i].length, &p); - } - *p++ = '@'; - quote_string(principal->realm.data, principal->realm.length, &p); - *p = 0; - *name = strdup(s); - free(s); - return 0; + int size = 0; + char *p; + char *s; + int i; + for(i = 0; i < principal->ncomp; i++) + size += 2*principal->comp[i].length + 1; + size += 2*principal->realm.length + 1; + s = ALLOC(size, char); + p = s; + for(i = 0; i < principal->ncomp; i++){ + if(i) *p++ = '/'; + quote_string(principal->comp[i].data, principal->comp[i].length, &p); + } + *p++ = '@'; + quote_string(principal->realm.data, principal->realm.length, &p); + *p = 0; + *name = strdup(s); + free(s); + return 0; } @@ -163,8 +169,8 @@ krb5_unparse_name_ext(krb5_context context, char **name, size_t *size) { - fprintf(stderr, "krb5_unparse_name_ext: not implemented\n"); - abort(); + fprintf(stderr, "krb5_unparse_name_ext: not implemented\n"); + abort(); } @@ -172,7 +178,7 @@ krb5_data* krb5_princ_realm(krb5_context context, krb5_principal principal) { - return &principal->realm; + return &principal->realm; } @@ -181,7 +187,7 @@ krb5_princ_set_realm(krb5_context context, krb5_principal principal, krb5_data *realm) { - principal->realm = *realm; + principal->realm = *realm; } @@ -192,31 +198,31 @@ krb5_build_principal(krb5_context context, const char *realm, ...) { - krb5_error_code ret; - va_list ap; - va_start(ap, realm); - ret = krb5_build_principal_va(context, principal, rlen, realm, ap); - va_end(ap); - return ret; + krb5_error_code ret; + va_list ap; + va_start(ap, realm); + ret = krb5_build_principal_va(context, principal, rlen, realm, ap); + va_end(ap); + return ret; } krb5_error_code krb5_principal_set_component(krb5_principal p, int n, void *data, size_t len) { - krb5_data *tmp; - if(p->ncomp <= n){ - int s = n + 10; - if(p->comp) - tmp = (krb5_data*)realloc(p->comp, s * sizeof(krb5_data)); - else - tmp = ALLOC(s, krb5_data); - if(!tmp) - return ENOMEM; - p->comp = tmp; - p->ncomp = s; - } - krb5_data_copy(&p->comp[n], data, len); - return 0; + krb5_data *tmp; + if(p->ncomp <= n){ + int s = n + 10; + if(p->comp) + tmp = (krb5_data*)realloc(p->comp, s * sizeof(krb5_data)); + else + tmp = ALLOC(s, krb5_data); + if(!tmp) + return ENOMEM; + p->comp = tmp; + p->ncomp = s; + } + krb5_data_copy(&p->comp[n], data, len); + return 0; } @@ -227,30 +233,30 @@ krb5_build_principal_va(krb5_context context, const char *realm, va_list ap) { - krb5_principal p; - int n; - char *s; + krb5_principal p; + int n; + char *s; - if(krb5_principal_alloc(&p)) - return ENOMEM; - p->type = KRB5_NT_PRINCIPAL; + if(krb5_principal_alloc(&p)) + return ENOMEM; + p->type = KRB5_NT_PRINCIPAL; - if(krb5_data_copy(&p->realm, (void*)realm, rlen)){ - free(p); - return ENOMEM; - } + if(krb5_data_copy(&p->realm, (void*)realm, rlen)){ + free(p); + return ENOMEM; + } - n = 0; - while(1){ - s = va_arg(ap, char*); - if(s == NULL) - break; - krb5_principal_set_component(p, n, s, strlen(s)); - n++; - } - p->ncomp = n; - *principal = p; - return 0; + n = 0; + while(1){ + s = va_arg(ap, char*); + if(s == NULL) + break; + krb5_principal_set_component(p, n, s, strlen(s)); + n++; + } + p->ncomp = n; + *principal = p; + return 0; } @@ -261,8 +267,8 @@ krb5_build_principal_ext(krb5_context context, const char *realm, ...) { - fprintf(stderr, "krb5_build_principal_ext: not implemented\n"); - abort(); + fprintf(stderr, "krb5_build_principal_ext: not implemented\n"); + abort(); } @@ -271,32 +277,32 @@ krb5_copy_principal(krb5_context context, krb5_const_principal inprinc, krb5_principal *outprinc) { - krb5_principal p; - int i; - if(krb5_principal_alloc(&p)) - return ENOMEM; - p->type = inprinc->type; - if(krb5_data_copy(&p->realm, inprinc->realm.data, inprinc->realm.length)){ - krb5_free_principal(p); - return ENOMEM; - } - p->comp = ALLOC(inprinc->ncomp, krb5_data); - if(!p->comp){ - krb5_free_principal(p); - return ENOMEM; - } - - for(i=0; incomp; i++){ - p->comp[i].length = 0; - if(krb5_data_copy(&p->comp[i], inprinc->comp[i].data, - inprinc->comp[i].length)){ - krb5_free_principal(p); - return ENOMEM; + krb5_principal p; + int i; + if(krb5_principal_alloc(&p)) + return ENOMEM; + p->type = inprinc->type; + if(krb5_data_copy(&p->realm, inprinc->realm.data, inprinc->realm.length)){ + krb5_free_principal(p); + return ENOMEM; } - p->ncomp = i+1; - } - *outprinc = p; - return 0; + p->comp = ALLOC(inprinc->ncomp, krb5_data); + if(!p->comp){ + krb5_free_principal(p); + return ENOMEM; + } + + for(i=0; incomp; i++){ + p->comp[i].length = 0; + if(krb5_data_copy(&p->comp[i], inprinc->comp[i].data, + inprinc->comp[i].length)){ + krb5_free_principal(p); + return ENOMEM; + } + p->ncomp = i+1; + } + *outprinc = p; + return 0; } @@ -305,19 +311,19 @@ krb5_principal_compare(krb5_context context, krb5_const_principal princ1, krb5_const_principal princ2) { - int i; - if(!krb5_realm_compare(context, princ1, princ2)) - return FALSE; - if(princ1->ncomp != princ2->ncomp) - return FALSE; - for(i=0; incomp; i++){ - if(princ1->comp[i].length != princ2->comp[i].length) - return FALSE; - if(memcmp(princ1->comp[i].data, princ2->comp[i].data, - princ1->comp[i].length)) - return FALSE; - } - return TRUE; + int i; + if(!krb5_realm_compare(context, princ1, princ2)) + return FALSE; + if(princ1->ncomp != princ2->ncomp) + return FALSE; + for(i=0; incomp; i++){ + if(princ1->comp[i].length != princ2->comp[i].length) + return FALSE; + if(memcmp(princ1->comp[i].data, princ2->comp[i].data, + princ1->comp[i].length)) + return FALSE; + } + return TRUE; } @@ -326,11 +332,11 @@ krb5_realm_compare(krb5_context context, krb5_const_principal princ1, krb5_const_principal princ2) { - if(princ1->realm.length != princ2->realm.length) - return FALSE; - if(memcmp(princ1->realm.data, princ2->realm.data, princ1->realm.length)) - return FALSE; - return TRUE; + if(princ1->realm.length != princ2->realm.length) + return FALSE; + if(memcmp(princ1->realm.data, princ2->realm.data, princ1->realm.length)) + return FALSE; + return TRUE; } @@ -341,10 +347,10 @@ krb5_425_conv_principal(krb5_context context, const char *realm, krb5_principal *princ) { - if(!strcmp(name, "rcmd")) - name = "host"; - return krb5_build_principal(context, princ, - strlen(realm), realm, name, instance, 0); + if(!strcmp(name, "rcmd")) + name = "host"; + return krb5_build_principal(context, princ, + strlen(realm), realm, name, instance, 0); } diff --git a/send_to_kdc.c b/send_to_kdc.c index 9e564d320..e450daaff 100644 --- a/send_to_kdc.c +++ b/send_to_kdc.c @@ -10,7 +10,7 @@ send_and_recv (int fd, struct fd_set fdset; struct timeval timeout; int ret; - long nbytes; + int nbytes; if (sendto (fd, send->data, send->length, 0, (struct sockaddr *)addr, sizeof(*addr)) < 0) diff --git a/string2key.c b/string2key.c index 116f9dba4..cf403aa70 100644 --- a/string2key.c +++ b/string2key.c @@ -1,5 +1,11 @@ #include "krb5_locl.h" +/* XXX */ + +#ifdef sun +#define memmove(a,b,c) bcopy(b,a,c) +#endif + static void reverse(unsigned char *p) { unsigned char tmp[8];