rpm
4.5
|
00001 00005 #include "system.h" 00006 00007 #if HAVE_MACHINE_TYPES_H 00008 # include <machine/types.h> 00009 #endif 00010 00011 #include <netinet/in.h> 00012 00013 #include <rpmlib.h> 00014 00015 #include "signature.h" 00016 #include "rpmlead.h" 00017 #include "debug.h" 00018 00019 /*@unchecked@*/ /*@observer@*/ 00020 static unsigned char lead_magic[] = { 00021 RPMLEAD_MAGIC0, RPMLEAD_MAGIC1, RPMLEAD_MAGIC2, RPMLEAD_MAGIC3 00022 }; 00023 00024 /* The lead needs to be 8 byte aligned */ 00025 00026 rpmRC writeLead(FD_t fd, const struct rpmlead *lead) 00027 { 00028 struct rpmlead l; 00029 00030 /*@-boundswrite@*/ 00031 memcpy(&l, lead, sizeof(l)); 00032 00033 memcpy(&l.magic, lead_magic, sizeof(l.magic)); 00034 /*@=boundswrite@*/ 00035 l.type = htons(l.type); 00036 l.archnum = htons(l.archnum); 00037 l.osnum = htons(l.osnum); 00038 l.signature_type = htons(l.signature_type); 00039 00040 /*@-boundswrite@*/ 00041 if (Fwrite(&l, 1, sizeof(l), fd) != sizeof(l)) 00042 return RPMRC_FAIL; 00043 /*@=boundswrite@*/ 00044 00045 return RPMRC_OK; 00046 } 00047 00048 rpmRC readLead(FD_t fd, struct rpmlead *lead) 00049 { 00050 /*@-boundswrite@*/ 00051 memset(lead, 0, sizeof(*lead)); 00052 /*@=boundswrite@*/ 00053 /*@-type@*/ /* FIX: remove timed read */ 00054 if (timedRead(fd, (char *)lead, sizeof(*lead)) != sizeof(*lead)) { 00055 if (Ferror(fd)) { 00056 rpmError(RPMERR_READ, _("read failed: %s (%d)\n"), 00057 Fstrerror(fd), errno); 00058 return RPMRC_FAIL; 00059 } 00060 return RPMRC_NOTFOUND; 00061 } 00062 /*@=type@*/ 00063 00064 if (memcmp(lead->magic, lead_magic, sizeof(lead_magic))) 00065 return RPMRC_NOTFOUND; 00066 lead->type = ntohs(lead->type); 00067 lead->archnum = ntohs(lead->archnum); 00068 lead->osnum = ntohs(lead->osnum); 00069 lead->signature_type = ntohs(lead->signature_type); 00070 if (lead->signature_type != RPMSIGTYPE_HEADERSIG) 00071 return RPMRC_NOTFOUND; 00072 00073 return RPMRC_OK; 00074 }