Databases Reference
In-Depth Information
All we need to do is use the vio->read_packet() function to read the data that
the client plugin has sent, and search it for the serial number, as specified in the
info->auth_string . The /proc/bus/usb/devices file looks like:
T: Bus=01 Lev=01 Prnt=01 Port=06 Cnt=01 Dev#= 4 Spd=480 MxCh= 0
P: Vendor=0ea0 ProdID=2126 Rev= 2.00
S: Manufacturer=OTi
S: Product=USB Multi- Card Reader
S: SerialNumber=0123456789abcdef
....
We better search for the complete line, with the "S: SerialNumber=" prefix, to make
sure we did not, accidentally, find a match in the middle of a longer serial number of
some other device:
{
unsigned char *pkt;
int pkt_len;
size_t buflen=strlen(info->auth_string) + 20;
char *buf=alloca(buflen);
my_snprintf(buf, buflen, "S: SerialNumber=%s\n",
info->auth_string);
First, we allocate a buffer, and create a string to search for. Note that it uses the
my_snprintf() function, which is exported via the my_snprintf service, as explained
earlier in this Appendix .
if ((pkt_len= vio->read_packet(vio, &pkt)) < 0)
return CR_ERROR;
Now we read the data, as sent by the client. The vio->read_packet() function
returns the number of bytes read and stores the pointer to the data in pkt . The data
itself is in the internal buffer of the MySQL network layer, and it will be overwritten
on the next I/O operation. In our case it is fine, but if we need the data for a longer
time, we will have to copy it.
return strstr(pkt, buf) ? CR_OK : CR_ERROR;
}
Done! After reading the data, all we need is one strstr() call to determine if any of
the connected USB devices, on the client side, has the correct serial number or not.
Now, we need to write the client part of our USB authentication.
 
Search WWH ::




Custom Search