use $(LIBENSCVECTOR) instead of libensc_vector.a
[util-vserver.git] / util-vserver / src / setattr.c
index 74de450..4513ac9 100644 (file)
@@ -37,15 +37,31 @@ struct option const
 CMDLINE_OPTIONS[] = {
   { "help",     no_argument,  0, CMD_HELP },
   { "version",  no_argument,  0, CMD_VERSION },
-  { "immutable", no_argument, 0, CMD_IMMUTABLE },
-  { "immulink",  no_argument, 0, CMD_IMMULINK },
+  { "immu",        no_argument, 0, CMD_IMMU  },
+  { "iunlink",     no_argument, 0, CMD_IMMU  },
+  { "admin",       no_argument, 0, CMD_ADMIN },
+  { "watch",       no_argument, 0, CMD_WATCH },
+  { "hide",        no_argument, 0, CMD_HIDE  },
+  { "barrier",     no_argument, 0, CMD_BARRIER },
+  { "~iunlink",    no_argument, 0, CMD_UNSET_IMMU  },
+  { "!iunlink",    no_argument, 0, CMD_UNSET_IMMU  },
+  { "~immu",       no_argument, 0, CMD_UNSET_IMMU  },
+  { "!immu",       no_argument, 0, CMD_UNSET_IMMU  },
+  { "~admin",      no_argument, 0, CMD_UNSET_ADMIN },
+  { "!admin",      no_argument, 0, CMD_UNSET_ADMIN },
+  { "~watch",      no_argument, 0, CMD_UNSET_WATCH },
+  { "!watch",      no_argument, 0, CMD_UNSET_WATCH },
+  { "~hide",       no_argument, 0, CMD_UNSET_HIDE  },
+  { "!hide",       no_argument, 0, CMD_UNSET_HIDE  },
+  { "~barrier",    no_argument, 0, CMD_UNSET_BARRIER },
+  { "!barrier",    no_argument, 0, CMD_UNSET_BARRIER },
+  { "iunlink-but-not-immutable",   no_argument, 0, CMD_IMMUX },
+  { "~iunlink-but-not-immutable",  no_argument, 0, CMD_UNSET_IMMUX },
+  { "!iunlink-but-not-immutable",  no_argument, 0, CMD_UNSET_IMMUX },
   { 0,0,0,0 }
 };
 
-char const             CMDLINE_OPTIONS_SHORT[] = "Rsu";
-
-static long    set_mask = 0;
-static long    del_mask = VC_IMMUTABLE_ALL;
+char const             CMDLINE_OPTIONS_SHORT[] = "Rx";
 
 void
 showHelp(int fd, char const *cmd, int res)
@@ -53,12 +69,10 @@ showHelp(int fd, char const *cmd, int res)
   WRITE_MSG(fd, "Usage:  ");
   WRITE_STR(fd, cmd);
   WRITE_MSG(fd,
-           " [-Rsu] [--immutable] [--immulink] [--] <file>+\n\n"
+           " [-Rx] [--[~](iunlink|admin|watch|hide|barrier|iunlink-but-not-immutable)]* [--] <file>+\n\n"
            " Options:\n"
            "   -R  ...  recurse through directories\n"
-           "   -s  ...  set flag only; when only one of the '--immu*' options\n"
-           "            is given, do not delete the other ones\n"
-           "   -u  ...  revert operation and unset the given flags\n"
+           "   -x  ...  do not cross filesystems\n\n"
            "Please report bugs to " PACKAGE_BUGREPORT "\n");
   exit(res);
 }
@@ -82,52 +96,22 @@ fixupParams(struct Arguments * args, int argc)
     exit(1);
   }
 
-  set_mask = 0;
-  if (args->immutable) set_mask |= VC_IMMUTABLE_FILE_FL;
-  if (args->immulink)  set_mask |= VC_IMMUTABLE_LINK_FL;
-  
-  if (args->do_set) del_mask = 0;
-  else              del_mask = VC_IMMUTABLE_ALL;
-
-  if (args->do_unset) {
-    del_mask = set_mask;
-    set_mask = 0;
-  }
+  args->do_display_dir = !args->do_recurse;
+  args->do_display_dot = true;
 }
 
-static bool
-setFlags(char const *name, char const *display_name,
-        struct stat const *exp_st)
+bool
+handleFile(char const *name, char const * display_name)
 {
-  int          fd = open(name, O_RDONLY);
-  int          res = false;
-  
-  if (fd==-1) {
-    perror("open()");
-    return false;
-  }
+  int rc = vc_set_iattr(name,
+                       0,
+                       global_args->set_mask & ~global_args->del_mask,
+                       global_args->set_mask |  global_args->del_mask);
 
-  if (!exp_st ||
-      !checkForRace(fd, name, exp_st))
-    goto err;
-
-  if (vc_X_set_ext2flags(fd, set_mask, del_mask)==-1) {
+  if (rc==-1) {
     perror(display_name);
-    goto err;
+    return false;
   }
-
-  res = true;
-
-  err:
-  close(fd);
-  return res;
-}
-
-bool
-handleFile(char const *name, char const * display_name,
-          struct stat const *exp_st)
-{
-  if (S_ISLNK(exp_st->st_mode)) return true;
   
-  return setFlags(name, display_name, exp_st);
+  return true;
 }