xdr.c 14 KB

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