From 8b7ad01b14df1e7529b9ba8a1ea17df0d6004ef9 Mon Sep 17 00:00:00 2001 From: hjl Date: Mon, 18 Oct 1999 23:21:12 +0000 Subject: Initial revision --- support/nfs/rmtab.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 support/nfs/rmtab.c (limited to 'support/nfs/rmtab.c') diff --git a/support/nfs/rmtab.c b/support/nfs/rmtab.c new file mode 100644 index 0000000..b9b5ff1 --- /dev/null +++ b/support/nfs/rmtab.c @@ -0,0 +1,122 @@ +/* + * support/nfs/rmtab.c + * + * Handling for rmtab. + * + * Copyright (C) 1995, 1996 Olaf Kirch + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include "nfslib.h" + +static FILE *rmfp = NULL; + +int +setrmtabent(char *type) +{ + if (rmfp) + fclose(rmfp); + rmfp = fsetrmtabent(_PATH_RMTAB, type); + return (rmfp != NULL); +} + +FILE * +fsetrmtabent(char *fname, char *type) +{ + int readonly = !strcmp(type, "r"); + FILE *fp; + + if (!fname) + return NULL; + if ((fp = fopen(fname, type)) == NULL) { + xlog(L_ERROR, "can't open %s for %sing", fname, + readonly ? "read" : "writ"); + return NULL; + } + return fp; +} + +struct rmtabent * +getrmtabent(int log) +{ + return fgetrmtabent(rmfp, log); +} + +struct rmtabent * +fgetrmtabent(FILE *fp, int log) +{ + static struct rmtabent re; + char buf[2048], *sp; + + errno = 0; + if (!fp) + return NULL; + do { + if (fgets(buf, sizeof(buf)-1, fp) == NULL) + return NULL; + if ((sp = strchr(buf, '\n')) != NULL) + *sp = '\0'; + if (!(sp = strchr(buf, ':'))) { + if (log) + xlog(L_ERROR, "malformed entry in rmtab file"); + errno = EINVAL; + return NULL; + } + *sp++ = '\0'; + } while (0); + strncpy(re.r_client, buf, sizeof (re.r_client) - 1); + re.r_client[sizeof (re.r_client) - 1] = '\0'; + strncpy(re.r_path, sp, sizeof (re.r_path) - 1); + re.r_path[sizeof (re.r_path) - 1] = '\0'; + return &re; +} + +void +putrmtabent(struct rmtabent *rep) +{ + fputrmtabent(rmfp, rep); +} + +void +fputrmtabent(FILE *fp, struct rmtabent *rep) +{ + if (!fp) + return; + fprintf(fp, "%s:%s\n", rep->r_client, rep->r_path); +} + +void +endrmtabent(void) +{ + fendrmtabent(rmfp); + rmfp = NULL; +} + +void +fendrmtabent(FILE *fp) +{ + if (fp) + fclose(fp); +} + +void +rewindrmtabent(void) +{ + if (rmfp) + rewind(rmfp); +} + +void +frewindrmtabent(FILE *fp) +{ + if (fp) + rewind (fp); +} -- cgit