X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=support%2Fnfs%2Frmtab.c;h=ca789a32c6a8599b07f0c74c0aa531a0b58a661d;hp=b9b5ff1c6ae55f1f6e083309f0706acc127757a2;hb=291b329ad1f5a65270097f4ec3a8dd465df42669;hpb=8b7ad01b14df1e7529b9ba8a1ea17df0d6004ef9 diff --git a/support/nfs/rmtab.c b/support/nfs/rmtab.c index b9b5ff1..ca789a3 100644 --- a/support/nfs/rmtab.c +++ b/support/nfs/rmtab.c @@ -6,7 +6,9 @@ * Copyright (C) 1995, 1996 Olaf Kirch */ -#include "config.h" +#ifdef HAVE_CONFIG_H +#include +#endif #include #include @@ -17,6 +19,18 @@ #include #include "nfslib.h" +/* + * Colons in incoming IPv6 presentation addresses have to + * replaced with another character, since rmtab already + * uses colons to delineate fields. + * + * Use a printable character, but one that would never be + * found in a presentation address or domain name + */ +#define IPV6_COLON ';' + +#define LINELEN (2048) + static FILE *rmfp = NULL; int @@ -45,52 +59,87 @@ fsetrmtabent(char *fname, char *type) } struct rmtabent * -getrmtabent(int log) +getrmtabent(int log, long *pos) { - return fgetrmtabent(rmfp, log); + return fgetrmtabent(rmfp, log, pos); } struct rmtabent * -fgetrmtabent(FILE *fp, int log) +fgetrmtabent(FILE *fp, int log, long *pos) { static struct rmtabent re; - char buf[2048], *sp; + char *count, *host, *path, *c; + static char buf[LINELEN]; errno = 0; if (!fp) return NULL; do { + if (pos) + *pos = ftell (fp); if (fgets(buf, sizeof(buf)-1, fp) == NULL) return NULL; - if ((sp = strchr(buf, '\n')) != NULL) - *sp = '\0'; - if (!(sp = strchr(buf, ':'))) { + host = buf; + if ((path = strchr(host, '\n')) != NULL) + *path = '\0'; + if (!(path = strchr(host, ':'))) { if (log) xlog(L_ERROR, "malformed entry in rmtab file"); errno = EINVAL; return NULL; } - *sp++ = '\0'; + *path++ = '\0'; + count = strchr(path, ':'); + if (count) { + *count++ = '\0'; + re.r_count = strtol (count, NULL, 0); + } + else + re.r_count = 1; } while (0); - strncpy(re.r_client, buf, sizeof (re.r_client) - 1); + + strncpy(re.r_client, host, sizeof (re.r_client) - 1); re.r_client[sizeof (re.r_client) - 1] = '\0'; - strncpy(re.r_path, sp, sizeof (re.r_path) - 1); + for (c = re.r_client; *c != '\0'; c++) + if (*c == IPV6_COLON) + *c = ':'; + + strncpy(re.r_path, path, sizeof (re.r_path) - 1); re.r_path[sizeof (re.r_path) - 1] = '\0'; + return &re; } void -putrmtabent(struct rmtabent *rep) +putrmtabent(struct rmtabent *rep, long *pos) { - fputrmtabent(rmfp, rep); + fputrmtabent(rmfp, rep, pos); } void -fputrmtabent(FILE *fp, struct rmtabent *rep) +fputrmtabent(FILE *fp, struct rmtabent *rep, long *pos) { - if (!fp) + static char buf[LINELEN]; + char *c; + + if (!fp || (pos && fseek (fp, *pos, SEEK_SET) != 0)) + return; + + /* + * To avoid confusing the token parser in fgetrmtabent(), + * convert colons in incoming IPv6 presentation addresses + * to semicolons. + */ + if (strlen(rep->r_client) > sizeof(buf)) { + xlog(L_ERROR, "client name too large"); return; - fprintf(fp, "%s:%s\n", rep->r_client, rep->r_path); + } + strncpy(buf, rep->r_client, sizeof(buf)); + for (c = buf; *c != '\0'; c++) + if (*c == ':') + *c = IPV6_COLON; + + (void)fprintf(fp, "%s:%s:0x%.8x\n", buf, rep->r_path, rep->r_count); } void @@ -103,8 +152,27 @@ endrmtabent(void) void fendrmtabent(FILE *fp) { - if (fp) + if (fp) { + static int have_new_cache = -1; + if (have_new_cache == -1) /* check only once */ + have_new_cache = check_new_cache(); + + if (!have_new_cache) { + /* + * If we are using the old caching interface: exportfs + * uses the rmtab to determine what should be exported, + * so it is important that it be up-to-date. + * + * If we are using the new caching interface: the rmtab + * is ignored by exportfs and the fdatasync only serves + * to slow us down. + */ + fflush(fp); + fdatasync(fileno(fp)); + } + fclose(fp); + } } void