Fix "make xcheck" in sunrpc.
[platform/upstream/glibc.git] / sunrpc / auth_des.c
index d8659a9..96bbcfc 100644 (file)
@@ -1,36 +1,32 @@
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)auth_des.c 2.2 88/07/29 4.0 RPCSRC; from 1.9 88/02/08 SMI";
-#endif
 /*
- * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
- * unrestricted use provided that this legend is included on all tape
- * media and as a part of the software program in whole or part.  Users
- * may copy or modify Sun RPC without charge, but are not authorized
- * to license or distribute it to anyone else except as part of a product or
- * program developed by the user.
- *
- * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
- * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
- *
- * Sun RPC is provided with no support and without any obligation on the
- * part of Sun Microsystems, Inc. to assist in its use, correction,
- * modification or enhancement.
+ * Copyright (c) 2010, Oracle America, Inc.
  *
- * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
- * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
- * OR ANY PART THEREOF.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
  *
- * In no event will Sun Microsystems, Inc. be liable for any lost revenue
- * or profits or other special, indirect and consequential damages, even if
- * Sun has been advised of the possibility of such damages.
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials
+ *       provided with the distribution.
+ *     * Neither the name of the "Oracle America, Inc." nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
  *
- * Sun Microsystems, Inc.
- * 2550 Garcia Avenue
- * Mountain View, California  94043
- */
-/*
- * Copyright (c) 1988 by Sun Microsystems, Inc.
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 /*
  * auth_des.c, client-side implementation of DES authentication
@@ -55,9 +51,6 @@ static char sccsid[] = "@(#)auth_des.c        2.2 88/07/29 4.0 RPCSRC; from 1.9 88/02/0
 
 #define debug(msg)             /* printf("%s\n", msg) */
 
-extern int rtime (struct sockaddr_in *, struct timeval *, struct timeval *);
-extern bool_t xdr_authdes_cred (XDR *, struct authdes_cred *);
-extern bool_t xdr_authdes_verf (XDR *, struct authdes_verf *);
 
 /*
  * DES authenticator operations vector
@@ -67,10 +60,10 @@ static bool_t authdes_marshal (AUTH *, XDR *);
 static bool_t authdes_validate (AUTH *, struct opaque_auth *);
 static bool_t authdes_refresh (AUTH *);
 static void authdes_destroy (AUTH *);
-static bool_t synchronize (struct sockaddr *, struct timeval *)
+static bool_t synchronize (struct sockaddr *, struct rpc_timeval *)
      internal_function;
 
-static struct auth_ops authdes_ops = {
+static const struct auth_ops authdes_ops = {
   authdes_nextverf,
   authdes_marshal,
   authdes_validate,
@@ -84,19 +77,19 @@ static struct auth_ops authdes_ops = {
  */
 struct ad_private {
   char *ad_fullname;           /* client's full name */
-  u_int ad_fullnamelen;                /* length of name, rounded up */
-  char *ad_servername;         /* server's full name */
+  u_int ad_fullnamelen;                /* length of name, rounded up */
+  char *ad_servername;         /* server's full name */
   u_int ad_servernamelen;      /* length of name, rounded up */
   uint32_t ad_window;          /* client specified window */
   bool_t ad_dosync;            /* synchronize? */
   struct sockaddr ad_syncaddr; /* remote host to synch with */
-  struct timeval ad_timediff;  /* server's time - client's time */
-  u_long ad_nickname;          /* server's nickname for client */
+  struct rpc_timeval ad_timediff;      /* server's time - client's time */
+  uint32_t ad_nickname;                /* server's nickname for client */
   struct authdes_cred ad_cred; /* storage for credential */
   struct authdes_verf ad_verf; /* storage for verifier */
-  struct timeval ad_timestamp; /* timestamp sent */
+  struct rpc_timeval ad_timestamp;     /* timestamp sent */
   des_block ad_xkey;           /* encrypted conversation key */
-  u_char ad_pkey[1024];                /* Servers actual public key */
+  u_char ad_pkey[1024];                /* Servers actual public key */
 };
 
 
@@ -111,16 +104,21 @@ authdes_create (const char *servername, u_int window,
   /* syncaddr   - optional addr of host to sync with */
   /* ckey       - optional conversation key to use */
 {
-  u_char pkey_data[1024];
+  char pkey_data[1024];
   netobj pkey;
 
   if (!getpublickey (servername, pkey_data))
-    return (NULL);
+    return NULL;
 
-  pkey.n_bytes = (char *) pkey_data;
-  pkey.n_len = strlen ((char *) pkey_data) + 1;
+  pkey.n_bytes = pkey_data;
+  pkey.n_len = strlen (pkey_data) + 1;
   return authdes_pk_create (servername, &pkey, window, syncaddr, ckey);
 }
+#ifdef EXPORT_RPC_SYMBOLS
+libc_hidden_def (authdes_create)
+#else
+libc_hidden_nolink (authdes_create, GLIBC_2_1)
+#endif
 
 AUTH *
 authdes_pk_create (const char *servername, netobj *pkey, u_int window,
@@ -135,6 +133,13 @@ authdes_pk_create (const char *servername, netobj *pkey, u_int window,
    */
   auth = ALLOC (AUTH);
   ad = ALLOC (struct ad_private);
+
+  if (auth == NULL || ad == NULL)
+    {
+      debug ("authdes_create: out of memory");
+      goto failed;
+    }
+
   memset (ad, 0, sizeof (struct ad_private));
   memcpy (ad->ad_pkey, pkey->n_bytes, pkey->n_len);
   if (!getnetname (namebuf))
@@ -145,8 +150,7 @@ authdes_pk_create (const char *servername, netobj *pkey, u_int window,
   ad->ad_servernamelen = strlen (servername);
   ad->ad_servername = mem_alloc (ad->ad_servernamelen + 1);
 
-  if (auth == NULL || ad == NULL || ad->ad_fullname == NULL ||
-      ad->ad_servername == NULL)
+  if (ad->ad_fullname == NULL || ad->ad_servername == NULL)
     {
       debug ("authdes_create: out of memory");
       goto failed;
@@ -155,8 +159,8 @@ authdes_pk_create (const char *servername, netobj *pkey, u_int window,
   /*
    * Set up private data
    */
-  bcopy (namebuf, ad->ad_fullname, ad->ad_fullnamelen + 1);
-  bcopy (servername, ad->ad_servername, ad->ad_servernamelen + 1);
+  memcpy (ad->ad_fullname, namebuf, ad->ad_fullnamelen + 1);
+  memcpy (ad->ad_servername, servername, ad->ad_servernamelen + 1);
   ad->ad_timediff.tv_sec = ad->ad_timediff.tv_usec = 0;
   if (syncaddr != NULL)
     {
@@ -172,7 +176,7 @@ authdes_pk_create (const char *servername, netobj *pkey, u_int window,
       if (key_gendes (&auth->ah_key) < 0)
        {
          debug ("authdes_create: unable to gen conversation key");
-         return (NULL);
+         goto failed;
        }
     }
   else
@@ -183,13 +187,13 @@ authdes_pk_create (const char *servername, netobj *pkey, u_int window,
    */
   auth->ah_cred.oa_flavor = AUTH_DES;
   auth->ah_verf.oa_flavor = AUTH_DES;
-  auth->ah_ops = &authdes_ops;
+  auth->ah_ops = (struct auth_ops *) &authdes_ops;
   auth->ah_private = (caddr_t) ad;
 
   if (!authdes_refresh (auth))
     goto failed;
 
-  return (auth);
+  return auth;
 
 failed:
   if (auth != NULL)
@@ -202,8 +206,13 @@ failed:
        FREE (ad->ad_servername, ad->ad_servernamelen + 1);
       FREE (ad, sizeof (struct ad_private));
     }
-  return (NULL);
+  return NULL;
 }
+#ifdef EXPORT_RPC_SYMBOLS
+libc_hidden_def (authdes_pk_create)
+#else
+libc_hidden_nolink (authdes_pk_create, GLIBC_2_1)
+#endif
 
 /*
  * Implement the five authentication operations
@@ -215,7 +224,7 @@ failed:
  */
 /*ARGSUSED */
 static void
-authdes_nextverf (AUTH * auth)
+authdes_nextverf (AUTH *auth)
 {
   /* what the heck am I supposed to do??? */
 }
@@ -226,7 +235,7 @@ authdes_nextverf (AUTH * auth)
  * 2. Marshal
  */
 static bool_t
-authdes_marshal (AUTH * auth, XDR * xdrs)
+authdes_marshal (AUTH *auth, XDR *xdrs)
 {
   struct ad_private *ad = AUTH_PRIVATE (auth);
   struct authdes_cred *cred = &ad->ad_cred;
@@ -234,16 +243,17 @@ authdes_marshal (AUTH * auth, XDR * xdrs)
   des_block cryptbuf[2];
   des_block ivec;
   int status;
-  unsigned int len;
-  register long *ixdr;
+  int len;
+  register int32_t *ixdr;
+  struct timeval tval;
 
   /*
    * Figure out the "time", accounting for any time difference
    * with the server if necessary.
    */
-  __gettimeofday (&ad->ad_timestamp, (struct timezone *) NULL);
-  ad->ad_timestamp.tv_sec += ad->ad_timediff.tv_sec;
-  ad->ad_timestamp.tv_usec += ad->ad_timediff.tv_usec;
+  __gettimeofday (&tval, (struct timezone *) NULL);
+  ad->ad_timestamp.tv_sec = tval.tv_sec + ad->ad_timediff.tv_sec;
+  ad->ad_timestamp.tv_usec = tval.tv_usec + ad->ad_timediff.tv_usec;
   if (ad->ad_timestamp.tv_usec >= MILLION)
     {
       ad->ad_timestamp.tv_usec -= MILLION;
@@ -255,9 +265,9 @@ authdes_marshal (AUTH * auth, XDR * xdrs)
    * encrypt them.
    * XXX We have a real Year 2038 problem here.
    */
-  ixdr = (long *) cryptbuf;
-  IXDR_PUT_LONG (ixdr, ad->ad_timestamp.tv_sec);
-  IXDR_PUT_LONG (ixdr, ad->ad_timestamp.tv_usec);
+  ixdr = (int32_t *) cryptbuf;
+  IXDR_PUT_INT32 (ixdr, ad->ad_timestamp.tv_sec);
+  IXDR_PUT_INT32 (ixdr, ad->ad_timestamp.tv_usec);
   if (ad->ad_cred.adc_namekind == ADN_FULLNAME)
     {
       IXDR_PUT_U_INT32 (ixdr, ad->ad_window);
@@ -267,14 +277,13 @@ authdes_marshal (AUTH * auth, XDR * xdrs)
              2 * sizeof (des_block), DES_ENCRYPT | DES_HW, (char *) &ivec);
     }
   else
-    {
-      status = ecb_crypt ((char *) &auth->ah_key, (char *) cryptbuf,
-                         sizeof (des_block), DES_ENCRYPT | DES_HW);
-    }
+    status = ecb_crypt ((char *) &auth->ah_key, (char *) cryptbuf,
+                       sizeof (des_block), DES_ENCRYPT | DES_HW);
+
   if (DES_FAILED (status))
     {
       debug ("authdes_marshal: DES encryption failure");
-      return (FALSE);
+      return FALSE;
     }
   ad->ad_verf.adv_xtimestamp = cryptbuf[0];
   if (ad->ad_cred.adc_namekind == ADN_FULLNAME)
@@ -293,13 +302,9 @@ authdes_marshal (AUTH * auth, XDR * xdrs)
    * authentication data.
    */
   if (ad->ad_cred.adc_namekind == ADN_FULLNAME)
-    {
-      len = ((1 + 1 + 2 + 1) * BYTES_PER_XDR_UNIT + ad->ad_fullnamelen);
-    }
+    len = ((1 + 1 + 2 + 1) * BYTES_PER_XDR_UNIT + ad->ad_fullnamelen);
   else
-    {
-      len = (1 + 1) * BYTES_PER_XDR_UNIT;
-    }
+    len = (1 + 1) * BYTES_PER_XDR_UNIT;
 
   if ((ixdr = xdr_inline (xdrs, 2 * BYTES_PER_XDR_UNIT)) != NULL)
     {
@@ -325,6 +330,7 @@ authdes_marshal (AUTH * auth, XDR * xdrs)
       ATTEMPT (xdr_putint32 (xdrs, &len));
     }
   ATTEMPT (xdr_authdes_verf (xdrs, verf));
+
   return TRUE;
 }
 
@@ -338,15 +344,15 @@ authdes_validate (AUTH *auth, struct opaque_auth *rverf)
   struct ad_private *ad = AUTH_PRIVATE (auth);
   struct authdes_verf verf;
   int status;
-  register u_long *ixdr;
+  register uint32_t *ixdr;
 
   if (rverf->oa_length != (2 + 1) * BYTES_PER_XDR_UNIT)
-    return (FALSE);
+    return FALSE;
 
-  ixdr = (u_long *) rverf->oa_base;
-  verf.adv_xtimestamp.key.high = (u_long) * ixdr++;
-  verf.adv_xtimestamp.key.low = (u_long) * ixdr++;
-  verf.adv_int_u = (u_long) * ixdr++;  /* nickname not XDR'd ! */
+  ixdr = (uint32_t *) rverf->oa_base;
+  verf.adv_xtimestamp.key.high = *ixdr++;
+  verf.adv_xtimestamp.key.low = *ixdr++;
+  verf.adv_int_u = *ixdr++;    /* nickname not XDR'd ! */
 
   /*
    * Decrypt the timestamp
@@ -363,15 +369,15 @@ authdes_validate (AUTH *auth, struct opaque_auth *rverf)
   /*
    * xdr the decrypted timestamp
    */
-  ixdr = (u_long *) verf.adv_xtimestamp.c;
-  verf.adv_timestamp.tv_sec = IXDR_GET_LONG (ixdr) + 1;
-  verf.adv_timestamp.tv_usec = IXDR_GET_LONG (ixdr);
+  ixdr = (uint32_t *) verf.adv_xtimestamp.c;
+  verf.adv_timestamp.tv_sec = IXDR_GET_U_INT32 (ixdr) + 1;
+  verf.adv_timestamp.tv_usec = IXDR_GET_U_INT32 (ixdr);
 
   /*
    * validate
    */
   if (memcmp ((char *) &ad->ad_timestamp, (char *) &verf.adv_timestamp,
-             sizeof (struct timeval)) != 0)
+             sizeof (struct rpc_timeval)) != 0)
     {
       debug ("authdes_validate: verifier mismatch\n");
       return FALSE;
@@ -395,8 +401,7 @@ authdes_refresh (AUTH *auth)
   struct ad_private *ad = AUTH_PRIVATE (auth);
   struct authdes_cred *cred = &ad->ad_cred;
 
-  if (ad->ad_dosync &&
-      !synchronize (&ad->ad_syncaddr, &ad->ad_timediff))
+  if (ad->ad_dosync && !synchronize (&ad->ad_syncaddr, &ad->ad_timediff))
     {
       /*
        * Hope the clocks are synced!
@@ -438,10 +443,10 @@ authdes_destroy (AUTH *auth)
  */
 static bool_t
 internal_function
-synchronize (struct sockaddr *syncaddr, struct timeval *timep)
+synchronize (struct sockaddr *syncaddr, struct rpc_timeval *timep)
 {
   struct timeval mytime;
-  struct timeval timeout;
+  struct rpc_timeval timeout;
 
   timeout.tv_sec = RTIME_TIMEOUT;
   timeout.tv_usec = 0;