netpacket_delete.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <stdint.h>
  2. #include <string.h>
  3. #include "crypto.h"
  4. #include "netpacket_internal.h"
  5. #include "netproto.h"
  6. #include "sysendian.h"
  7. #include "netpacket.h"
  8. /**
  9. * netpacket_delete_file(NPC, machinenum, class, name, nonce, callback):
  10. * Construct and send a NETPACKET_DELETE_FILE packet asking to delete the
  11. * specified file.
  12. */
  13. int
  14. netpacket_delete_file(NETPACKET_CONNECTION * NPC,
  15. uint64_t machinenum, uint8_t class, const uint8_t name[32],
  16. const uint8_t nonce[32], handlepacket_callback * callback)
  17. {
  18. uint8_t packetbuf[105];
  19. /* Construct the packet. */
  20. be64enc(&packetbuf[0], machinenum);
  21. packetbuf[8] = class;
  22. memcpy(&packetbuf[9], name, 32);
  23. memcpy(&packetbuf[41], nonce, 32);
  24. /* Append hmac. */
  25. if (netpacket_hmac_append(NETPACKET_DELETE_FILE,
  26. packetbuf, 73, CRYPTO_KEY_AUTH_DELETE))
  27. goto err0;
  28. /* Send the packet. */
  29. if (netproto_writepacket(NPC->NC, NETPACKET_DELETE_FILE,
  30. packetbuf, 105, netpacket_op_packetsent, NPC))
  31. goto err0;
  32. /* Set callback for handling a response. */
  33. NPC->pending_current->handlepacket = callback;
  34. /* Success! */
  35. return (0);
  36. err0:
  37. /* Failure! */
  38. return (-1);
  39. }