#define NFSD_DIR "/proc/net/rpc"
#endif
+#ifndef CLIENT_CACHE_TIMEOUT_FILE
+#define CLIENT_CACHE_TIMEOUT_FILE "/proc/sys/fs/nfs/idmap_cache_timeout"
+#endif
+
#ifndef NFS4NOBODY_USER
#define NFS4NOBODY_USER "nobody"
#endif
void release_parent();
static int verbose = 0;
+#define DEFAULT_IDMAP_CACHE_EXPIRY 600 /* seconds */
+static int cache_entry_expiration = 0;
static char pipefsdir[PATH_MAX];
static char *nobodyuser, *nobodygroup;
static uid_t nobodyuid;
if (stat(conf_path, &sb) == -1 && (errno == ENOENT || errno == EACCES)) {
warn("Skipping configuration file \"%s\"", conf_path);
+ conf_path = NULL;
} else {
conf_init();
verbose = conf_get_num("General", "Verbosity", 0);
+ cache_entry_expiration = conf_get_num("General",
+ "Cache-Expiration", DEFAULT_IDMAP_CACHE_EXPIRY);
CONF_SAVE(xpipefsdir, conf_get_str("General", "Pipefs-Directory"));
if (xpipefsdir != NULL)
strlcpy(pipefsdir, xpipefsdir, sizeof(pipefsdir));
CONF_SAVE(nobodyuser, conf_get_str("Mapping", "Nobody-User"));
CONF_SAVE(nobodygroup, conf_get_str("Mapping", "Nobody-Group"));
- nfs4_init_name_mapping(conf_path);
}
while ((opt = getopt(argc, argv, GETOPTSTR)) != -1)
errx(1, "Could not find group \"%s\"", nobodygroup);
nobodygid = gr->gr_gid;
+ nfs4_set_debug(verbose, idmapd_warnx);
+ if (conf_path == NULL)
+ conf_path = _PATH_IDMAPDCONF;
+ if (nfs4_init_name_mapping(conf_path))
+ errx(1, "Unable to create name to user id mappings.");
+
if (!fg)
mydaemon(0, 0);
event_init();
+ if (verbose > 0)
+ idmapd_warnx("Expiration time is %d seconds.",
+ cache_entry_expiration);
if (serverstart) {
nfsdret = nfsdopen();
if (nfsdret == 0) {
.tv_usec = 0,
};
+ if (cache_entry_expiration != DEFAULT_IDMAP_CACHE_EXPIRY) {
+ int timeout_fd, len;
+ char timeout_buf[12];
+ if ((timeout_fd = open(CLIENT_CACHE_TIMEOUT_FILE,
+ O_RDWR)) == -1) {
+ idmapd_warnx("Unable to open '%s' to set "
+ "client cache expiration time "
+ "to %d seconds\n",
+ CLIENT_CACHE_TIMEOUT_FILE,
+ cache_entry_expiration);
+ } else {
+ len = snprintf(timeout_buf, sizeof(timeout_buf),
+ "%d", cache_entry_expiration);
+ if ((write(timeout_fd, timeout_buf, len)) != len)
+ idmapd_warnx("Error writing '%s' to "
+ "'%s' to set client "
+ "cache expiration time\n",
+ timeout_buf,
+ CLIENT_CACHE_TIMEOUT_FILE);
+ close(timeout_fd);
+ }
+ }
+
if ((fd = open(pipefsdir, O_RDONLY)) == -1)
idmapd_err(1, "main: open(%s)", pipefsdir);
if (which != EV_READ)
goto out;
- if ((len = read(ic->ic_fd, buf, sizeof(buf))) == -1) {
+ if ((len = read(ic->ic_fd, buf, sizeof(buf))) <= 0) {
idmapd_warnx("nfsdcb: read(%s) failed: errno %d (%s)",
- ic->ic_path, errno, strerror(errno));
+ ic->ic_path, len?errno:0,
+ len?strerror(errno):"End of File");
goto out;
}
addfield(&bp, &bsiz, p);
/* Name */
addfield(&bp, &bsiz, im.im_name);
-#define NFSD_EXPIRY 300 /* seconds */
/* expiry */
- snprintf(buf1, sizeof(buf1), "%lu", time(NULL) + NFSD_EXPIRY);
+ snprintf(buf1, sizeof(buf1), "%lu",
+ time(NULL) + cache_entry_expiration);
addfield(&bp, &bsiz, buf1);
/* ID */
snprintf(buf1, sizeof(buf1), "%u", im.im_id);
snprintf(buf1, sizeof(buf1), "%u", im.im_id);
addfield(&bp, &bsiz, buf1);
/* expiry */
- snprintf(buf1, sizeof(buf1), "%lu", time(NULL) + NFSD_EXPIRY);
+ snprintf(buf1, sizeof(buf1), "%lu",
+ time(NULL) + cache_entry_expiration);
addfield(&bp, &bsiz, buf1);
/* Name */
addfield(&bp, &bsiz, im.im_name);
idmapd_warnx("ReOpening %s", ic->ic_path);
if ((fd = open(ic->ic_path, O_RDWR, 0)) != -1) {
- if (ic->ic_fd != -1)
- close(ic->ic_fd);
if ((ic->ic_event.ev_flags & EVLIST_INIT))
event_del(&ic->ic_event);
+ if (ic->ic_fd != -1)
+ close(ic->ic_fd);
ic->ic_event.ev_fd = ic->ic_fd = fd;
event_set(&ic->ic_event, ic->ic_fd, EV_READ, nfsdcb, ic);