+struct createinfo createinfo = {
+ .symlinks = 1,
+#ifdef DEBIAN
+ .gid = 6, /* disk */
+ .mode = 0660,
+#else
+ .mode = 0600,
+#endif
+};
+
+int parse_auto(char *str, char *msg, int config)
+{
+ int autof;
+ if (str == NULL || *str == 0)
+ autof = 2;
+ else if (strcasecmp(str,"no")==0)
+ autof = 1;
+ else if (strcasecmp(str,"yes")==0)
+ autof = 2;
+ else if (strcasecmp(str,"md")==0)
+ autof = config?5:3;
+ else {
+ /* There might be digits, and maybe a hypen, at the end */
+ char *e = str + strlen(str);
+ int num = 4;
+ int len;
+ while (e > str && isdigit(e[-1]))
+ e--;
+ if (*e) {
+ num = atoi(e);
+ if (num <= 0) num = 1;
+ }
+ if (e > str && e[-1] == '-')
+ e--;
+ len = e - str;
+ if ((len == 2 && strncasecmp(str,"md",2)==0)) {
+ autof = config ? 5 : 3;
+ } else if ((len == 3 && strncasecmp(str,"yes",3)==0)) {
+ autof = 2;
+ } else if ((len == 3 && strncasecmp(str,"mdp",3)==0)) {
+ autof = config ? 6 : 4;
+ } else if ((len == 1 && strncasecmp(str,"p",1)==0) ||
+ (len >= 4 && strncasecmp(str,"part",4)==0)) {
+ autof = 6;
+ } else {
+ fprintf(stderr, Name ": %s arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n"
+ " optionally followed by a number.\n",
+ msg, str);
+ exit(2);
+ }
+ autof |= num << 3;
+ }
+ return autof;
+}
+
+static void createline(char *line)
+{
+ char *w;
+ char *ep;
+
+ for (w=dl_next(line); w!=line; w=dl_next(w)) {
+ if (strncasecmp(w, "auto=", 5) == 0)
+ createinfo.autof = parse_auto(w+5, "auto=", 1);
+ else if (strncasecmp(w, "owner=", 6) == 0) {
+ if (w[6] == 0) {
+ fprintf(stderr, Name ": missing owner name\n");
+ continue;
+ }
+ createinfo.uid = strtoul(w+6, &ep, 10);
+ if (*ep != 0) {
+ struct passwd *pw;
+ /* must be a name */
+ pw = getpwnam(w+6);
+ if (pw)
+ createinfo.uid = pw->pw_uid;
+ else
+ fprintf(stderr, Name ": CREATE user %s not found\n", w+6);
+ }
+ } else if (strncasecmp(w, "group=", 6) == 0) {
+ if (w[6] == 0) {
+ fprintf(stderr, Name ": missing group name\n");
+ continue;
+ }
+ createinfo.gid = strtoul(w+6, &ep, 10);
+ if (*ep != 0) {
+ struct group *gr;
+ /* must be a name */
+ gr = getgrnam(w+6);
+ if (gr)
+ createinfo.gid = gr->gr_gid;
+ else
+ fprintf(stderr, Name ": CREATE group %s not found\n", w+6);
+ }
+ } else if (strncasecmp(w, "mode=", 5) == 0) {
+ if (w[5] == 0) {
+ fprintf(stderr, Name ": missing CREATE mode\n");
+ continue;
+ }
+ createinfo.mode = strtoul(w+5, &ep, 8);
+ if (*ep != 0) {
+ createinfo.mode = 0600;
+ fprintf(stderr, Name ": unrecognised CREATE mode %s\n",
+ w+5);
+ }
+ } else if (strncasecmp(w, "metadata=", 9) == 0) {
+ /* style of metadata to use by default */
+ int i;
+ for (i=0; superlist[i] && !createinfo.supertype; i++)
+ createinfo.supertype =
+ superlist[i]->match_metadata_desc(w+9);
+ if (!createinfo.supertype)
+ fprintf(stderr, Name ": metadata format %s unknown, ignoring\n",
+ w+9);
+ } else if (strncasecmp(w, "symlinks=yes", 12) == 0)
+ createinfo.symlinks = 1;
+ else if (strncasecmp(w, "symlinks=no", 11) == 0)
+ createinfo.symlinks = 0;
+ else {
+ fprintf(stderr, Name ": unrecognised word on CREATE line: %s\n",
+ w);
+ }
+ }
+}