setuid-allowed.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2013 Damien Miller <djm@mindrot.org>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /* $OpenBSD$ */
  17. #include "includes.h"
  18. #include <sys/types.h>
  19. #ifdef HAVE_SYS_STATVFS_H
  20. # include <sys/statvfs.h>
  21. #endif
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <errno.h>
  26. static void
  27. usage(void)
  28. {
  29. fprintf(stderr, "check-setuid [path]\n");
  30. exit(1);
  31. }
  32. int
  33. main(int argc, char **argv)
  34. {
  35. const char *path = ".";
  36. struct statvfs sb;
  37. if (argc > 2)
  38. usage();
  39. else if (argc == 2)
  40. path = argv[1];
  41. if (statvfs(path, &sb) != 0) {
  42. /* Don't return an error if the host doesn't support statvfs */
  43. if (errno == ENOSYS)
  44. return 0;
  45. fprintf(stderr, "statvfs for \"%s\" failed: %s\n",
  46. path, strerror(errno));
  47. }
  48. return (sb.f_flag & ST_NOSUID) ? 1 : 0;
  49. }