intiauth.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* vcc/intiauth.c
  2. *
  3. * This file is part of vcc.
  4. *
  5. * vcc is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * vcc is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with vcc. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <unistd.h>
  21. #include <fcntl.h>
  22. #include <errno.h>
  23. #include <string.h>
  24. #include <vcc/vcc.h>
  25. #include <vcc/plugin.h>
  26. #include <vcc/version.h>
  27. #include <vcc/interfaces.h>
  28. int ia_login(char *session);
  29. int do_intiauth(void) {
  30. char auth_session[65];
  31. int fdt, fdu;
  32. if ((fdt = open("/var/run/intiauth-session", O_RDONLY)) < 0)
  33. return 0;
  34. if ((fdu = open("/var/run/intiauth-user", O_RDONLY)) < 0) {
  35. close(fdt);
  36. return 0;
  37. }
  38. memset(auth_session, 0, 65);
  39. if (unlikely(read(fdt, auth_session, 64) != 64)) {
  40. fprintf(stderr, "/var/run/intiauth-session: wrong file format: too short. \n");
  41. close(fdt);
  42. return 0;
  43. }
  44. read(fdu, usrname, USRNAME_SIZE);
  45. close(fdt);
  46. close(fdu);
  47. printf("intiauth: %s %s\n", usrname, auth_session);
  48. ia_login(auth_session);
  49. return 1;
  50. }