s4:heimdal: import lorikeet-heimdal-200906080040 (commit 904d0124b46eed7a8ad6e5b73e89...
[samba.git] / source4 / heimdal / lib / roken / getdtablesize.c
similarity index 50%
rename from source4/heimdal/lib/krb5/get_in_tkt_with_keytab.c
rename to source4/heimdal/lib/roken/getdtablesize.c
index 0dedbefd2c3a253cdbbbd0a675afb98b521fdab0..a515af34545018a85f411b2c3b5e160761f38b90 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan
+ * Copyright (c) 1995-2001 Kungliga Tekniska Högskolan
  * (Royal Institute of Technology, Stockholm, Sweden).
  * All rights reserved.
  *
  * SUCH DAMAGE.
  */
 
-#include "krb5_locl.h"
+#include <config.h>
 
-RCSID("$Id$");
+#include "roken.h"
 
-krb5_error_code KRB5_LIB_FUNCTION
-krb5_keytab_key_proc (krb5_context context,
-                     krb5_enctype enctype,
-                     krb5_salt salt,
-                     krb5_const_pointer keyseed,
-                     krb5_keyblock **key)
-{
-    krb5_keytab_key_proc_args *args  = rk_UNCONST(keyseed);
-    krb5_keytab keytab = args->keytab;
-    krb5_principal principal  = args->principal;
-    krb5_error_code ret;
-    krb5_keytab real_keytab;
-    krb5_keytab_entry entry;
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef TIME_WITH_SYS_TIME
+#include <sys/time.h>
+#include <time.h>
+#elif defined(HAVE_SYS_TIME_H)
+#include <sys/time.h>
+#else
+#include <time.h>
+#endif
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
 
-    if(keytab == NULL)
-       krb5_kt_default(context, &real_keytab);
-    else
-       real_keytab = keytab;
+#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
 
-    ret = krb5_kt_get_entry (context, real_keytab, principal,
-                            0, enctype, &entry);
+#ifdef HAVE_SYS_SYSCTL_H
+#include <sys/sysctl.h>
+#endif
 
-    if (keytab == NULL)
-       krb5_kt_close (context, real_keytab);
+int ROKEN_LIB_FUNCTION
+getdtablesize(void)
+{
+  int files = -1;
+#if defined(HAVE_SYSCONF) && defined(_SC_OPEN_MAX)
+  files = sysconf(_SC_OPEN_MAX);
+#else /* !defined(HAVE_SYSCONF) */
+#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
+  struct rlimit res;
+  if (getrlimit(RLIMIT_NOFILE, &res) == 0)
+    files = res.rlim_cur;
+#else /* !definded(HAVE_GETRLIMIT) */
+#if defined(HAVE_SYSCTL) && defined(CTL_KERN) && defined(KERN_MAXFILES)
+  int mib[2];
+  size_t len;
 
-    if (ret)
-       return ret;
+  mib[0] = CTL_KERN;
+  mib[1] = KERN_MAXFILES;
+  len = sizeof(files);
+  sysctl(&mib, 2, &files, sizeof(files), NULL, 0);
+#endif /* defined(HAVE_SYSCTL) */
+#endif /* !definded(HAVE_GETRLIMIT) */
+#endif /* !defined(HAVE_SYSCONF) */
 
-    ret = krb5_copy_keyblock (context, &entry.keyblock, key);
-    krb5_kt_free_entry(context, &entry);
-    return ret;
-}
-
-krb5_error_code KRB5_LIB_FUNCTION
-krb5_get_in_tkt_with_keytab (krb5_context context,
-                            krb5_flags options,
-                            krb5_addresses *addrs,
-                            const krb5_enctype *etypes,
-                            const krb5_preauthtype *pre_auth_types,
-                            krb5_keytab keytab,
-                            krb5_ccache ccache,
-                            krb5_creds *creds,
-                            krb5_kdc_rep *ret_as_reply)
-{
-    krb5_keytab_key_proc_args a;
+#ifdef OPEN_MAX
+  if (files < 0)
+    files = OPEN_MAX;
+#endif
 
-    a.principal = creds->client;
-    a.keytab    = keytab;
+#ifdef NOFILE
+  if (files < 0)
+    files = NOFILE;
+#endif
 
-    return krb5_get_in_tkt (context,
-                           options,
-                           addrs,
-                           etypes,
-                           pre_auth_types,
-                           krb5_keytab_key_proc,
-                           &a,
-                           NULL,
-                           NULL,
-                           creds,
-                           ccache,
-                           ret_as_reply);
+  return files;
 }