xdr.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. /*
  2. * linux/fs/lockd/xdr.c
  3. *
  4. * XDR support for lockd and the lock client.
  5. *
  6. * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
  7. */
  8. #include <linux/types.h>
  9. #include <linux/sched.h>
  10. #include <linux/utsname.h>
  11. #include <linux/nfs.h>
  12. #include <linux/sunrpc/xdr.h>
  13. #include <linux/sunrpc/clnt.h>
  14. #include <linux/sunrpc/svc.h>
  15. #include <linux/sunrpc/stats.h>
  16. #include <linux/lockd/lockd.h>
  17. #include <linux/lockd/sm_inter.h>
  18. #define NLMDBG_FACILITY NLMDBG_XDR
  19. static inline loff_t
  20. s32_to_loff_t(__s32 offset)
  21. {
  22. return (loff_t)offset;
  23. }
  24. static inline __s32
  25. loff_t_to_s32(loff_t offset)
  26. {
  27. __s32 res;
  28. if (offset >= NLM_OFFSET_MAX)
  29. res = NLM_OFFSET_MAX;
  30. else if (offset <= -NLM_OFFSET_MAX)
  31. res = -NLM_OFFSET_MAX;
  32. else
  33. res = offset;
  34. return res;
  35. }
  36. /*
  37. * XDR functions for basic NLM types
  38. */
  39. static __be32 *nlm_decode_cookie(__be32 *p, struct nlm_cookie *c)
  40. {
  41. unsigned int len;
  42. len = ntohl(*p++);
  43. if(len==0)
  44. {
  45. c->len=4;
  46. memset(c->data, 0, 4); /* hockeypux brain damage */
  47. }
  48. else if(len<=NLM_MAXCOOKIELEN)
  49. {
  50. c->len=len;
  51. memcpy(c->data, p, len);
  52. p+=XDR_QUADLEN(len);
  53. }
  54. else
  55. {
  56. printk(KERN_NOTICE
  57. "lockd: bad cookie size %d (only cookies under %d bytes are supported.)\n", len, NLM_MAXCOOKIELEN);
  58. return NULL;
  59. }
  60. return p;
  61. }
  62. static inline __be32 *
  63. nlm_encode_cookie(__be32 *p, struct nlm_cookie *c)
  64. {
  65. *p++ = htonl(c->len);
  66. memcpy(p, c->data, c->len);
  67. p+=XDR_QUADLEN(c->len);
  68. return p;
  69. }
  70. static __be32 *
  71. nlm_decode_fh(__be32 *p, struct nfs_fh *f)
  72. {
  73. unsigned int len;
  74. if ((len = ntohl(*p++)) != NFS2_FHSIZE) {
  75. printk(KERN_NOTICE
  76. "lockd: bad fhandle size %d (should be %d)\n",
  77. len, NFS2_FHSIZE);
  78. return NULL;
  79. }
  80. f->size = NFS2_FHSIZE;
  81. memset(f->data, 0, sizeof(f->data));
  82. memcpy(f->data, p, NFS2_FHSIZE);
  83. return p + XDR_QUADLEN(NFS2_FHSIZE);
  84. }
  85. static inline __be32 *
  86. nlm_encode_fh(__be32 *p, struct nfs_fh *f)
  87. {
  88. *p++ = htonl(NFS2_FHSIZE);
  89. memcpy(p, f->data, NFS2_FHSIZE);
  90. return p + XDR_QUADLEN(NFS2_FHSIZE);
  91. }
  92. /*
  93. * Encode and decode owner handle
  94. */
  95. static inline __be32 *
  96. nlm_decode_oh(__be32 *p, struct xdr_netobj *oh)
  97. {
  98. return xdr_decode_netobj(p, oh);
  99. }
  100. static inline __be32 *
  101. nlm_encode_oh(__be32 *p, struct xdr_netobj *oh)
  102. {
  103. return xdr_encode_netobj(p, oh);
  104. }
  105. static __be32 *
  106. nlm_decode_lock(__be32 *p, struct nlm_lock *lock)
  107. {
  108. struct file_lock *fl = &lock->fl;
  109. s32 start, len, end;
  110. if (!(p = xdr_decode_string_inplace(p, &lock->caller,
  111. &lock->len,
  112. NLM_MAXSTRLEN))
  113. || !(p = nlm_decode_fh(p, &lock->fh))
  114. || !(p = nlm_decode_oh(p, &lock->oh)))
  115. return NULL;
  116. lock->svid = ntohl(*p++);
  117. locks_init_lock(fl);
  118. fl->fl_owner = current->files;
  119. fl->fl_pid = (pid_t)lock->svid;
  120. fl->fl_flags = FL_POSIX;
  121. fl->fl_type = F_RDLCK; /* as good as anything else */
  122. start = ntohl(*p++);
  123. len = ntohl(*p++);
  124. end = start + len - 1;
  125. fl->fl_start = s32_to_loff_t(start);
  126. if (len == 0 || end < 0)
  127. fl->fl_end = OFFSET_MAX;
  128. else
  129. fl->fl_end = s32_to_loff_t(end);
  130. return p;
  131. }
  132. /*
  133. * Encode a lock as part of an NLM call
  134. */
  135. static __be32 *
  136. nlm_encode_lock(__be32 *p, struct nlm_lock *lock)
  137. {
  138. struct file_lock *fl = &lock->fl;
  139. __s32 start, len;
  140. if (!(p = xdr_encode_string(p, lock->caller))
  141. || !(p = nlm_encode_fh(p, &lock->fh))
  142. || !(p = nlm_encode_oh(p, &lock->oh)))
  143. return NULL;
  144. if (fl->fl_start > NLM_OFFSET_MAX
  145. || (fl->fl_end > NLM_OFFSET_MAX && fl->fl_end != OFFSET_MAX))
  146. return NULL;
  147. start = loff_t_to_s32(fl->fl_start);
  148. if (fl->fl_end == OFFSET_MAX)
  149. len = 0;
  150. else
  151. len = loff_t_to_s32(fl->fl_end - fl->fl_start + 1);
  152. *p++ = htonl(lock->svid);
  153. *p++ = htonl(start);
  154. *p++ = htonl(len);
  155. return p;
  156. }
  157. /*
  158. * Encode result of a TEST/TEST_MSG call
  159. */
  160. static __be32 *
  161. nlm_encode_testres(__be32 *p, struct nlm_res *resp)
  162. {
  163. s32 start, len;
  164. if (!(p = nlm_encode_cookie(p, &resp->cookie)))
  165. return NULL;
  166. *p++ = resp->status;
  167. if (resp->status == nlm_lck_denied) {
  168. struct file_lock *fl = &resp->lock.fl;
  169. *p++ = (fl->fl_type == F_RDLCK)? xdr_zero : xdr_one;
  170. *p++ = htonl(resp->lock.svid);
  171. /* Encode owner handle. */
  172. if (!(p = xdr_encode_netobj(p, &resp->lock.oh)))
  173. return NULL;
  174. start = loff_t_to_s32(fl->fl_start);
  175. if (fl->fl_end == OFFSET_MAX)
  176. len = 0;
  177. else
  178. len = loff_t_to_s32(fl->fl_end - fl->fl_start + 1);
  179. *p++ = htonl(start);
  180. *p++ = htonl(len);
  181. }
  182. return p;
  183. }
  184. /*
  185. * First, the server side XDR functions
  186. */
  187. int
  188. nlmsvc_decode_testargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
  189. {
  190. u32 exclusive;
  191. if (!(p = nlm_decode_cookie(p, &argp->cookie)))
  192. return 0;
  193. exclusive = ntohl(*p++);
  194. if (!(p = nlm_decode_lock(p, &argp->lock)))
  195. return 0;
  196. if (exclusive)
  197. argp->lock.fl.fl_type = F_WRLCK;
  198. return xdr_argsize_check(rqstp, p);
  199. }
  200. int
  201. nlmsvc_encode_testres(struct svc_rqst *rqstp, __be32 *p, struct nlm_res *resp)
  202. {
  203. if (!(p = nlm_encode_testres(p, resp)))
  204. return 0;
  205. return xdr_ressize_check(rqstp, p);
  206. }
  207. int
  208. nlmsvc_decode_lockargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
  209. {
  210. u32 exclusive;
  211. if (!(p = nlm_decode_cookie(p, &argp->cookie)))
  212. return 0;
  213. argp->block = ntohl(*p++);
  214. exclusive = ntohl(*p++);
  215. if (!(p = nlm_decode_lock(p, &argp->lock)))
  216. return 0;
  217. if (exclusive)
  218. argp->lock.fl.fl_type = F_WRLCK;
  219. argp->reclaim = ntohl(*p++);
  220. argp->state = ntohl(*p++);
  221. argp->monitor = 1; /* monitor client by default */
  222. return xdr_argsize_check(rqstp, p);
  223. }
  224. int
  225. nlmsvc_decode_cancargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
  226. {
  227. u32 exclusive;
  228. if (!(p = nlm_decode_cookie(p, &argp->cookie)))
  229. return 0;
  230. argp->block = ntohl(*p++);
  231. exclusive = ntohl(*p++);
  232. if (!(p = nlm_decode_lock(p, &argp->lock)))
  233. return 0;
  234. if (exclusive)
  235. argp->lock.fl.fl_type = F_WRLCK;
  236. return xdr_argsize_check(rqstp, p);
  237. }
  238. int
  239. nlmsvc_decode_unlockargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
  240. {
  241. if (!(p = nlm_decode_cookie(p, &argp->cookie))
  242. || !(p = nlm_decode_lock(p, &argp->lock)))
  243. return 0;
  244. argp->lock.fl.fl_type = F_UNLCK;
  245. return xdr_argsize_check(rqstp, p);
  246. }
  247. int
  248. nlmsvc_decode_shareargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
  249. {
  250. struct nlm_lock *lock = &argp->lock;
  251. memset(lock, 0, sizeof(*lock));
  252. locks_init_lock(&lock->fl);
  253. lock->svid = ~(u32) 0;
  254. lock->fl.fl_pid = (pid_t)lock->svid;
  255. if (!(p = nlm_decode_cookie(p, &argp->cookie))
  256. || !(p = xdr_decode_string_inplace(p, &lock->caller,
  257. &lock->len, NLM_MAXSTRLEN))
  258. || !(p = nlm_decode_fh(p, &lock->fh))
  259. || !(p = nlm_decode_oh(p, &lock->oh)))
  260. return 0;
  261. argp->fsm_mode = ntohl(*p++);
  262. argp->fsm_access = ntohl(*p++);
  263. return xdr_argsize_check(rqstp, p);
  264. }
  265. int
  266. nlmsvc_encode_shareres(struct svc_rqst *rqstp, __be32 *p, struct nlm_res *resp)
  267. {
  268. if (!(p = nlm_encode_cookie(p, &resp->cookie)))
  269. return 0;
  270. *p++ = resp->status;
  271. *p++ = xdr_zero; /* sequence argument */
  272. return xdr_ressize_check(rqstp, p);
  273. }
  274. int
  275. nlmsvc_encode_res(struct svc_rqst *rqstp, __be32 *p, struct nlm_res *resp)
  276. {
  277. if (!(p = nlm_encode_cookie(p, &resp->cookie)))
  278. return 0;
  279. *p++ = resp->status;
  280. return xdr_ressize_check(rqstp, p);
  281. }
  282. int
  283. nlmsvc_decode_notify(struct svc_rqst *rqstp, __be32 *p, struct nlm_args *argp)
  284. {
  285. struct nlm_lock *lock = &argp->lock;
  286. if (!(p = xdr_decode_string_inplace(p, &lock->caller,
  287. &lock->len, NLM_MAXSTRLEN)))
  288. return 0;
  289. argp->state = ntohl(*p++);
  290. return xdr_argsize_check(rqstp, p);
  291. }
  292. int
  293. nlmsvc_decode_reboot(struct svc_rqst *rqstp, __be32 *p, struct nlm_reboot *argp)
  294. {
  295. if (!(p = xdr_decode_string_inplace(p, &argp->mon, &argp->len, SM_MAXSTRLEN)))
  296. return 0;
  297. argp->state = ntohl(*p++);
  298. /* Preserve the address in network byte order */
  299. argp->addr = *p++;
  300. argp->vers = *p++;
  301. argp->proto = *p++;
  302. return xdr_argsize_check(rqstp, p);
  303. }
  304. int
  305. nlmsvc_decode_res(struct svc_rqst *rqstp, __be32 *p, struct nlm_res *resp)
  306. {
  307. if (!(p = nlm_decode_cookie(p, &resp->cookie)))
  308. return 0;
  309. resp->status = *p++;
  310. return xdr_argsize_check(rqstp, p);
  311. }
  312. int
  313. nlmsvc_decode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)
  314. {
  315. return xdr_argsize_check(rqstp, p);
  316. }
  317. int
  318. nlmsvc_encode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)
  319. {
  320. return xdr_ressize_check(rqstp, p);
  321. }
  322. /*
  323. * Now, the client side XDR functions
  324. */
  325. #ifdef NLMCLNT_SUPPORT_SHARES
  326. static int
  327. nlmclt_decode_void(struct rpc_rqst *req, u32 *p, void *ptr)
  328. {
  329. return 0;
  330. }
  331. #endif
  332. static int
  333. nlmclt_encode_testargs(struct rpc_rqst *req, __be32 *p, nlm_args *argp)
  334. {
  335. struct nlm_lock *lock = &argp->lock;
  336. if (!(p = nlm_encode_cookie(p, &argp->cookie)))
  337. return -EIO;
  338. *p++ = (lock->fl.fl_type == F_WRLCK)? xdr_one : xdr_zero;
  339. if (!(p = nlm_encode_lock(p, lock)))
  340. return -EIO;
  341. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  342. return 0;
  343. }
  344. static int
  345. nlmclt_decode_testres(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
  346. {
  347. if (!(p = nlm_decode_cookie(p, &resp->cookie)))
  348. return -EIO;
  349. resp->status = *p++;
  350. if (resp->status == nlm_lck_denied) {
  351. struct file_lock *fl = &resp->lock.fl;
  352. u32 excl;
  353. s32 start, len, end;
  354. memset(&resp->lock, 0, sizeof(resp->lock));
  355. locks_init_lock(fl);
  356. excl = ntohl(*p++);
  357. resp->lock.svid = ntohl(*p++);
  358. fl->fl_pid = (pid_t)resp->lock.svid;
  359. if (!(p = nlm_decode_oh(p, &resp->lock.oh)))
  360. return -EIO;
  361. fl->fl_flags = FL_POSIX;
  362. fl->fl_type = excl? F_WRLCK : F_RDLCK;
  363. start = ntohl(*p++);
  364. len = ntohl(*p++);
  365. end = start + len - 1;
  366. fl->fl_start = s32_to_loff_t(start);
  367. if (len == 0 || end < 0)
  368. fl->fl_end = OFFSET_MAX;
  369. else
  370. fl->fl_end = s32_to_loff_t(end);
  371. }
  372. return 0;
  373. }
  374. static int
  375. nlmclt_encode_lockargs(struct rpc_rqst *req, __be32 *p, nlm_args *argp)
  376. {
  377. struct nlm_lock *lock = &argp->lock;
  378. if (!(p = nlm_encode_cookie(p, &argp->cookie)))
  379. return -EIO;
  380. *p++ = argp->block? xdr_one : xdr_zero;
  381. *p++ = (lock->fl.fl_type == F_WRLCK)? xdr_one : xdr_zero;
  382. if (!(p = nlm_encode_lock(p, lock)))
  383. return -EIO;
  384. *p++ = argp->reclaim? xdr_one : xdr_zero;
  385. *p++ = htonl(argp->state);
  386. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  387. return 0;
  388. }
  389. static int
  390. nlmclt_encode_cancargs(struct rpc_rqst *req, __be32 *p, nlm_args *argp)
  391. {
  392. struct nlm_lock *lock = &argp->lock;
  393. if (!(p = nlm_encode_cookie(p, &argp->cookie)))
  394. return -EIO;
  395. *p++ = argp->block? xdr_one : xdr_zero;
  396. *p++ = (lock->fl.fl_type == F_WRLCK)? xdr_one : xdr_zero;
  397. if (!(p = nlm_encode_lock(p, lock)))
  398. return -EIO;
  399. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  400. return 0;
  401. }
  402. static int
  403. nlmclt_encode_unlockargs(struct rpc_rqst *req, __be32 *p, nlm_args *argp)
  404. {
  405. struct nlm_lock *lock = &argp->lock;
  406. if (!(p = nlm_encode_cookie(p, &argp->cookie)))
  407. return -EIO;
  408. if (!(p = nlm_encode_lock(p, lock)))
  409. return -EIO;
  410. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  411. return 0;
  412. }
  413. static int
  414. nlmclt_encode_res(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
  415. {
  416. if (!(p = nlm_encode_cookie(p, &resp->cookie)))
  417. return -EIO;
  418. *p++ = resp->status;
  419. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  420. return 0;
  421. }
  422. static int
  423. nlmclt_encode_testres(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
  424. {
  425. if (!(p = nlm_encode_testres(p, resp)))
  426. return -EIO;
  427. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  428. return 0;
  429. }
  430. static int
  431. nlmclt_decode_res(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
  432. {
  433. if (!(p = nlm_decode_cookie(p, &resp->cookie)))
  434. return -EIO;
  435. resp->status = *p++;
  436. return 0;
  437. }
  438. /*
  439. * Buffer requirements for NLM
  440. */
  441. #define NLM_void_sz 0
  442. #define NLM_cookie_sz 1+XDR_QUADLEN(NLM_MAXCOOKIELEN)
  443. #define NLM_caller_sz 1+XDR_QUADLEN(sizeof(utsname()->nodename))
  444. #define NLM_netobj_sz 1+XDR_QUADLEN(XDR_MAX_NETOBJ)
  445. /* #define NLM_owner_sz 1+XDR_QUADLEN(NLM_MAXOWNER) */
  446. #define NLM_fhandle_sz 1+XDR_QUADLEN(NFS2_FHSIZE)
  447. #define NLM_lock_sz 3+NLM_caller_sz+NLM_netobj_sz+NLM_fhandle_sz
  448. #define NLM_holder_sz 4+NLM_netobj_sz
  449. #define NLM_testargs_sz NLM_cookie_sz+1+NLM_lock_sz
  450. #define NLM_lockargs_sz NLM_cookie_sz+4+NLM_lock_sz
  451. #define NLM_cancargs_sz NLM_cookie_sz+2+NLM_lock_sz
  452. #define NLM_unlockargs_sz NLM_cookie_sz+NLM_lock_sz
  453. #define NLM_testres_sz NLM_cookie_sz+1+NLM_holder_sz
  454. #define NLM_res_sz NLM_cookie_sz+1
  455. #define NLM_norep_sz 0
  456. #ifndef MAX
  457. # define MAX(a, b) (((a) > (b))? (a) : (b))
  458. #endif
  459. /*
  460. * For NLM, a void procedure really returns nothing
  461. */
  462. #define nlmclt_decode_norep NULL
  463. #define PROC(proc, argtype, restype) \
  464. [NLMPROC_##proc] = { \
  465. .p_proc = NLMPROC_##proc, \
  466. .p_encode = (kxdrproc_t) nlmclt_encode_##argtype, \
  467. .p_decode = (kxdrproc_t) nlmclt_decode_##restype, \
  468. .p_bufsiz = MAX(NLM_##argtype##_sz, NLM_##restype##_sz) << 2, \
  469. .p_statidx = NLMPROC_##proc, \
  470. .p_name = #proc, \
  471. }
  472. static struct rpc_procinfo nlm_procedures[] = {
  473. PROC(TEST, testargs, testres),
  474. PROC(LOCK, lockargs, res),
  475. PROC(CANCEL, cancargs, res),
  476. PROC(UNLOCK, unlockargs, res),
  477. PROC(GRANTED, testargs, res),
  478. PROC(TEST_MSG, testargs, norep),
  479. PROC(LOCK_MSG, lockargs, norep),
  480. PROC(CANCEL_MSG, cancargs, norep),
  481. PROC(UNLOCK_MSG, unlockargs, norep),
  482. PROC(GRANTED_MSG, testargs, norep),
  483. PROC(TEST_RES, testres, norep),
  484. PROC(LOCK_RES, res, norep),
  485. PROC(CANCEL_RES, res, norep),
  486. PROC(UNLOCK_RES, res, norep),
  487. PROC(GRANTED_RES, res, norep),
  488. #ifdef NLMCLNT_SUPPORT_SHARES
  489. PROC(SHARE, shareargs, shareres),
  490. PROC(UNSHARE, shareargs, shareres),
  491. PROC(NM_LOCK, lockargs, res),
  492. PROC(FREE_ALL, notify, void),
  493. #endif
  494. };
  495. static struct rpc_version nlm_version1 = {
  496. .number = 1,
  497. .nrprocs = 16,
  498. .procs = nlm_procedures,
  499. };
  500. static struct rpc_version nlm_version3 = {
  501. .number = 3,
  502. .nrprocs = 24,
  503. .procs = nlm_procedures,
  504. };
  505. #ifdef CONFIG_LOCKD_V4
  506. extern struct rpc_version nlm_version4;
  507. #endif
  508. static struct rpc_version * nlm_versions[] = {
  509. [1] = &nlm_version1,
  510. [3] = &nlm_version3,
  511. #ifdef CONFIG_LOCKD_V4
  512. [4] = &nlm_version4,
  513. #endif
  514. };
  515. static struct rpc_stat nlm_stats;
  516. struct rpc_program nlm_program = {
  517. .name = "lockd",
  518. .number = NLM_PROGRAM,
  519. .nrvers = ARRAY_SIZE(nlm_versions),
  520. .version = nlm_versions,
  521. .stats = &nlm_stats,
  522. };
  523. #ifdef RPC_DEBUG
  524. const char *nlmdbg_cookie2a(const struct nlm_cookie *cookie)
  525. {
  526. /*
  527. * We can get away with a static buffer because we're only
  528. * called with BKL held.
  529. */
  530. static char buf[2*NLM_MAXCOOKIELEN+1];
  531. int i;
  532. int len = sizeof(buf);
  533. char *p = buf;
  534. len--; /* allow for trailing \0 */
  535. if (len < 3)
  536. return "???";
  537. for (i = 0 ; i < cookie->len ; i++) {
  538. if (len < 2) {
  539. strcpy(p-3, "...");
  540. break;
  541. }
  542. sprintf(p, "%02x", cookie->data[i]);
  543. p += 2;
  544. len -= 2;
  545. }
  546. *p = '\0';
  547. return buf;
  548. }
  549. #endif