summaryrefslogtreecommitdiffstats
path: root/src/lib/krb5/ccache/file/fcc_init.c
blob: a422505e1b0f9906eb7d077d3456c780cef22ab2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * $Source$
 * $Author$
 *
 * Copyright 1990 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <krb5/copyright.h>.
 *
 * This file contains the source code for krb5_fcc_initialize.
 */

#if !defined(lint) && !defined(SABER)
static char fcc_init_c[] = "$Id$";
#endif /* !lint && !SABER */

#include <krb5/copyright.h>

#include "fcc.h"

/*
 * Modifies:
 * id
 *
 * Effects:
 * Creates/refreshes the file cred cache id.  If the cache exists, its
 * contents ae destroyed.
 *
 * Errors:
 * system errors
 * permission errors
 */
krb5_error_code
krb5_fcc_initialize(id, princ)
   krb5_ccache id;
   krb5_principal princ;
{
     int ret;

     ret = open(((krb5_fcc_data *) id->data)->filename, O_CREAT | O_TRUNC |
		O_RDWR, 0);
     if (ret < 0)
	  return errno;
     ((krb5_fcc_data *) id->data)->fd = ret;

     ret = fchmod(((krb5_fcc_data *) id->data)->fd, S_IREAD | S_IWRITE);
     if (ret == -1)
	  return ret;

     krb5_fcc_store_principal(id, princ);

     if (OPENCLOSE(id)) {
	  close(((krb5_fcc_data *) id->data)->fd);
	  ((krb5_fcc_data *) id->data)->fd = -1;
     }
     return KRB5_OK;
}