qubes_penctl.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * The Qubes OS Project, http://www.qubes-os.org
  3. *
  4. * Copyright (C) 2010 Rafal Wojtczuk <rafal@invisiblethingslab.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. *
  20. */
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <stdio.h>
  24. #include <unistd.h>
  25. #include <xs.h>
  26. int check_name(unsigned char *s)
  27. {
  28. int c;
  29. for (; *s; s++) {
  30. c = *s;
  31. if (c >= 'a' && c <= 'z')
  32. continue;
  33. if (c >= 'A' && c <= 'Z')
  34. continue;
  35. if (c == '_' || c == '-')
  36. continue;
  37. return 0;
  38. }
  39. return 1;
  40. }
  41. int main(int argc, char **argv)
  42. {
  43. char buf[256] = "new";
  44. struct xs_handle *xs;
  45. xs = xs_domain_open();
  46. setuid(getuid());
  47. if (!xs) {
  48. perror("xs_domain_open");
  49. exit(1);
  50. }
  51. if (argc < 2) {
  52. fprintf(stderr, "usage: %s new\n"
  53. "%s send vmname\n", argv[0], argv[0]);
  54. exit(1);
  55. }
  56. if (argc > 2) {
  57. if (!check_name((unsigned char*)argv[2])) {
  58. fprintf(stderr, "invalid vmname %s\n", argv[2]);
  59. exit(1);
  60. }
  61. snprintf(buf, sizeof(buf), "send %s", argv[2]);
  62. }
  63. if (!xs_write(xs, 0, "device/qpen", buf, strlen(buf))) {
  64. perror("xs_write");
  65. exit(1);
  66. }
  67. xs_daemon_close(xs);
  68. return 0;
  69. }