52#if HAVE_KRB5_MEMORY_KEYTAB
53typedef struct _krb5_kt_list {
54 struct _krb5_kt_list *next;
55 krb5_keytab_entry *entry;
57krb5_kt_list ktlist =
nullptr;
59krb5_keytab memory_keytab;
61krb5_error_code krb5_free_kt_list(krb5_context context, krb5_kt_list kt_list);
62krb5_error_code krb5_write_keytab(krb5_context context,
65krb5_error_code krb5_read_keytab(krb5_context context,
67 krb5_kt_list *kt_list);
71check_k5_err(krb5_context context,
const char *function, krb5_error_code
code)
76 errmsg = krb5_get_error_message(context,
code);
78 fprintf(stderr,
"%s| %s: ERROR: %s: %s\n",
LogTime(),
PROGRAM, function, errmsg);
79#if HAVE_KRB5_FREE_ERROR_MESSAGE
80 krb5_free_error_message(context, errmsg);
81#elif HAVE_KRB5_FREE_ERROR_STRING
82 krb5_free_error_string(context, (
char *)errmsg);
97 struct addrinfo *hres =
nullptr, *hres_list;
100 rc = gethostname(hostname,
sizeof(hostname)-1);
102 debug((
char *)
"%s| %s: ERROR: resolving hostname '%s' failed\n",
LogTime(),
PROGRAM, hostname);
103 fprintf(stderr,
"%s| %s: ERROR: resolving hostname '%s' failed\n",
107 rc = getaddrinfo(hostname,
nullptr,
nullptr, &hres);
108 if (rc != 0 || hres ==
nullptr ) {
109 debug((
char *)
"%s| %s: ERROR: resolving hostname with getaddrinfo: %s failed\n",
112 "%s| %s: ERROR: resolving hostname with getaddrinfo: %s failed\n",
118 hres_list = hres_list->ai_next;
120 rc = getnameinfo(hres->ai_addr, hres->ai_addrlen, hostname,
121 sizeof(hostname),
nullptr, 0, 0);
123 debug((
char *)
"%s| %s: ERROR: resolving ip address with getnameinfo: %s failed\n",
126 "%s| %s: ERROR: resolving ip address with getnameinfo: %s failed\n",
132 hostname[
sizeof(hostname)-1] =
'\0';
138 const char *function,
int log,
int sout)
140 if (GSS_ERROR(major_status)) {
141 OM_uint32 maj_stat, min_stat;
142 OM_uint32 msg_ctx = 0;
143 gss_buffer_desc status_string;
151 maj_stat = gss_display_status(&min_stat, major_status,
152 GSS_C_GSS_CODE, GSS_C_NULL_OID, &msg_ctx, &status_string);
153 if (maj_stat == GSS_S_COMPLETE && status_string.length > 0) {
154 if (
sizeof(buf) > len + status_string.length + 1) {
155 snprintf(buf + len, (
sizeof(buf) - len),
"%s", (
char *) status_string.value);
156 len += status_string.length;
160 gss_release_buffer(&min_stat, &status_string);
162 if (
sizeof(buf) > len + 2) {
163 snprintf(buf + len, (
sizeof(buf) - len),
"%s",
". ");
169 maj_stat = gss_display_status(&min_stat, minor_status,
170 GSS_C_MECH_CODE, GSS_C_NULL_OID, &msg_ctx, &status_string);
171 if (maj_stat == GSS_S_COMPLETE && status_string.length > 0) {
172 if (
sizeof(buf) > len + status_string.length) {
173 snprintf(buf + len, (
sizeof(buf) - len),
"%s", (
char *) status_string.value);
174 len += status_string.length;
178 gss_release_buffer(&min_stat, &status_string);
182 fprintf(stdout,
"BH %s failed: %s\n", function, buf);
184 fprintf(stderr,
"%s| %s: INFO: User not authenticated\n",
LogTime(),
191#if HAVE_KRB5_MEMORY_KEYTAB
195krb5_error_code krb5_free_kt_list(krb5_context context, krb5_kt_list list)
197 krb5_kt_list lp = list;
200#if USE_HEIMDAL_KRB5 || ( HAVE_KRB5_KT_FREE_ENTRY && HAVE_DECL_KRB5_KT_FREE_ENTRY )
201 krb5_error_code retval = krb5_kt_free_entry(context, lp->entry);
203 krb5_error_code retval = krb5_free_keytab_entry_contents(context, lp->entry);
206 if (
check_k5_err(context,
"krb5_kt_free_entry", retval))
208 krb5_kt_list prev = lp;
218krb5_error_code krb5_read_keytab(krb5_context context,
char *name, krb5_kt_list *list)
220 krb5_kt_list lp =
nullptr, tail =
nullptr, back =
nullptr;
222 krb5_keytab_entry *entry;
223 krb5_kt_cursor cursor;
224 krb5_error_code retval = 0;
228 for (lp = *list; lp->next; lp = lp->next);
231 retval = krb5_kt_resolve(context, name, &kt);
234 retval = krb5_kt_start_seq_get(context, kt, &cursor);
235 if (
check_k5_err(context,
"krb5_kt_start_seq_get", retval))
238 entry = (krb5_keytab_entry *)
xcalloc(1,
sizeof (krb5_keytab_entry));
241 debug((
char *)
"%s| %s: ERROR: krb5_read_keytab failed: %s\n",
243 fprintf(stderr,
"%s| %s: ERROR: krb5_read_keytab: %s\n",
247 memset(entry, 0,
sizeof (*entry));
248 retval = krb5_kt_next_entry(context, kt, entry, &cursor);
249 if (
check_k5_err(context,
"krb5_kt_next_entry", retval))
253 lp = (krb5_kt_list)
xmalloc(
sizeof (*lp));
256 debug((
char *)
"%s| %s: ERROR: krb5_read_keytab failed: %s\n",
258 fprintf(stderr,
"%s| %s: ERROR: krb5_read_keytab: %s\n",
263 lp->next = (krb5_kt_list)
xmalloc(
sizeof (*lp));
266 debug((
char *)
"%s| %s: ERROR: krb5_read_keytab failed: %s\n",
268 fprintf(stderr,
"%s| %s: ERROR: krb5_read_keytab: %s\n",
281 if (retval == KRB5_KT_END)
284 krb5_free_kt_list(context, tail);
287 back->next =
nullptr;
292 krb5_kt_end_seq_get(context, kt, &cursor);
294 krb5_kt_close(context, kt);
301krb5_error_code krb5_write_keytab(krb5_context context, krb5_kt_list list,
char *name)
304 krb5_error_code retval = 0;
306 snprintf(ktname,
sizeof(ktname),
"%s", name);
307 retval = krb5_kt_resolve(context, ktname, &memory_keytab);
310 for (krb5_kt_list lp = list; lp; lp = lp->next) {
311 retval = krb5_kt_add_entry(context, memory_keytab, lp->entry);
323main(
int argc,
char *
const argv[])
327 char *user =
nullptr;
328 char *rfc_user =
nullptr;
330 char ad_groups[MAX_PAC_GROUP_SIZE];
334 gss_buffer_desc data_set = GSS_C_EMPTY_BUFFER;
336 gss_buffer_desc type_id = GSS_C_EMPTY_BUFFER;
339 krb5_context context =
nullptr;
343 int opt,
log = 0, norealm = 0;
344 OM_uint32 ret_flags = 0, spnego_flag = 0;
345 char *
service_name = (
char *)
"HTTP", *host_name =
nullptr;
346 char *token =
nullptr;
347 char *service_principal =
nullptr;
348 char *keytab_name =
nullptr;
349 char *keytab_name_env =
nullptr;
351#if HAVE_KRB5_MEMORY_KEYTAB
352 char *memory_keytab_name =
nullptr;
353 char *memory_keytab_name_env =
nullptr;
355 char *rcache_type =
nullptr;
356 char *rcache_type_env =
nullptr;
357 char *rcache_dir =
nullptr;
358 char *rcache_dir_env =
nullptr;
359 OM_uint32 major_status, minor_status;
360 gss_ctx_id_t gss_context = GSS_C_NO_CONTEXT;
361 gss_name_t client_name = GSS_C_NO_NAME;
362 gss_name_t server_name = GSS_C_NO_NAME;
363 gss_cred_id_t server_creds = GSS_C_NO_CREDENTIAL;
364 gss_buffer_desc service = GSS_C_EMPTY_BUFFER;
365 gss_buffer_desc input_token = GSS_C_EMPTY_BUFFER;
366 gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER;
367 const unsigned char *kerberosToken =
nullptr;
368 const unsigned char *spnegoToken =
nullptr;
369 size_t spnegoTokenLength = 0;
371 setbuf(stdout,
nullptr);
372 setbuf(stdin,
nullptr);
374 while (-1 != (opt =
getopt(argc, argv,
"dirs:k:c:t:"))) {
393 fprintf(stderr,
"ERROR: keytab file not given\n");
400 if ((ktp=strchr(keytab_name,
':')))
404 if (stat((
const char*)ktp, &fstat)) {
406 fprintf(stderr,
"ERROR: keytab file %s does not exist\n",keytab_name);
408 fprintf(stderr,
"ERROR: Error %s during stat of keytab file %s\n",
strerror(errno),keytab_name);
410 }
else if (!S_ISREG(fstat.st_mode)) {
411 fprintf(stderr,
"ERROR: keytab file %s is not a file\n",keytab_name);
416 if (access(ktp, R_OK)) {
417 fprintf(stderr,
"ERROR: keytab file %s is not accessible\n",keytab_name);
429 fprintf(stderr,
"ERROR: replay cache directory not given\n");
436 if (stat((
const char*)rcache_dir, &dstat)) {
438 fprintf(stderr,
"ERROR: replay cache directory %s does not exist\n",rcache_dir);
440 fprintf(stderr,
"ERROR: Error %s during stat of replay cache directory %s\n",
strerror(errno),rcache_dir);
442 }
else if (!S_ISDIR(dstat.st_mode)) {
443 fprintf(stderr,
"ERROR: replay cache directory %s is not a directory\n",rcache_dir);
448 if (access(rcache_dir, W_OK)) {
449 fprintf(stderr,
"ERROR: replay cache directory %s is not accessible\n",rcache_dir);
458 fprintf(stderr,
"ERROR: replay cache type not given\n");
466 fprintf(stderr,
"ERROR: service principal not given\n");
471 fprintf(stderr,
"Usage: \n");
472 fprintf(stderr,
"squid_kerb_auth [-d] [-i] [-s SPN] [-k keytab] [-c rcdir] [-t rctype]\n");
473 fprintf(stderr,
"-d full debug\n");
474 fprintf(stderr,
"-i informational messages\n");
475 fprintf(stderr,
"-r remove realm from username\n");
476 fprintf(stderr,
"-s service principal name\n");
477 fprintf(stderr,
"-k keytab name\n");
478 fprintf(stderr,
"-c replay cache directory\n");
479 fprintf(stderr,
"-t replay cache type\n");
481 "The SPN can be set to GSS_C_NO_NAME to allow any entry from keytab\n");
482 fprintf(stderr,
"default SPN is HTTP/fqdn@DEFAULT_REALM\n");
488 if (service_principal && strcasecmp(service_principal,
"GSS_C_NO_NAME")) {
489 if (!strstr(service_principal,
"HTTP/")) {
490 debug((
char *)
"%s| %s: WARN: service_principal %s does not start with HTTP/\n",
493 service.value = service_principal;
494 service.length = strlen((
char *) service.value);
499 "%s| %s: FATAL: Local hostname could not be determined. Please specify the service principal\n",
501 fprintf(stdout,
"BH hostname error\n");
505 snprintf((
char *) service.value, strlen(
service_name) + strlen(host_name) + 2,
507 service.length = strlen((
char *) service.value);
512 rcache_type_env = (
char *)
xmalloc(strlen(
"KRB5RCACHETYPE=")+strlen(rcache_type)+1);
513 strcpy(rcache_type_env,
"KRB5RCACHETYPE=");
514 strcat(rcache_type_env, rcache_type);
515 putenv(rcache_type_env);
516 debug((
char *)
"%s| %s: INFO: Setting replay cache type to %s\n",
521 rcache_dir_env = (
char *)
xmalloc(strlen(
"KRB5RCACHEDIR=")+strlen(rcache_dir)+1);
522 strcpy(rcache_dir_env,
"KRB5RCACHEDIR=");
523 strcat(rcache_dir_env, rcache_dir);
524 putenv(rcache_dir_env);
525 debug((
char *)
"%s| %s: INFO: Setting replay cache directory to %s\n",
530 keytab_name_env = (
char *)
xmalloc(strlen(
"KRB5_KTNAME=")+strlen(keytab_name)+1);
531 strcpy(keytab_name_env,
"KRB5_KTNAME=");
532 strcat(keytab_name_env, keytab_name);
533 putenv(keytab_name_env);
535 keytab_name_env = getenv(
"KRB5_KTNAME");
536 if (!keytab_name_env) {
537 ret = krb5_init_context(&context);
539 krb5_kt_default_name(context, default_keytab,
MAXPATHLEN);
541 keytab_name =
xstrdup(default_keytab);
542 krb5_free_context(context);
544 keytab_name =
xstrdup(keytab_name_env);
547#if HAVE_KRB5_MEMORY_KEYTAB
548 ret = krb5_init_context(&context);
550 memory_keytab_name = (
char *)
xmalloc(strlen(
"MEMORY:negotiate_kerberos_auth_")+16);
551 snprintf(memory_keytab_name, strlen(
"MEMORY:negotiate_kerberos_auth_")+16,
552 "MEMORY:negotiate_kerberos_auth_%d", (
unsigned int) getpid());
553 ret = krb5_read_keytab(context, keytab_name, &ktlist);
555 debug((
char *)
"%s| %s: ERROR: Reading keytab %s into list failed\n",
558 ret = krb5_write_keytab(context, ktlist, memory_keytab_name);
560 debug((
char *)
"%s| %s: ERROR: Writing list into keytab %s\n",
563 memory_keytab_name_env = (
char *)
xmalloc(strlen(
"KRB5_KTNAME=")+strlen(memory_keytab_name)+1);
564 strcpy(memory_keytab_name_env,
"KRB5_KTNAME=");
565 strcat(memory_keytab_name_env, memory_keytab_name);
566 putenv(memory_keytab_name_env);
568 keytab_name =
xstrdup(memory_keytab_name);
569 debug((
char *)
"%s| %s: INFO: Changed keytab to %s\n",
573 ret = krb5_free_kt_list(context,ktlist);
575 debug((
char *)
"%s| %s: ERROR: Freeing list failed\n",
579 krb5_free_context(context);
581#ifdef HAVE_HEIMDAL_KERBEROS
582 gsskrb5_register_acceptor_identity(keytab_name);
585 if (fgets(buf,
sizeof(buf) - 1, stdin) ==
nullptr) {
587 debug((
char *)
"%s| %s: FATAL: fgets() failed! dying..... errno=%d (%s)\n",
591 fprintf(stdout,
"BH input error\n");
594 fprintf(stdout,
"BH input error\n");
597 c = (
char *) memchr(buf,
'\n',
sizeof(buf) - 1);
606 fprintf(stdout,
"BH Oversized message\n");
610 debug((
char *)
"%s| %s: DEBUG: Got '%s' from squid (length: %ld).\n",
LogTime(),
PROGRAM, buf, length);
612 if (buf[0] ==
'\0') {
614 fprintf(stdout,
"BH Invalid request\n");
617 if (strlen(buf) < 2) {
619 fprintf(stdout,
"BH Invalid request\n");
622 if (!strncmp(buf,
"QQ", 2)) {
623 gss_release_buffer(&minor_status, &input_token);
624 gss_release_buffer(&minor_status, &output_token);
625 gss_release_buffer(&minor_status, &service);
626 gss_release_cred(&minor_status, &server_creds);
628 gss_release_name(&minor_status, &server_name);
630 gss_release_name(&minor_status, &client_name);
631 if (gss_context != GSS_C_NO_CONTEXT)
632 gss_delete_sec_context(&minor_status, &gss_context,
nullptr);
636 xfree(kerberosToken);
644 xfree(rcache_type_env);
646 xfree(rcache_dir_env);
648 xfree(keytab_name_env);
649#if HAVE_KRB5_MEMORY_KEYTAB
650 krb5_kt_close(context, memory_keytab);
651 xfree(memory_keytab_name);
652 xfree(memory_keytab_name_env);
655 fprintf(stdout,
"BH quit command\n");
658 if (strncmp(buf,
"YR", 2) && strncmp(buf,
"KK", 2)) {
660 fprintf(stdout,
"BH Invalid request\n");
663 if (!strncmp(buf,
"YR", 2)) {
664 if (gss_context != GSS_C_NO_CONTEXT)
665 gss_delete_sec_context(&minor_status, &gss_context,
nullptr);
666 gss_context = GSS_C_NO_CONTEXT;
668 if (strlen(buf) <= 3) {
669 debug((
char *)
"%s| %s: ERROR: Invalid negotiate request [%s]\n",
LogTime(),
PROGRAM, buf);
670 fprintf(stdout,
"BH Invalid negotiate request\n");
673 const char *b64Token = buf+3;
674 const size_t srcLen = strlen(buf+3);
676 debug((
char *)
"%s| %s: DEBUG: Decode '%s' (decoded length estimate: %d).\n",
678 input_token.value =
xmalloc(input_token.length);
683 if (!
base64_decode_update(&ctx, &dstLen,
static_cast<uint8_t*
>(input_token.value), srcLen, b64Token) ||
685 debug((
char *)
"%s| %s: ERROR: Invalid base64 token [%s]\n",
LogTime(),
PROGRAM, b64Token);
686 fprintf(stdout,
"BH Invalid negotiate request token\n");
689 input_token.length = dstLen;
693 debug((
char *)
"%s| %s: WARNING: received type %d NTLM token\n",
695 (
int) *((
unsigned char *) input_token.value +
697 fprintf(stdout,
"BH received type %d NTLM token\n",
698 (
int) *((
unsigned char *) input_token.value +
702 if (service_principal) {
703 if (strcasecmp(service_principal,
"GSS_C_NO_NAME")) {
704 major_status = gss_import_name(&minor_status, &service,
705 (gss_OID) GSS_C_NULL_OID, &server_name);
708 server_name = GSS_C_NO_NAME;
709 major_status = GSS_S_COMPLETE;
713 major_status = gss_import_name(&minor_status, &service,
721 gss_acquire_cred(&minor_status, server_name, GSS_C_INDEFINITE,
722 GSS_C_NO_OID_SET, GSS_C_ACCEPT, &server_creds,
nullptr,
nullptr);
723 if (
check_gss_err(major_status, minor_status,
"gss_acquire_cred()",
log, 1))
726 major_status = gss_accept_sec_context(&minor_status,
730 GSS_C_NO_CHANNEL_BINDINGS,
731 &client_name,
nullptr, &output_token, &ret_flags,
nullptr,
nullptr);
733 if (output_token.length) {
734 spnegoToken = (
const unsigned char *) output_token.value;
735 spnegoTokenLength = output_token.length;
737 if (token ==
nullptr) {
739 fprintf(stdout,
"BH Not enough memory\n");
744 size_t blen =
base64_encode_update(&tokCtx, token, spnegoTokenLength,
reinterpret_cast<const uint8_t*
>(spnegoToken));
748 if (
check_gss_err(major_status, minor_status,
"gss_accept_sec_context()",
log, 1))
750 if (major_status & GSS_S_CONTINUE_NEEDED) {
752 fprintf(stdout,
"TT token=%s\n", token);
755 gss_release_buffer(&minor_status, &output_token);
757 gss_display_name(&minor_status, client_name, &output_token,
760 if (
check_gss_err(major_status, minor_status,
"gss_display_name()",
log, 1))
762 user = (
char *)
xmalloc(output_token.length + 1);
763 if (user ==
nullptr) {
765 fprintf(stdout,
"BH Not enough memory\n");
768 memcpy(user, output_token.value, output_token.length);
769 user[output_token.length] =
'\0';
770 if (norealm && (p = strchr(user,
'@')) !=
nullptr) {
775 ret = krb5_init_context(&context);
778#define ADWIN2KPAC 128
779 major_status = gsskrb5_extract_authz_data_from_sec_context(&minor_status,
780 gss_context, ADWIN2KPAC, &data_set);
782 "gsskrb5_extract_authz_data_from_sec_context()",
log, 0)) {
783 ret = krb5_pac_parse(context, data_set.value, data_set.length, &pac);
784 gss_release_buffer(&minor_status, &data_set);
786 ag = get_ad_groups((
char *)&ad_groups, context, pac);
787 krb5_pac_free(context, pac);
789 krb5_free_context(context);
792 type_id.value = (
void *)
"mspac";
793 type_id.length = strlen((
char *)type_id.value);
794#define KRB5PACLOGONINFO 1
795 major_status = gss_map_name_to_any(&minor_status, client_name, KRB5PACLOGONINFO, &type_id, (gss_any_t *)&pac);
796 if (!
check_gss_err(major_status, minor_status,
"gss_map_name_to_any()",
log, 0)) {
797 ag = get_ad_groups((
char *)&ad_groups,context, pac);
799 (void)gss_release_any_name_mapping(&minor_status, client_name, &type_id, (gss_any_t *)&pac);
800 krb5_free_context(context);
809 fprintf(stdout,
"OK token=%s user=%s %s\n", token, rfc_user, ag?ag:
"group=");
811 fprintf(stdout,
"OK token=%s user=%s\n", token, rfc_user);
813 debug((
char *)
"%s| %s: DEBUG: OK token=%s user=%s\n",
LogTime(),
PROGRAM, token, rfc_user);
815 fprintf(stderr,
"%s| %s: INFO: User %s authenticated\n",
LogTime(),
819 if (
check_gss_err(major_status, minor_status,
"gss_accept_sec_context()",
log, 1))
821 if (major_status & GSS_S_CONTINUE_NEEDED) {
824 fprintf(stdout,
"ERR\n");
827 gss_release_buffer(&minor_status, &output_token);
829 gss_display_name(&minor_status, client_name, &output_token,
832 if (
check_gss_err(major_status, minor_status,
"gss_display_name()",
log, 1))
837 user = (
char *)
xmalloc(output_token.length + 1);
838 if (user ==
nullptr) {
840 fprintf(stdout,
"BH Not enough memory\n");
843 memcpy(user, output_token.value, output_token.length);
844 user[output_token.length] =
'\0';
845 if (norealm && (p = strchr(user,
'@')) !=
nullptr) {
850 fprintf(stdout,
"OK token=%s user=%s %s\n",
"AA==", rfc_user, ag?ag:
"group=");
852 fprintf(stdout,
"OK token=%s user=%s\n",
"AA==", rfc_user);
854 debug((
char *)
"%s| %s: DEBUG: OK token=%s user=%s\n",
LogTime(),
PROGRAM,
"AA==", rfc_user);
856 fprintf(stderr,
"%s| %s: INFO: User %s authenticated\n",
LogTime(),
860 gss_release_buffer(&minor_status, &input_token);
861 gss_release_buffer(&minor_status, &output_token);
862 gss_release_cred(&minor_status, &server_creds);
864 gss_release_name(&minor_status, &server_name);
866 gss_release_name(&minor_status, &client_name);
884#ifndef MAX_AUTHTOKEN_LEN
885#define MAX_AUTHTOKEN_LEN 65535
888main(
int argc,
char *
const argv[])
890 setbuf(stdout,
nullptr);
891 setbuf(stdin,
nullptr);
894 if (fgets(buf,
sizeof(buf) - 1, stdin) ==
NULL) {
895 fprintf(stdout,
"BH input error\n");
898 fprintf(stdout,
"BH Kerberos authentication not supported\n");
void log(char *format,...)
const char * LogTime(void)
void base64_encode_init(struct base64_encode_ctx *ctx)
size_t base64_encode_update(struct base64_encode_ctx *ctx, char *dst, size_t length, const uint8_t *src)
void base64_decode_init(struct base64_decode_ctx *ctx)
size_t base64_encode_final(struct base64_encode_ctx *ctx, char *dst)
#define base64_encode_len(length)
int base64_decode_update(struct base64_decode_ctx *ctx, size_t *dst_length, uint8_t *dst, size_t src_length, const char *src)
int base64_decode_final(struct base64_decode_ctx *ctx)
#define BASE64_DECODE_LENGTH(length)
void debug(const char *format,...)
int getopt(int nargc, char *const *nargv, const char *ostr)
#define gss_nt_service_name
char * gethost_name(void)
#define SQUID_KERB_AUTH_VERSION
int check_gss_err(OM_uint32 major_status, OM_uint32 minor_status, const char *function, int log, int sout)
int check_k5_err(krb5_context context, const char *msg, krb5_error_code code)
static const unsigned char ntlmProtocol[]
#define MAX_AUTHTOKEN_LEN
int main(int argc, char *const argv[])
#define rfc1738_escape(x)
void * xcalloc(size_t n, size_t sz)