* Use PATH_FSTAB instead of hard-coded value.
* Change function name in dump(8) that was conflicting.
Obtained-from: FreeBSD
* SUCH DAMAGE.
*
* @(#)fstab.h 8.1 (Berkeley) 6/2/93
+ * $FreeBSD: src/include/fstab.h,v 1.4 2003/04/07 12:54:59 mdodd Exp $
* $DragonFly: src/include/fstab.h,v 1.2 2003/11/14 01:01:43 dillon Exp $
*/
#include <sys/cdefs.h>
__BEGIN_DECLS
-struct fstab *getfsent (void);
-struct fstab *getfsspec (const char *);
-struct fstab *getfsfile (const char *);
-int setfsent (void);
-void endfsent (void);
+void endfsent(void);
+struct fstab *getfsent(void);
+struct fstab *getfsfile(const char *);
+struct fstab *getfsspec(const char *);
+const char *getfstab(void);
+int setfsent(void);
+void setfstab(const char *);
__END_DECLS
#endif /* !_FSTAB_H_ */
MLINKS+=getcwd.3 getwd.3
MLINKS+=getdomainname.3 setdomainname.3
MLINKS+=getfsent.3 endfsent.3 getfsent.3 getfsfile.3 getfsent.3 getfsspec.3 \
- getfsent.3 getfstype.3 getfsent.3 setfsent.3
+ getfsent.3 getfstab.3 getfsent.3 getfstype.3 getfsent.3 setfsent.3 \
+ getfsent.3 setfstab.3
MLINKS+=getgrent.3 endgrent.3 getgrent.3 getgrgid.3 getgrent.3 getgrnam.3 \
getgrent.3 setgrent.3 getgrent.3 setgroupent.3
MLINKS+=gethostname.3 sethostname.3
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: src/lib/libc/gen/fstab.c,v 1.8 2000/01/27 23:06:15 jasone Exp $
- * $DragonFly: src/lib/libc/gen/fstab.c,v 1.6 2005/11/13 00:07:42 swildner Exp $
- *
* @(#)fstab.c 8.1 (Berkeley) 6/4/93
- * $FreeBSD: src/lib/libc/gen/fstab.c,v 1.8 2000/01/27 23:06:15 jasone Exp $
+ * $FreeBSD: src/lib/libc/gen/fstab.c,v 1.15 2007/01/09 00:27:53 imp Exp $
+ * $DragonFly: src/lib/libc/gen/fstab.c,v 1.6 2005/11/13 00:07:42 swildner Exp $
*/
#include "namespace.h"
static FILE *_fs_fp;
static struct fstab _fs_fstab;
static int LineNo = 0;
+static char *path_fstab;
+static char fstab_path[PATH_MAX];
+static int fsp_set = 0;
+
+static void error(int);
+static void fixfsfile(void);
+static int fstabscan(void);
+
+void
+setfstab(const char *file)
+{
+
+ if (file == NULL) {
+ path_fstab = _PATH_FSTAB;
+ } else {
+ strncpy(fstab_path, file, PATH_MAX);
+ fstab_path[PATH_MAX - 1] = '\0';
+ path_fstab = fstab_path;
+ }
+ fsp_set = 1;
+}
+
+const char *
+getfstab(void)
+{
-static void error (int);
-static void fixfsfile (void);
-static int fstabscan (void);
+ if (fsp_set)
+ return (path_fstab);
+ else
+ return (_PATH_FSTAB);
+}
static void
fixfsfile(void)
return((struct fstab *)NULL);
}
-int
+int
setfsent(void)
{
if (_fs_fp) {
LineNo = 0;
return(1);
}
- if ((_fs_fp = fopen(_PATH_FSTAB, "r")) != NULL) {
+ if (fsp_set == 0) {
+ if (issetugid())
+ setfstab(NULL);
+ else
+ setfstab(getenv("PATH_FSTAB"));
+ }
+ if ((_fs_fp = fopen(path_fstab, "r")) != NULL) {
LineNo = 0;
return(1);
}
fclose(_fs_fp);
_fs_fp = NULL;
}
+
+ fsp_set = 0;
}
static void
char num[30];
_write(STDERR_FILENO, "fstab: ", 7);
- _write(STDERR_FILENO, _PATH_FSTAB, sizeof(_PATH_FSTAB) - 1);
+ _write(STDERR_FILENO, path_fstab, strlen(path_fstab));
_write(STDERR_FILENO, ":", 1);
sprintf(num, "%d: ", LineNo);
_write(STDERR_FILENO, num, strlen(num));
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\" SUCH DAMAGE.
.\"
.\" @(#)getfsent.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/gen/getfsent.3,v 1.5.2.4 2001/12/14 18:33:51 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/getfsent.3,v 1.17 2007/01/09 00:27:53 imp Exp $
.\" $DragonFly: src/lib/libc/gen/getfsent.3,v 1.3 2006/05/26 19:39:36 swildner Exp $
.\"
-.Dd June 4, 1993
+.Dd April 7, 2003
.Dt GETFSENT 3
.Os
.Sh NAME
.Nm getfsspec ,
.Nm getfsfile ,
.Nm setfsent ,
-.Nm endfsent
+.Nm endfsent ,
+.Nm setfstab ,
+.Nm getfstab
.Nd get file system descriptor file entry
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In fstab.h
-.Ft struct fstab *
+.Ft "struct fstab *"
.Fn getfsent void
-.Ft struct fstab *
+.Ft "struct fstab *"
.Fn getfsspec "const char *spec"
-.Ft struct fstab *
+.Ft "struct fstab *"
.Fn getfsfile "const char *file"
.Ft int
.Fn setfsent void
.Ft void
.Fn endfsent void
+.Ft void
+.Fn setfstab "const char *file"
+.Ft "const char *"
+.Fn getfstab void
.Sh DESCRIPTION
The
.Fn getfsent ,
closes the file.
.Pp
The
+.Fn setfstab
+function sets the file to be used by subsequent operations.
+The value set by
+.Fn setfstab
+does not persist across calls to
+.Fn endfsent .
+.Pp
+The
+.Fn getfstab
+function returns the name of the file that will be used.
+.Pp
+The
.Fn getfsspec
and
.Fn getfsfile
.Fn endfsent
function
returns nothing.
+.Sh ENVIRONMENT
+.Bl -tag -width ".Ev PATH_FSTAB"
+.It Ev PATH_FSTAB
+If the environment variable
+.Ev PATH_FSTAB
+is set, all operations are performed against the specified file.
+.Ev PATH_FSTAB
+will not be honored if the process environment or memory address space is
+considered
+.Dq tainted .
+(See
+.Xr issetugid 2
+for more information.)
+.El
.Sh FILES
.Bl -tag -width /etc/fstab -compact
.It Pa /etc/fstab
and
.Fn setfsent
functions appeared in
-.Bx 4.3 .
+.Bx 4.3 ;
+the
+.Fn setfstab
+and
+.Fn getfstab
+functions appeared in
+.Fx 5.1 .
.Sh BUGS
These functions use static data storage;
if the data is needed for future use, it should be
void Exit(int) __dead2;
void dumpabort(int);
-void getfstab(void);
+void dump_getfstab(void);
char *rawname(char *);
struct ufs1_dinode *getino(ufs1_ino_t);
if (signal(SIGINT, interrupt) == SIG_IGN)
signal(SIGINT, SIG_IGN);
- getfstab(); /* /etc/fstab snarfed */
+ dump_getfstab(); /* /etc/fstab snarfed */
/*
* disk can be either the full special file name,
* the suffix of the special file name,
static SLIST_HEAD(, pfstab) table;
void
-getfstab(void)
+dump_getfstab(void)
{
struct fstab *fs;
struct pfstab *pf;
struct tm *tlast;
time(&tnow);
- getfstab(); /* /etc/fstab input */
+ dump_getfstab(); /* /etc/fstab input */
initdumptimes(); /* /etc/dumpdates input */
qsort(ddatev, nddates, sizeof(struct dumpdates *), datesort);