4 * static idmapping functions for gss principals.
6 * Copyright (c) 2008 David Härdeman <david@hardeman.nu>.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <sys/types.h>
45 #include "nfsidmap_internal.h"
48 * Static Translation Methods
50 * These functions use getpwnam to find uid/gid(s) for gss principals
51 * which are first mapped to local user names using static mappings
60 static struct passwd
*static_getpwnam(const char *name
, const char *domain
,
65 size_t buflen
= sysconf(_SC_GETPW_R_SIZE_MAX
);
69 buf
= malloc(sizeof(*buf
) + buflen
);
75 localname
= conf_get_str("Static", (char *)name
);
81 IDMAP_LOG(4, ("static_getpwnam: name '%s' mapped to '%s'\n",
85 err
= getpwnam_r(localname
, &buf
->pwbuf
, buf
->buf
, buflen
, &pw
);
94 IDMAP_LOG(0, ("static_getpwnam: name '%s' not found\n",
110 static int static_gss_princ_to_ids(char *secname
, char *princ
,
111 uid_t
*uid
, uid_t
*gid
,
112 extra_mapping_params
**ex
)
117 /* XXX: Is this necessary? */
118 if (strcmp(secname
, "krb5") != 0 && strcmp(secname
, "spkm3") != 0)
121 pw
= static_getpwnam(princ
, NULL
, &err
);
132 static int static_gss_princ_to_grouplist(char *secname
, char *princ
,
133 gid_t
*groups
, int *ngroups
,
134 extra_mapping_params
**ex
)
139 /* XXX: Is this necessary? */
140 if (strcmp(secname
, "krb5") != 0 && strcmp(secname
, "spkm3") != 0)
143 pw
= static_getpwnam(princ
, NULL
, &err
);
146 if (getgrouplist(pw
->pw_name
, pw
->pw_gid
, groups
, ngroups
) < 0)
155 struct trans_func static_trans
= {
162 .princ_to_ids
= static_gss_princ_to_ids
,
163 .gss_princ_to_grouplist
= static_gss_princ_to_grouplist
,
166 struct trans_func
*libnfsidmap_plugin_init()
168 return (&static_trans
);