~ubuntu-branches/debian/experimental/nfs-utils/experimental

« back to all changes in this revision

Viewing changes to support/nfs/keytab.c

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2006-07-08 14:26:40 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060708142640-r171kjj2a13gy2kz
Tags: 1:1.0.9-1
* Updated co-mantainer mail address.
* New upstream release.
  - Added 'mount.nfs' utility which can be used as a mount helper
    to mount nfs filesystems. It does not yet support 'user' mounts.
  - Makefile/autoconf tidyups
  - No compiles with no warnings
  - deleted debian/* at request of debian maintainer
  - deleted assorted other unused files
  - mountd can be run multi-threaded for configurations with many hundreds
    of clients (mountd -t 20).  Default is single-threaded
  - Support for selection NFS version to be exported, and protocol to
    use.  This requires kernel patches that should be in linux 2.6.19.
  - Use 65534 rather than -2 for default anon.  This makes no difference in many
    cases, but is important in some.
  - New utility 'rpcdebug' for controlled kernel 'debug' options for nfs and nfsd.
  - nfsstat reports NFSv4 operation statistics that should be available in
    linux 2.6.18.
  - assorted other fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * support/nfs/keytab.c
3
 
 *
4
 
 * Manage the nfskeys database.
5
 
 *
6
 
 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
7
 
 */
8
 
 
9
 
#include "config.h"
10
 
 
11
 
#include <string.h>
12
 
#include <stdlib.h>
13
 
#include <stdio.h>
14
 
#include <syslog.h>
15
 
#include <ctype.h>
16
 
#include "xmalloc.h"
17
 
#include "nfslib.h"
18
 
#include "exportfs.h"
19
 
#include "xio.h"
20
 
 
21
 
static FILE     *cfp = NULL;
22
 
 
23
 
int
24
 
setnfskeyent(char *fname)
25
 
{
26
 
        if (cfp)
27
 
                fclose(cfp);
28
 
        if (!fname)
29
 
                fname = _PATH_NFSKEYS;
30
 
        cfp = fsetnfskeyent(fname, "r");
31
 
        return cfp != NULL;
32
 
}
33
 
 
34
 
FILE *
35
 
fsetnfskeyent(char *fname, char *type)
36
 
{
37
 
#if 0
38
 
        FILE    *fp;
39
 
 
40
 
        if ((fp = fopen(fname, type)) == NULL)
41
 
                xlog(L_ERROR, "can't open %s for %sing\n",
42
 
                                fname, type[0] == 'r'? "read" : "writ");
43
 
        return fp;
44
 
#else
45
 
        return fopen(fname, type);
46
 
#endif
47
 
}
48
 
 
49
 
struct nfskeyent *
50
 
getnfskeyent(void)
51
 
{
52
 
        return fgetnfskeyent(cfp);
53
 
}
54
 
 
55
 
struct nfskeyent *
56
 
fgetnfskeyent(FILE *fp)
57
 
{
58
 
        static struct nfskeyent ke;
59
 
 
60
 
        if (!fp)
61
 
                return NULL;
62
 
 
63
 
        do {
64
 
                if (fread(&ke, sizeof(ke), 1, fp) != 1)
65
 
                        return NULL;
66
 
        } while(ke.k_hostname[0] == '\0');
67
 
        return &ke;
68
 
}
69
 
 
70
 
void
71
 
endnfskeyent(void)
72
 
{
73
 
        if (cfp)
74
 
                fclose(cfp);
75
 
        cfp = NULL;
76
 
}
77
 
 
78
 
void
79
 
fendnfskeyent(FILE *fp)
80
 
{
81
 
        if (fp)
82
 
                fclose(fp);
83
 
}
84
 
 
85
 
void
86
 
fputnfskeyent(FILE *fp, struct nfskeyent *kep)
87
 
{
88
 
        fwrite(kep, sizeof(*kep), 1, fp);
89
 
}
90
 
 
91
 
int
92
 
getnfskeytype(char *st)
93
 
{
94
 
        if (!strcasecmp(st, "null"))
95
 
                return CLE_KEY_NULL;
96
 
        if (!strcasecmp(st, "md5"))
97
 
                return CLE_KEY_MD5;
98
 
        if (!strcasecmp(st, "sha"))
99
 
                return CLE_KEY_SHA;
100
 
        return CLE_KEY_NONE;
101
 
}
102
 
 
103
 
char *
104
 
getnfskeyname(int type)
105
 
{
106
 
        switch (type) {
107
 
        case CLE_KEY_NONE:
108
 
                return "none";
109
 
        case CLE_KEY_NULL:
110
 
                return "null";
111
 
        case CLE_KEY_MD5:
112
 
                return "md5";
113
 
        case CLE_KEY_SHA:
114
 
                return "sha";
115
 
        }
116
 
        return "unk";
117
 
}
118
 
 
119
 
int
120
 
getnfskeysize(int type)
121
 
{
122
 
        switch (type) {
123
 
        case CLE_KEY_MD5:
124
 
                return 16;
125
 
        case CLE_KEY_SHA:
126
 
                return 20;
127
 
        }
128
 
        return 0;
129
 
}