WiimoteSync: null_pin.patch
| File null_pin.patch, 2.9 kB (added by dsmith, 2 years ago) |
|---|
-
src/textfile.c
diff -ur bluez-4.39/src/textfile.c bluez-4.39.cwiid/src/textfile.c
old new 343 343 return str; 344 344 } 345 345 346 static char *read_key_null(const char *pathname, const char *key, int icase, int *val_len) 347 { 348 struct stat st; 349 char *map, *off, *end, *tmp, *str = NULL; 350 off_t size; size_t len; 351 int fd, err = 0; 352 353 fd = open(pathname, O_RDONLY); 354 if (fd < 0) 355 return NULL; 356 357 if (flock(fd, LOCK_SH) < 0) { 358 err = errno; 359 goto close; 360 } 361 362 if (fstat(fd, &st) < 0) { 363 err = errno; 364 goto unlock; 365 } 366 367 size = st.st_size; 368 369 map = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); 370 if (!map || map == MAP_FAILED) { 371 err = errno; 372 goto unlock; 373 } 374 375 len = strlen(key); 376 off = find_key(map, size, key, len, icase); 377 if (!off) { 378 err = EILSEQ; 379 goto unmap; 380 } 381 382 end = memchr(off, '\r', size - (off - map)); 383 tmp = memchr(off, '\n', size - (off - map)); 384 if (tmp && (!end || (tmp < end))) { 385 end = tmp; 386 } 387 if (!end) { 388 err = EILSEQ; 389 goto unmap; 390 } 391 392 str = malloc(end - off - len); 393 if (!str) { 394 err = EILSEQ; 395 goto unmap; 396 } 397 398 memset(str, 0, end - off - len); 399 strncpy(str, off + len + 1, end - off - len - 1); 400 if (val_len) { 401 *val_len = end - off - len - 1; 402 } 403 404 unmap: 405 munmap(map, size); 406 407 unlock: 408 flock(fd, LOCK_UN); 409 410 close: 411 close(fd); 412 errno = err; 413 414 return str; 415 } 416 346 417 int textfile_put(const char *pathname, const char *key, const char *value) 347 418 { 348 419 return write_key(pathname, key, value, 0); … … 368 439 return read_key(pathname, key, 0); 369 440 } 370 441 442 char *textfile_get_null(const char *pathname, const char *key, int *len) 443 { 444 return read_key_null(pathname, key, 0, len); 445 } 446 371 447 char *textfile_caseget(const char *pathname, const char *key) 372 448 { 373 449 return read_key(pathname, key, 1); -
src/textfile.h
diff -ur bluez-4.39/src/textfile.h bluez-4.39.cwiid/src/textfile.h
old new 34 34 int textfile_del(const char *pathname, const char *key); 35 35 int textfile_casedel(const char *pathname, const char *key); 36 36 char *textfile_get(const char *pathname, const char *key); 37 char *textfile_get_null(const char *pathname, const char *key, int *len); 37 38 char *textfile_caseget(const char *pathname, const char *key); 38 39 39 40 int textfile_foreach(const char *pathname, -
src/storage.c
diff -ur bluez-4.39/src/storage.c bluez-4.39.cwiid/src/storage.c
old new 618 618 create_filename(filename, PATH_MAX, local, "pincodes"); 619 619 620 620 ba2str(peer, addr); 621 str = textfile_get (filename, addr);621 str = textfile_get_null(filename, addr, &len); 622 622 if (!str) 623 623 return -ENOENT; 624 624 625 625 strncpy(pin, str, 16); 626 len = strlen(pin);627 626 628 627 free(str); 629 628
