diff options
author | markm <markm@FreeBSD.org> | 1999-09-19 14:19:32 +0000 |
---|---|---|
committer | markm <markm@FreeBSD.org> | 1999-09-19 14:19:32 +0000 |
commit | fe83e8abf357ee11114856a5278bb38431a9517c (patch) | |
tree | 36ce70fe2e8419130e546c38a7790e8ab224a362 /crypto/kerberosIV/lib/krb/ticket_memory.c | |
parent | a8a89cfaf983bc64f4b42f7c35209a5a36dd0fe8 (diff) | |
download | FreeBSD-src-fe83e8abf357ee11114856a5278bb38431a9517c.zip FreeBSD-src-fe83e8abf357ee11114856a5278bb38431a9517c.tar.gz |
Clean import of KTH krb4-0.10.1.
Diffstat (limited to 'crypto/kerberosIV/lib/krb/ticket_memory.c')
-rw-r--r-- | crypto/kerberosIV/lib/krb/ticket_memory.c | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/crypto/kerberosIV/lib/krb/ticket_memory.c b/crypto/kerberosIV/lib/krb/ticket_memory.c index 04e20b6..d1fab2e 100644 --- a/crypto/kerberosIV/lib/krb/ticket_memory.c +++ b/crypto/kerberosIV/lib/krb/ticket_memory.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan + * Copyright (c) 1995, 1996, 1997, 1998 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * @@ -45,7 +45,7 @@ #include "krb_locl.h" #include "ticket_memory.h" -RCSID("$Id: ticket_memory.c,v 1.9 1997/04/20 18:07:36 assar Exp $"); +RCSID("$Id: ticket_memory.c,v 1.13 1998/08/23 18:07:41 assar Exp $"); void msg(char *text, int error); @@ -55,40 +55,36 @@ tktmem *SharedMemory; static int CredIndex = -1; +void PostUpdateMessage(void); + int newTktMem(const char *tf_name) { - if(!SharedMemory) - { - unsigned int MemorySize = sizeof(tktmem); - unsigned int MemorySizeHi = sizeof(tktmem)>>16; - unsigned int MemorySizeLo = MemorySize&0xFFFF; - SharedMemoryHandle = CreateFileMapping((HANDLE)(int)-1, 0, + if(!SharedMemory){ + SharedMemoryHandle = CreateFileMapping((HANDLE)-1, 0, PAGE_READWRITE, - MemorySizeHi, MemorySizeLo, + sizeof(tktmem) >> 16, + sizeof(tktmem) & 0xffff, "krb_memory"); - - if(!SharedMemoryHandle) - { + + if(!SharedMemoryHandle){ msg("Could not create shared memory.", GetLastError()); return KFAILURE; } SharedMemory = MapViewOfFile(SharedMemoryHandle, FILE_MAP_WRITE, 0, 0, 0); - if(!SharedMemory) - { + if(!SharedMemory){ msg("Unable to alloc shared memory.", GetLastError()); return KFAILURE; } - if(GetLastError() != ERROR_ALREADY_EXISTS) - { + if(GetLastError() != ERROR_ALREADY_EXISTS) { + memset(SharedMemory, 0, sizeof(*SharedMemory)); if(tf_name) - strcpy(SharedMemory->tmname, tf_name); - SharedMemory->last_cred_no = 0; + strcpy_truncate(SharedMemory->tmname, + tf_name, sizeof(SharedMemory->tmname)); } } - CredIndex = 0; return KSUCCESS; } @@ -96,8 +92,7 @@ newTktMem(const char *tf_name) int freeTktMem(const char *tf_name) { - if(SharedMemory) - { + if(SharedMemory) { UnmapViewOfFile(SharedMemory); CloseHandle(SharedMemoryHandle); } @@ -184,9 +179,8 @@ in_tkt(char *pname, char *pinst) int dest_tkt(void) { - /* Here goes code to destroy tickets in shared memory. */ - /* Not implemented yet. */ - return KFAILURE; + memset(getTktMem(0), 0, sizeof(tktmem)); + return 0; } /* Short description of routines: @@ -265,9 +259,9 @@ tf_get_pname(char *p) if(!(TktStore = getTktMem(0))) return KFAILURE; - if(!TktStore->pname) + if(!TktStore->pname[0]) return KFAILURE; - strcpy(p, TktStore->pname); + strcpy_truncate(p, TktStore->pname, ANAME_SZ); return KSUCCESS; } @@ -283,9 +277,7 @@ tf_put_pname(char *p) if(!(TktStore = getTktMem(0))) return KFAILURE; - if(!TktStore->pname) - return KFAILURE; - strcpy(TktStore->pname, p); + strcpy_truncate(TktStore->pname, p, sizeof(TktStore->pname)); return KSUCCESS; } @@ -306,9 +298,7 @@ tf_get_pinst(char *inst) if(!(TktStore = getTktMem(0))) return KFAILURE; - if(!TktStore->pinst) - return KFAILURE; - strcpy(inst, TktStore->pinst); + strcpy_truncate(inst, TktStore->pinst, INST_SZ); return KSUCCESS; } @@ -324,9 +314,7 @@ tf_put_pinst(char *inst) if(!(TktStore = getTktMem(0))) return KFAILURE; - if(!TktStore->pinst) - return KFAILURE; - strcpy(TktStore->pinst, inst); + strcpy_truncate(TktStore->pinst, inst, sizeof(TktStore->pinst)); return KSUCCESS; } @@ -350,10 +338,11 @@ tf_get_cred(CREDENTIALS *c) if(!(TktStore = getTktMem(0))) return KFAILURE; + krb_set_kdc_time_diff(TktStore->kdc_diff); if((index = nextCredIndex()) == -1) return EOF; if(!(cred = TktStore->cred_vec+index)) - return KFAILURE; + return KFAILURE; if(!c) return KFAILURE; memcpy(c, cred, sizeof(*c)); @@ -402,20 +391,31 @@ tf_save_cred(char *service, /* Service name */ if(last == -1) return KFAILURE; cred = mem->cred_vec+last; - strcpy(cred->service, service); - strcpy(cred->instance, instance); - strcpy(cred->realm, realm); - strcpy(cred->session, session); + strcpy_truncate(cred->service, service, sizeof(cred->service)); + strcpy_truncate(cred->instance, instance, sizeof(cred->instance)); + strcpy_truncate(cred->realm, realm, sizeof(cred->realm)); + memcpy(cred->session, session, sizeof(cred->session)); cred->lifetime = lifetime; cred->kvno = kvno; memcpy(&(cred->ticket_st), ticket, sizeof(*ticket)); cred->issue_date = issue_date; - strcpy(cred->pname, mem->pname); - strcpy(cred->pinst, mem->pinst); + strcpy_truncate(cred->pname, mem->pname, sizeof(cred->pname)); + strcpy_truncate(cred->pinst, mem->pinst, sizeof(cred->pinst)); + PostUpdateMessage(); return KSUCCESS; } +static void +set_time_diff(time_t diff) +{ + tktmem *TktStore = getTktMem(0); + if(TktStore == NULL) + return; + TktStore->kdc_diff = diff; +} + + int tf_setup(CREDENTIALS *cred, char *pname, char *pinst) { @@ -430,6 +430,8 @@ tf_setup(CREDENTIALS *cred, char *pname, char *pinst) return INTK_ERR; } + set_time_diff(krb_get_kdc_time_diff()); + ret = tf_save_cred(cred->service, cred->instance, cred->realm, cred->session, cred->lifetime, cred->kvno, &cred->ticket_st, cred->issue_date); |