pre_tagline.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /* __ ____ __ ___
  2. / /_/ / /_/ /____ / _/
  3. / __/ / __/ __/ _ \/ _/
  4. \__/ /\__/\__/\___/_/
  5. /_/
  6. /
  7. / Only allow sane chars in user tagline.
  8. / cscript SITE[:space:]TAGLINE pre /bin/pre_tagline
  9. */
  10. #include <sys/types.h>
  11. #include <regex.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <syslog.h>
  15. #include <string.h>
  16. int main(int argc, char *argv[])
  17. {
  18. int i = 0;
  19. regex_t tagline;
  20. int result;
  21. if ( argc != 4 || strcmp(argv[2], getenv("USER")) != 0) return EXIT_FAILURE;
  22. result = regcomp(&tagline, "^[]\\.[A-Za-z0-9^_ -]*$", REG_EXTENDED);
  23. result = regexec(&tagline, argv[1], 0, NULL, 0);
  24. if ( result == REG_NOMATCH || strlen(argv[1]) > 50 ) { result = REG_NOMATCH; }
  25. regfree(&tagline);
  26. if ( !result ) return EXIT_SUCCESS;
  27. else if ( result == REG_NOMATCH ) {
  28. openlog("BAD_TAGLINE", LOG_NDELAY, LOG_DAEMON);
  29. syslog(LOG_ERR, "{%s}", getenv("USER"));
  30. closelog();
  31. return EXIT_FAILURE;
  32. } else return EXIT_FAILURE;
  33. return EXIT_SUCCESS;
  34. }