auth_wep.c 830 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <auth.h>
  4. #include "authlocal.h"
  5. /*
  6. * make factotum add wep keys to an 802.11 device
  7. */
  8. int
  9. auth_wep(char *dev, char *fmt, ...)
  10. {
  11. AuthRpc *rpc;
  12. char *params, *p;
  13. int fd;
  14. va_list arg;
  15. int rv;
  16. rv = -1;
  17. if(dev == nil){
  18. werrstr("no device specified");
  19. return rv;
  20. }
  21. fd = open("/mnt/factotum/rpc", ORDWR);
  22. if(fd < 0)
  23. return rv;
  24. rpc = auth_allocrpc(fd);
  25. if(rpc != nil){
  26. quotefmtinstall(); /* just in case */
  27. va_start(arg, fmt);
  28. params = vsmprint(fmt, arg);
  29. va_end(arg);
  30. if(params != nil){
  31. p = smprint("proto=wep %s", params);
  32. if(p != nil){
  33. if(auth_rpc(rpc, "start", p, strlen(p)) == ARok
  34. && auth_rpc(rpc, "write", dev, strlen(dev)) == ARok)
  35. rv = 0;
  36. free(p);
  37. }
  38. free(params);
  39. }
  40. auth_freerpc(rpc);
  41. }
  42. close(fd);
  43. return rv;
  44. }