Initial import from FreeBSD RELENG_4:
[dragonfly.git] / crypto / kerberosIV / lib / krb / save_credentials.c
1 /* 
2   Copyright (C) 1989 by the Massachusetts Institute of Technology
3
4    Export of this software from the United States of America is assumed
5    to require a specific license from the United States Government.
6    It is the responsibility of any person or organization contemplating
7    export to obtain such a license before exporting.
8
9 WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
10 distribute this software and its documentation for any purpose and
11 without fee is hereby granted, provided that the above copyright
12 notice appear in all copies and that both that copyright notice and
13 this permission notice appear in supporting documentation, and that
14 the name of M.I.T. not be used in advertising or publicity pertaining
15 to distribution of the software without specific, written prior
16 permission.  M.I.T. makes no representations about the suitability of
17 this software for any purpose.  It is provided "as is" without express
18 or implied warranty.
19
20   */
21
22 #include "krb_locl.h"
23
24 RCSID("$Id: save_credentials.c,v 1.5 1997/03/23 03:53:17 joda Exp $");
25
26 /*
27  * This routine takes a ticket and associated info and calls
28  * tf_save_cred() to store them in the ticket cache.  The peer
29  * routine for extracting a ticket and associated info from the
30  * ticket cache is krb_get_cred().  When changes are made to
31  * this routine, the corresponding changes should be made
32  * in krb_get_cred() as well.
33  *
34  * Returns KSUCCESS if all goes well, otherwise an error returned
35  * by the tf_init() or tf_save_cred() routines.
36  */
37
38 int
39 save_credentials(char *service, /* Service name */
40                  char *instance, /* Instance */
41                  char *realm,   /* Auth domain */
42                  unsigned char *session, /* Session key */
43                  int lifetime,  /* Lifetime */
44                  int kvno,      /* Key version number */
45                  KTEXT ticket,  /* The ticket itself */
46                  int32_t issue_date) /* The issue time */
47 {
48     int tf_status;   /* return values of the tf_util calls */
49
50     /* Open and lock the ticket file for writing */
51     if ((tf_status = tf_init(TKT_FILE, W_TKT_FIL)) != KSUCCESS)
52         return(tf_status);
53
54     /* Save credentials by appending to the ticket file */
55     tf_status = tf_save_cred(service, instance, realm, session,
56                              lifetime, kvno, ticket, issue_date);
57     tf_close();
58     return (tf_status);
59 }