+/*
+ * Append the given flavor to the exportent's e_secinfo array, or
+ * do nothing if it's already there. Returns the index of flavor
+ * in the resulting array in any case.
+ */
+static int secinfo_addflavor(struct flav_info *flav, struct exportent *ep)
+{
+ struct sec_entry *p;
+
+ for (p=ep->e_secinfo; p->flav; p++) {
+ if (p->flav == flav)
+ return p - ep->e_secinfo;
+ }
+ if (p - ep->e_secinfo >= SECFLAVOR_COUNT) {
+ xlog(L_ERROR, "more than %d security flavors on an export\n",
+ SECFLAVOR_COUNT);
+ return -1;
+ }
+ p->flav = flav;
+ p->flags = ep->e_flags;
+ (p+1)->flav = NULL;
+ return p - ep->e_secinfo;
+}
+
+static struct flav_info *find_flavor(char *name)
+{
+ struct flav_info *flav;
+ for (flav = flav_map; flav < flav_map + flav_map_size; flav++)
+ if (strcmp(flav->flavour, name) == 0)
+ return flav;
+ return NULL;
+}
+
+/* @str is a colon seperated list of security flavors. Their order
+ * is recorded in @ep, and a bitmap corresponding to the list is returned.
+ * A zero return indicates an error.
+ */
+static unsigned int parse_flavors(char *str, struct exportent *ep)
+{
+ unsigned int out=0;
+ char *flavor;
+ int bit;
+
+ while ( (flavor=strsep(&str, ":")) ) {
+ struct flav_info *flav = find_flavor(flavor);
+ if (flav == NULL) {
+ xlog(L_ERROR, "unknown flavor %s\n", flavor);
+ return 0;
+ }
+ bit = secinfo_addflavor(flav, ep);
+ if (bit < 0)
+ return 0;
+ out |= 1<<bit;
+ }
+ return out;
+}
+
+/* Sets the bits in @mask for the appropriate security flavor flags. */
+static void setflags(int mask, unsigned int active, struct exportent *ep)
+{
+ int bit=0;
+
+ ep->e_flags |= mask;
+
+ while (active) {
+ if (active & 1)
+ ep->e_secinfo[bit].flags |= mask;
+ bit++;
+ active >>= 1;
+ }
+}
+
+/* Clears the bits in @mask for the appropriate security flavor flags. */
+static void clearflags(int mask, unsigned int active, struct exportent *ep)
+{
+ int bit=0;
+
+ ep->e_flags &= ~mask;
+
+ while (active) {
+ if (active & 1)
+ ep->e_secinfo[bit].flags &= ~mask;
+ bit++;
+ active >>= 1;
+ }
+}
+
+/* options that can vary per flavor: */
+#define NFSEXP_SECINFO_FLAGS (NFSEXP_READONLY | NFSEXP_ROOTSQUASH \
+ | NFSEXP_ALLSQUASH)
+