summaryrefslogtreecommitdiffstats
path: root/usr.bin/rdistd
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2014-07-05 10:21:24 +0000
committerguenther <guenther@openbsd.org>2014-07-05 10:21:24 +0000
commita59aa42107d795bafdf48fa39777c34d060f8d58 (patch)
tree30e5d96efa99ec95be61a1eb49f6085acf385f95 /usr.bin/rdistd
parentGiven an http or https URL with user and password, URL-decode the user (diff)
downloadwireguard-openbsd-a59aa42107d795bafdf48fa39777c34d060f8d58.tar.xz
wireguard-openbsd-a59aa42107d795bafdf48fa39777c34d060f8d58.zip
Assume we have getfsstat(); simplify the interface to the *mountent()
wrappers
Diffstat (limited to 'usr.bin/rdistd')
-rw-r--r--usr.bin/rdistd/filesys-os.c294
-rw-r--r--usr.bin/rdistd/filesys.c17
2 files changed, 31 insertions, 280 deletions
diff --git a/usr.bin/rdistd/filesys-os.c b/usr.bin/rdistd/filesys-os.c
index 33e2092ca4b..8558094a60a 100644
--- a/usr.bin/rdistd/filesys-os.c
+++ b/usr.bin/rdistd/filesys-os.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: filesys-os.c,v 1.10 2009/10/27 23:59:42 deraadt Exp $ */
+/* $OpenBSD: filesys-os.c,v 1.11 2014/07/05 10:21:24 guenther Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@@ -29,144 +29,59 @@
* SUCH DAMAGE.
*/
+#include <sys/param.h>
+#include <sys/mount.h>
+
#include "defs.h"
/*
* OS specific file system routines
*/
-#if FSI_TYPE == FSI_GETFSSTAT
static struct statfs *mnt = NULL;
-#endif /* FSI_GETFSSTAT */
-
-#if FSI_TYPE == FSI_MNTCTL
-static struct vmount *mnt = NULL;
-#endif /* FSI_MNTCTL */
-
-#if (FSI_TYPE == FSI_MNTCTL) || (FSI_TYPE == FSI_GETFSSTAT)
-static char *mntbuf = NULL;
static int entries_left;
-#endif /* FSI_MNTCTL || FSI_GETFSSTAT */
-
-#if FSI_TYPE == FSI_MNTCTL
-/*
- * AIX version of setmountent()
- */
-FILE *
-setmountent(const char *file, const char *mode)
-{
- ulong size;
- if (mntbuf)
- (void) free(mntbuf);
-
- mntctl(MCTL_QUERY, sizeof(size), &size);
- mntbuf = (char *) xmalloc(size);
-
- entries_left = mntctl(MCTL_QUERY, size, mntbuf);
- if (!entries_left)
- return(NULL);
-
- mnt = (struct vmount *)mntbuf;
- return((FILE *) 1);
-}
-#endif /* FSI_MNTCTL */
-
-#if FSI_TYPE == FSI_GETFSSTAT
/*
* getfsstat() version of get mount info routines.
*/
-FILE *
-setmountent(const char *file, const char *mode)
+int
+setmountent(void)
{
long size;
- if (mntbuf)
- (void) free(mntbuf);
-
size = getfsstat(NULL, 0, MNT_WAIT);
if (size == -1)
- return (NULL);
+ return (0);
+
+ free(mnt);
size *= sizeof(struct statfs);
- mntbuf = (char *) xmalloc(size);
+ mnt = xmalloc(size);
- entries_left = getfsstat((struct statfs *)mntbuf, size, MNT_WAIT);
+ entries_left = getfsstat(mnt, size, MNT_WAIT);
if (entries_left == -1)
- return(NULL);
+ return (0);
- mnt = (struct statfs *) mntbuf;
-
- return((FILE *) 1);
+ return (1);
}
-#endif /* FSI_GETFSSTAT */
-#if FSI_TYPE == FSI_MNTCTL
-/*
- * AIX version of getmountent()
- */
-/*
- * Iterate over mount entries
- */
-mntent_t *
-getmountent(FILE *fptr)
-{
- static mntent_t mntstruct;
-
- if (!entries_left)
- return((mntent_t*)0);
-
- bzero((char *) &mntstruct, sizeof(mntstruct));
-
- if (mnt->vmt_flags & MNT_READONLY)
- mntstruct.me_flags |= MEFLAG_READONLY;
-
- mntstruct.me_path = vmt2dataptr(mnt, VMT_STUB);
- switch ((ulong)(struct vmount*)mnt->vmt_gfstype) {
- case MNT_NFS:
- mntstruct.me_type = METYPE_NFS;
- break;
- default:
- mntstruct.me_type = METYPE_OTHER;
- break;
- }
-
- mnt = (struct vmount*)((mnt->vmt_length)+(char *)mnt);
- entries_left--;
-
- return(&mntstruct);
-}
-#endif /* FSI_MNTCTL */
-
-#if FSI_TYPE == FSI_GETFSSTAT
/*
* getfsstat() version of getmountent()
*/
mntent_t *
-getmountent(FILE *fptr)
+getmountent(void)
{
static mntent_t mntstruct;
static char remote_dev[MAXHOSTNAMELEN+MAXPATHLEN+1];
if (!entries_left)
- return((mntent_t*)0);
+ return (NULL);
- bzero((char *) &mntstruct, sizeof(mntstruct));
+ memset(&mntstruct, 0, sizeof(mntstruct));
-#if defined(MNT_RDONLY)
if (mnt->f_flags & MNT_RDONLY)
mntstruct.me_flags |= MEFLAG_READONLY;
-#endif
-#if defined(M_RDONLY)
- if (mnt->f_flags & M_RDONLY)
- mntstruct.me_flags |= MEFLAG_READONLY;
-#endif
-#ifdef HAVE_FSTYPENAME
- if (strcmp(mnt->f_fstypename, "nfs") == 0)
-#else
- if (mnt->f_type == MOUNT_NFS)
-#endif /* HAVE_FSTYPENAME */
- {
+ if (strcmp(mnt->f_fstypename, "nfs") == 0) {
strlcpy(remote_dev, mnt->f_mntfromname, sizeof(remote_dev));
mntstruct.me_path = remote_dev;
mntstruct.me_type = METYPE_NFS;
@@ -178,182 +93,20 @@ getmountent(FILE *fptr)
mnt++;
entries_left--;
- return(&mntstruct);
+ return (&mntstruct);
}
-#endif
-#if (FSI_TYPE == FSI_MNTCTL) || (FSI_TYPE == FSI_GETFSSTAT)
/*
* Done with iterations
*/
void
-endmountent(FILE *fptr)
+endmountent(void)
{
+ free(mnt);
mnt = NULL;
-
- if (mntbuf) {
- (void) free(mntbuf);
- mntbuf = NULL;
- }
-}
-#endif /* FSI_MNTCTL || FSI_GETFSSTAT */
-
-#if FSI_TYPE == FSI_GETMNTENT2
-/*
- * Prepare to iterate over mounted filesystem list
- */
-FILE *
-setmountent(const char *file, const char *mode)
-{
- return(fopen(file, mode));
-}
-
-/*
- * Done with iteration
- */
-void
-endmountent(FILE *fptr)
-{
- fclose(fptr);
-}
-
-/*
- * Iterate over mount entries
- */
-mntent_t *
-getmountent(FILE *fptr)
-{
- static mntent_t me;
- static struct mnttab mntent;
-
- bzero((char *)&me, sizeof(mntent_t));
-
-#if defined(UNICOS)
- if (getmntent(fptr, &mntent) != NULL) {
-#else
- if (getmntent(fptr, &mntent) != -1) {
-#endif
- me.me_path = mntent.mnt_mountp;
- me.me_type = mntent.mnt_fstype;
- if (mntent.mnt_mntopts && hasmntopt(&mntent, MNTOPT_RO))
- me.me_flags |= MEFLAG_READONLY;
-
-#if defined(MNTTYPE_IGNORE)
- if (strcmp(mntent.mnt_fstype, MNTTYPE_IGNORE) == 0)
- me.me_flags |= MEFLAG_IGNORE;
-#endif /* MNTTYPE_IGNORE */
-#if defined(MNTTYPE_SWAP)
- if (strcmp(mntent.mnt_fstype, MNTTYPE_SWAP) == 0)
- me.me_flags |= MEFLAG_IGNORE;
-#endif /* MNTTYPE_SWAP */
-
- return(&me);
- } else
- return(NULL);
-}
-#endif /* FSI_GETMNTNET2 */
-
-#if FSI_TYPE == FSI_GETMNTENT
-/*
- * Prepare to iterate over mounted filesystem list
- */
-FILE *
-setmountent(const char *file, const char *mode)
-{
- return(setmntent(file, mode));
}
/*
- * Done with iteration
- */
-void
-endmountent(FILE *fptr)
-{
- endmntent(fptr);
-}
-
-/*
- * Iterate over mount entries
- */
-mntent_t *
-getmountent(FILE *fptr)
-{
- static mntent_t me;
- struct mntent *mntent;
-
- bzero((char *)&me, sizeof(mntent_t));
-
- if ((mntent = getmntent(fptr)) != NULL) {
- me.me_path = mntent->mnt_dir;
- me.me_type = mntent->mnt_type;
- if (mntent->mnt_opts && hasmntopt(mntent, MNTOPT_RO))
- me.me_flags |= MEFLAG_READONLY;
-
-#if defined(MNTTYPE_IGNORE)
- if (strcmp(mntent->mnt_type, MNTTYPE_IGNORE) == 0)
- me.me_flags |= MEFLAG_IGNORE;
-#endif /* MNTTYPE_IGNORE */
-#if defined(MNTTYPE_SWAP)
- if (strcmp(mntent->mnt_type, MNTTYPE_SWAP) == 0)
- me.me_flags |= MEFLAG_IGNORE;
-#endif /* MNTTYPE_SWAP */
-
- return(&me);
- } else
- return(NULL);
-}
-#endif /* FSI_GETMNTNET */
-
-#if FSI_TYPE == FSI_GETMNT
-/*
- * getmnt() interface (Ultrix)
- */
-
-#include <sys/fs_types.h>
-
-static int startmounts = 0;
-
-FILE *
-setmountent(const char *file, const char *mode)
-{
- startmounts = 0;
- return((FILE *) 1);
-}
-
-void
-endmountent(FILE *fptr)
-{
- /* NOOP */
-}
-
-/*
- * Iterate over mounted filesystems using getmnt()
- */
-mntent_t *
-getmountent(FILE *fptr)
-{
- struct fs_data fs_data;
- static mntent_t me;
-
- if (getmnt(&startmounts, &fs_data, sizeof(fs_data), NOSTAT_MANY,
- NULL) <= 0)
- return(NULL);
-
- bzero((char *)&me, sizeof(mntent_t));
- me.me_path = fs_data.fd_path;
- if (fs_data.fd_fstype == GT_NFS)
- me.me_type = METYPE_NFS;
- else
- me.me_type = METYPE_OTHER;
-
- if (fs_data.fd_flags & M_RONLY)
- me.me_flags |= MEFLAG_READONLY;
-
- return(&me);
-}
-#endif /* FSI_GETMNT */
-
-/*
* Make a new (copy) of a mntent structure.
*/
mntent_t *
@@ -361,13 +114,10 @@ newmountent(const mntent_t *old)
{
mntent_t *new;
- if (!old)
- return(NULL);
-
- new = (mntent_t *) xcalloc(1, sizeof(mntent_t));
+ new = xmalloc(sizeof *new);
new->me_path = xstrdup(old->me_path);
new->me_type = xstrdup(old->me_type);
new->me_flags = old->me_flags;
- return(new);
+ return (new);
}
diff --git a/usr.bin/rdistd/filesys.c b/usr.bin/rdistd/filesys.c
index f13e6343d43..d827590995c 100644
--- a/usr.bin/rdistd/filesys.c
+++ b/usr.bin/rdistd/filesys.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: filesys.c,v 1.14 2014/07/05 07:58:41 guenther Exp $ */
+/* $OpenBSD: filesys.c,v 1.15 2014/07/05 10:21:24 guenther Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@@ -29,6 +29,9 @@
* SUCH DAMAGE.
*/
+#include <sys/param.h>
+#include <sys/mount.h>
+
#include "defs.h"
/*
@@ -207,16 +210,14 @@ wakeup(int dummy)
struct mntinfo *
makemntinfo(struct mntinfo *mi)
{
- FILE *mfp;
static struct mntinfo *mntinfo;
struct mntinfo *newmi, *m;
struct stat mntstat;
mntent_t *mnt;
int timeo = 310;
- if (!(mfp = setmountent(MOUNTED_FILE, "r"))) {
- message(MT_NERROR, "%s: setmntent failed: %s",
- MOUNTED_FILE, SYSERR);
+ if (setmountent()) {
+ message(MT_NERROR, "setmntent failed: %s", SYSERR);
return(NULL);
}
@@ -228,7 +229,7 @@ makemntinfo(struct mntinfo *mi)
}
mntinfo = mi;
- while ((mnt = getmountent(mfp)) != NULL) {
+ while ((mnt = getmountent()) != NULL) {
debugmsg(DM_MISC, "mountent = '%s' (%s)",
mnt->me_path, mnt->me_type);
@@ -268,8 +269,8 @@ makemntinfo(struct mntinfo *mi)
mntinfo = newmi;
}
- (void) alarm(0);
- (void) endmountent(mfp);
+ alarm(0);
+ endmountent();
return(mntinfo);
}