/*
- * $Id: volume.c,v 1.33 2002-08-30 19:32:41 didg Exp $
+ * $Id: volume.c,v 1.34 2002-08-31 05:35:10 jmarcus Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
#define VOLOPT_FORCEUID 11 /* force uid for username x */
#define VOLOPT_FORCEGID 12 /* force gid for group x */
-#define VOLOPT_MAX 12
+#define VOLOPT_UMASK 13
+#define VOLOPT_MAX 13
#else /* normally, there are only 9 possible options */
-#define VOLOPT_MAX 10
+#define VOLOPT_UMASK 11
+#define VOLOPT_MAX 11
#endif /* FORCE_UIDGID */
#define VOLOPT_NUM (VOLOPT_MAX + 1)
options[VOLOPT_DBPATH].c_value = strdup(val + 1);
#endif /* CNID_DB */
+ } else if (optionok(tmp, "umask:", val)) {
+ options[VOLOPT_UMASK].i_value = (int)strtol(val, (char **)NULL, 8);
} else if (optionok(tmp, "mapchars:",val)) {
if (options[VOLOPT_MAPCHARS].c_value)
free(options[VOLOPT_MAPCHARS].c_value);
volume->v_dbpath = strdup(options[VOLOPT_DBPATH].c_value);
#endif /* CNID_DB */
+ if (options[VOLOPT_UMASK].i_value)
+ volume->v_umask = (mode_t)options[VOLOPT_UMASK].i_value;
+
#ifdef FORCE_UIDGID
if (options[VOLOPT_FORCEUID].c_value) {
strcat( tmp, "/" );
strcat( tmp, p );
}
+ /* Tag a user's home directory with their umask. Note, this will
+ * be overwritten if the user actually specifies a umask: option
+ * for a '~' volume. */
+ save_options[VOLOPT_UMASK].i_value = obj->options.save_mask;
/* fall through */
case '/' :
#ifdef CNID_DB
if (volume->v_dbpath)
- volume->v_db = cnid_open (volume->v_dbpath);
+ volume->v_db = cnid_open (volume->v_dbpath, volume->v_umask);
if (volume->v_db == NULL)
- volume->v_db = cnid_open (volume->v_path);
+ volume->v_db = cnid_open (volume->v_path, volume->v_umask);
#endif /* CNID_DB */
#ifndef CNID_DB
/*
- * $Id: cnid_open.c,v 1.42 2002-08-30 03:12:52 jmarcus Exp $
+ * $Id: cnid_open.c,v 1.43 2002-08-31 05:35:10 jmarcus Exp $
*
* Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
* All Rights Reserved. See COPYRIGHT.
#endif /* DB_VERSION_MINOR */
}
-void *cnid_open(const char *dir) {
+void *cnid_open(const char *dir, mode_t mask) {
struct stat st, rsb, lsb, csb;
#ifndef CNID_DB_CDB
struct flock lock;
}
strcpy(path + len, DBHOME);
- if ((stat(path, &st) < 0) && (ad_mkdir(path, 0777) < 0)) {
+ if ((stat(path, &st) < 0) && (ad_mkdir(path, 0777 & ~mask) < 0)) {
LOG(log_error, logtype_default, "cnid_open: DBHOME mkdir failed for %s", path);
goto fail_adouble;
}
* to the sahe directory. */
strcat(path, DBLOCKFILE);
strcpy(db->lock_file, path);
- if ((db->lockfd = open(path, O_RDWR | O_CREAT, 0666)) > -1) {
+ if ((db->lockfd = open(path, O_RDWR | O_CREAT, 0666 & ~mask)) > -1) {
lock.l_start = 0;
lock.l_len = 1;
while (fcntl(db->lockfd, F_SETLK, &lock) < 0) {
#endif /* CNID_DB_CDB */
/* Open the database environment. */
- if ((rc = db->dbenv->open(db->dbenv, path, DBOPTIONS, 0666)) != 0) {
+ if ((rc = db->dbenv->open(db->dbenv, path, DBOPTIONS, 0666 & ~mask)) != 0) {
if (rc == DB_RUNRECOVERY) {
/* This is the mother of all errors. We _must_ fail here. */
LOG(log_error, logtype_default, "cnid_open: CATASTROPHIC ERROR opening database environment %s. Run db_recovery -c immediately", path);
/* We can't get a full transactional environment, so multi-access
* is out of the question. Let's assume a read-only environment,
* and try to at least get a shared memory pool. */
- if ((rc = db->dbenv->open(db->dbenv, path, DB_INIT_MPOOL, 0666)) != 0) {
+ if ((rc = db->dbenv->open(db->dbenv, path, DB_INIT_MPOOL, 0666 & ~mask)) != 0) {
/* Nope, not a MPOOL, either. Last-ditch effort: we'll try to
* open the environment with no flags. */
- if ((rc = db->dbenv->open(db->dbenv, path, 0, 0666)) != 0) {
+ if ((rc = db->dbenv->open(db->dbenv, path, 0, 0666 & ~mask)) != 0) {
LOG(log_error, logtype_default, "cnid_open: dbenv->open of %s failed: %s",
path, db_strerror(rc));
goto fail_lock;
/*db->db_didname->set_bt_compare(db->db_didname, &compare_unix);*/
if ((rc = db->db_didname->open(db->db_didname, DBDIDNAME, NULL,
- DB_HASH, open_flag, 0666))) {
+ DB_HASH, open_flag, 0666 & ~mask))) {
LOG(log_error, logtype_default, "cnid_open: Failed to open did/name database: %s",
db_strerror(rc));
goto fail_appinit;
}
db->db_macname->set_bt_compare(db->db_macname, &compare_mac);
- if ((rc = db->db_macname->open(db->db_macname, DBMACNAME, NULL, DB_BTREE, open_flag, 0666)) != 0) {
+ if ((rc = db->db_macname->open(db->db_macname, DBMACNAME, NULL, DB_BTREE, open_flag, 0666 & ~mask)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to open did/macname database: %s",
db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
}
db->db_shortname->set_bt_compare(db->db_shortname, &compare_mac);
- if ((rc = db->db_shortname->open(db->db_shortname, DBSHORTNAME, NULL, DB_BTREE, open_flag, 0666)) != 0) {
+ if ((rc = db->db_shortname->open(db->db_shortname, DBSHORTNAME, NULL, DB_BTREE, open_flag, 0666 & ~mask)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to open did/shortname database: %s",
db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
}
db->db_longname->set_bt_compare(db->db_longname, &compare_unicode);
- if ((rc = db->db_longname->open(db->db_longname, DBLONGNAME, NULL, DB_BTREE, open_flag, 0666)) != 0) {
+ if ((rc = db->db_longname->open(db->db_longname, DBLONGNAME, NULL, DB_BTREE, open_flag, 0666 & ~mask)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to open did/longname database: %s",
db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
goto fail_appinit;
}
- if ((rc = db->db_devino->open(db->db_devino, DBDEVINO, NULL, DB_HASH, open_flag, 0666)) != 0) {
+ if ((rc = db->db_devino->open(db->db_devino, DBDEVINO, NULL, DB_HASH, open_flag, 0666 & ~mask)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to open devino database: %s",
db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
}
- if ((rc = db->db_cnid->open(db->db_cnid, DBCNID, NULL, DB_HASH, open_flag, 0666)) != 0) {
+ if ((rc = db->db_cnid->open(db->db_cnid, DBCNID, NULL, DB_HASH, open_flag, 0666 & ~mask)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to open dev/ino database: %s",
db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
goto fail_appinit;
}
- if ((rc = db->db_mangle->open(db->db_mangle, DBMANGLE, NULL, DB_HASH, open_flag, 0666)) != 0) {
+ if ((rc = db->db_mangle->open(db->db_mangle, DBMANGLE, NULL, DB_HASH, open_flag, 0666 & ~mask)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to open mangle database: %s", db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
db->db_devino->close(db->db_devino, 0);