* Portions copyright (c) 1999, 2000\r
* Intel Corporation.\r
* All rights reserved.\r
- * \r
+ *\r
* Redistribution and use in source and binary forms, with or without\r
* modification, are permitted provided that the following conditions\r
* are met:\r
- * \r
+ *\r
* 1. Redistributions of source code must retain the above copyright\r
* notice, this list of conditions and the following disclaimer.\r
- * \r
+ *\r
* 2. Redistributions in binary form must reproduce the above copyright\r
* notice, this list of conditions and the following disclaimer in the\r
* documentation and/or other materials provided with the distribution.\r
- * \r
+ *\r
* 3. All advertising materials mentioning features or use of this software\r
* must display the following acknowledgement:\r
- * \r
+ *\r
* This product includes software developed by Intel Corporation and\r
* its contributors.\r
- * \r
+ *\r
* 4. Neither the name of Intel Corporation or its contributors may be\r
* used to endorse or promote products derived from this software\r
* without specific prior written permission.\r
- * \r
+ *\r
* THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''\r
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF\r
* THE POSSIBILITY OF SUCH DAMAGE.\r
- * \r
+ *\r
+ base64.c,v 1.1.1.1 2003/11/19 01:51:25 kyu3 Exp\r
*/\r
\r
-#if !defined(LINT) && !defined(CODECENTER)\r
-static char rcsid[] = "$Id: base64.c,v 1.1.1.1 2003/11/19 01:51:25 kyu3 Exp $";\r
-#endif /* not lint */\r
-\r
#include <sys/types.h>\r
#include <sys/param.h>\r
#include <sys/socket.h>\r
#define Assert(Cond) if (!(Cond)) abort()\r
\r
static const char Base64[] =\r
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";\r
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";\r
static const char Pad64 = '=';\r
\r
/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt)\r
end of the data is performed using the '=' character.\r
\r
Since all base64 input is an integral number of octets, only the\r
- ------------------------------------------------- \r
+ -------------------------------------------------\r
following cases can arise:\r
- \r
+\r
(1) the final quantum of encoding input is an integral\r
multiple of 24 bits; here, the final unit of encoded\r
- output will be an integral multiple of 4 characters\r
- with no "=" padding,\r
+ output will be an integral multiple of 4 characters\r
+ with no "=" padding,\r
(2) the final quantum of encoding input is exactly 8 bits;\r
here, the final unit of encoded output will be two\r
- characters followed by two "=" padding characters, or\r
+ characters followed by two "=" padding characters, or\r
(3) the final quantum of encoding input is exactly 16 bits;\r
here, the final unit of encoded output will be three\r
- characters followed by one "=" padding character.\r
+ characters followed by one "=" padding character.\r
*/\r
\r
int\r
b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) {\r
- size_t datalength = 0;\r
- u_char input[3];\r
- u_char output[4];\r
- size_t i;\r
-\r
- while (2 < srclength) {\r
- input[0] = *src++;\r
- input[1] = *src++;\r
- input[2] = *src++;\r
- srclength -= 3;\r
-\r
- output[0] = input[0] >> 2;\r
- output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);\r
- output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);\r
- output[3] = input[2] & 0x3f;\r
- Assert(output[0] < 64);\r
- Assert(output[1] < 64);\r
- Assert(output[2] < 64);\r
- Assert(output[3] < 64);\r
-\r
- if (datalength + 4 > targsize)\r
- return (-1);\r
- target[datalength++] = Base64[output[0]];\r
- target[datalength++] = Base64[output[1]];\r
- target[datalength++] = Base64[output[2]];\r
- target[datalength++] = Base64[output[3]];\r
- }\r
- \r
- /* Now we worry about padding. */\r
- if (0 != srclength) {\r
- /* Get what's left. */\r
- input[0] = input[1] = input[2] = '\0';\r
- for (i = 0; i < srclength; i++)\r
- input[i] = *src++;\r
- \r
- output[0] = input[0] >> 2;\r
- output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);\r
- output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);\r
- Assert(output[0] < 64);\r
- Assert(output[1] < 64);\r
- Assert(output[2] < 64);\r
-\r
- if (datalength + 4 > targsize)\r
- return (-1);\r
- target[datalength++] = Base64[output[0]];\r
- target[datalength++] = Base64[output[1]];\r
- if (srclength == 1)\r
- target[datalength++] = Pad64;\r
- else\r
- target[datalength++] = Base64[output[2]];\r
- target[datalength++] = Pad64;\r
- }\r
- if (datalength >= targsize)\r
- return (-1);\r
- target[datalength] = '\0'; /* Returned value doesn't count \0. */\r
- return ((int)datalength);\r
+ size_t datalength = 0;\r
+ u_char input[3];\r
+ u_char output[4];\r
+ size_t i;\r
+\r
+ while (2 < srclength) {\r
+ input[0] = *src++;\r
+ input[1] = *src++;\r
+ input[2] = *src++;\r
+ srclength -= 3;\r
+\r
+ output[0] = input[0] >> 2;\r
+ output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);\r
+ output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);\r
+ output[3] = input[2] & 0x3f;\r
+ Assert(output[0] < 64);\r
+ Assert(output[1] < 64);\r
+ Assert(output[2] < 64);\r
+ Assert(output[3] < 64);\r
+\r
+ if (datalength + 4 > targsize)\r
+ return (-1);\r
+ target[datalength++] = Base64[output[0]];\r
+ target[datalength++] = Base64[output[1]];\r
+ target[datalength++] = Base64[output[2]];\r
+ target[datalength++] = Base64[output[3]];\r
+ }\r
+\r
+ /* Now we worry about padding. */\r
+ if (0 != srclength) {\r
+ /* Get what's left. */\r
+ input[0] = input[1] = input[2] = '\0';\r
+ for (i = 0; i < srclength; i++)\r
+ input[i] = *src++;\r
+\r
+ output[0] = input[0] >> 2;\r
+ output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);\r
+ output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);\r
+ Assert(output[0] < 64);\r
+ Assert(output[1] < 64);\r
+ Assert(output[2] < 64);\r
+\r
+ if (datalength + 4 > targsize)\r
+ return (-1);\r
+ target[datalength++] = Base64[output[0]];\r
+ target[datalength++] = Base64[output[1]];\r
+ if (srclength == 1)\r
+ target[datalength++] = Pad64;\r
+ else\r
+ target[datalength++] = Base64[output[2]];\r
+ target[datalength++] = Pad64;\r
+ }\r
+ if (datalength >= targsize)\r
+ return (-1);\r
+ target[datalength] = '\0'; /* Returned value doesn't count \0. */\r
+ return ((int)datalength);\r
}\r
\r
/* skips all whitespace anywhere.\r
\r
int\r
b64_pton(\r
- char const *src,\r
- u_char *target,\r
- size_t targsize\r
- )\r
+ char const *src,\r
+ u_char *target,\r
+ size_t targsize\r
+ )\r
{\r
- int tarindex, state, ch;\r
- char *pos;\r
-\r
- state = 0;\r
- tarindex = 0;\r
-\r
- while ((ch = *src++) != '\0') {\r
- if (isspace(ch)) /* Skip whitespace anywhere. */\r
- continue;\r
-\r
- if (ch == Pad64)\r
- break;\r
-\r
- pos = strchr(Base64, ch);\r
- if (pos == 0) /* A non-base64 character. */\r
- return (-1);\r
-\r
- switch (state) {\r
- case 0:\r
- if (target) {\r
- if ((size_t)tarindex >= targsize)\r
- return (-1);\r
- target[tarindex] = (u_char)((pos - Base64) << 2);\r
- }\r
- state = 1;\r
- break;\r
- case 1:\r
- if (target) {\r
- if ((size_t)tarindex + 1 >= targsize)\r
- return (-1);\r
- target[tarindex] |= (u_char)((pos - Base64) >> 4);\r
- target[tarindex+1] = (u_char)(((pos - Base64) & 0x0f)\r
- << 4) ;\r
- }\r
- tarindex++;\r
- state = 2;\r
- break;\r
- case 2:\r
- if (target) {\r
- if ((size_t)tarindex + 1 >= targsize)\r
- return (-1);\r
- target[tarindex] |= (u_char)((pos - Base64) >> 2);\r
- target[tarindex+1] = (u_char)(((pos - Base64) & 0x03)\r
- << 6);\r
- }\r
- tarindex++;\r
- state = 3;\r
- break;\r
- case 3:\r
- if (target) {\r
- if ((size_t)tarindex >= targsize)\r
- return (-1);\r
- target[tarindex] |= (u_char)(pos - Base64);\r
- }\r
- tarindex++;\r
- state = 0;\r
- break;\r
- default:\r
- abort();\r
- }\r
- }\r
-\r
- /*\r
- * We are done decoding Base-64 chars. Let's see if we ended\r
- * on a byte boundary, and/or with erroneous trailing characters.\r
- */\r
-\r
- if (ch == Pad64) { /* We got a pad char. */\r
- ch = *src++; /* Skip it, get next. */\r
- switch (state) {\r
- case 0: /* Invalid = in first position */\r
- case 1: /* Invalid = in second position */\r
- return (-1);\r
-\r
- case 2: /* Valid, means one byte of info */\r
- /* Skip any number of spaces. */\r
- for ((void)NULL; ch != '\0'; ch = *src++)\r
- if (!isspace(ch))\r
- break;\r
- /* Make sure there is another trailing = sign. */\r
- if (ch != Pad64)\r
- return (-1);\r
- ch = *src++; /* Skip the = */\r
- /* Fall through to "single trailing =" case. */\r
- /* FALLTHROUGH */\r
-\r
- case 3: /* Valid, means two bytes of info */\r
- /*\r
- * We know this char is an =. Is there anything but\r
- * whitespace after it?\r
- */\r
- for ((void)NULL; ch != '\0'; ch = *src++)\r
- if (!isspace(ch))\r
- return (-1);\r
-\r
- /*\r
- * Now make sure for cases 2 and 3 that the "extra"\r
- * bits that slopped past the last full byte were\r
- * zeros. If we don't check them, they become a\r
- * subliminal channel.\r
- */\r
- if (target && target[tarindex] != 0)\r
- return (-1);\r
- }\r
- } else {\r
- /*\r
- * We ended by seeing the end of the string. Make sure we\r
- * have no partial bytes lying around.\r
- */\r
- if (state != 0)\r
- return (-1);\r
- }\r
-\r
- return (tarindex);\r
+ int tarindex, state, ch;\r
+ char *pos;\r
+\r
+ state = 0;\r
+ tarindex = 0;\r
+\r
+ while ((ch = *src++) != '\0') {\r
+ if (isspace(ch)) /* Skip whitespace anywhere. */\r
+ continue;\r
+\r
+ if (ch == Pad64)\r
+ break;\r
+\r
+ pos = strchr(Base64, ch);\r
+ if (pos == 0) /* A non-base64 character. */\r
+ return (-1);\r
+\r
+ switch (state) {\r
+ case 0:\r
+ if (target) {\r
+ if ((size_t)tarindex >= targsize)\r
+ return (-1);\r
+ target[tarindex] = (u_char)((pos - Base64) << 2);\r
+ }\r
+ state = 1;\r
+ break;\r
+ case 1:\r
+ if (target) {\r
+ if ((size_t)tarindex + 1 >= targsize)\r
+ return (-1);\r
+ target[tarindex] |= (u_char)((pos - Base64) >> 4);\r
+ target[tarindex+1] = (u_char)(((pos - Base64) & 0x0f)\r
+ << 4) ;\r
+ }\r
+ tarindex++;\r
+ state = 2;\r
+ break;\r
+ case 2:\r
+ if (target) {\r
+ if ((size_t)tarindex + 1 >= targsize)\r
+ return (-1);\r
+ target[tarindex] |= (u_char)((pos - Base64) >> 2);\r
+ target[tarindex+1] = (u_char)(((pos - Base64) & 0x03)\r
+ << 6);\r
+ }\r
+ tarindex++;\r
+ state = 3;\r
+ break;\r
+ case 3:\r
+ if (target) {\r
+ if ((size_t)tarindex >= targsize)\r
+ return (-1);\r
+ target[tarindex] |= (u_char)(pos - Base64);\r
+ }\r
+ tarindex++;\r
+ state = 0;\r
+ break;\r
+ default:\r
+ abort();\r
+ }\r
+ }\r
+\r
+ /*\r
+ * We are done decoding Base-64 chars. Let's see if we ended\r
+ * on a byte boundary, and/or with erroneous trailing characters.\r
+ */\r
+\r
+ if (ch == Pad64) { /* We got a pad char. */\r
+ ch = *src++; /* Skip it, get next. */\r
+ switch (state) {\r
+ case 0: /* Invalid = in first position */\r
+ case 1: /* Invalid = in second position */\r
+ return (-1);\r
+\r
+ case 2: /* Valid, means one byte of info */\r
+ /* Skip any number of spaces. */\r
+ for ((void)NULL; ch != '\0'; ch = *src++)\r
+ if (!isspace(ch))\r
+ break;\r
+ /* Make sure there is another trailing = sign. */\r
+ if (ch != Pad64)\r
+ return (-1);\r
+ ch = *src++; /* Skip the = */\r
+ /* Fall through to "single trailing =" case. */\r
+ /* FALLTHROUGH */\r
+\r
+ case 3: /* Valid, means two bytes of info */\r
+ /*\r
+ * We know this char is an =. Is there anything but\r
+ * whitespace after it?\r
+ */\r
+ for ((void)NULL; ch != '\0'; ch = *src++)\r
+ if (!isspace(ch))\r
+ return (-1);\r
+\r
+ /*\r
+ * Now make sure for cases 2 and 3 that the "extra"\r
+ * bits that slopped past the last full byte were\r
+ * zeros. If we don't check them, they become a\r
+ * subliminal channel.\r
+ */\r
+ if (target && target[tarindex] != 0)\r
+ return (-1);\r
+ }\r
+ } else {\r
+ /*\r
+ * We ended by seeing the end of the string. Make sure we\r
+ * have no partial bytes lying around.\r
+ */\r
+ if (state != 0)\r
+ return (-1);\r
+ }\r
+\r
+ return (tarindex);\r
}\r
/*\r
* Copyright (c) 1987, 1993\r
- * The Regents of the University of California. All rights reserved.\r
+ * The Regents of the University of California. All rights reserved.\r
*\r
* Portions copyright (c) 1999, 2000\r
* Intel Corporation.\r
* All rights reserved.\r
- * \r
+ *\r
* Redistribution and use in source and binary forms, with or without\r
* modification, are permitted provided that the following conditions\r
* are met:\r
- * \r
+ *\r
* 1. Redistributions of source code must retain the above copyright\r
* notice, this list of conditions and the following disclaimer.\r
- * \r
+ *\r
* 2. Redistributions in binary form must reproduce the above copyright\r
* notice, this list of conditions and the following disclaimer in the\r
* documentation and/or other materials provided with the distribution.\r
- * \r
+ *\r
* 3. All advertising materials mentioning features or use of this software\r
* must display the following acknowledgement:\r
- * \r
+ *\r
* This product includes software developed by the University of\r
* California, Berkeley, Intel Corporation, and its contributors.\r
- * \r
+ *\r
* 4. Neither the name of University, Intel Corporation, or their respective\r
* contributors may be used to endorse or promote products derived from\r
* this software without specific prior written permission.\r
- * \r
+ *\r
* THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND\r
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\r
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\r
* SOFTWARE.\r
- */\r
\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-static char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93";\r
-static char rcsid[] = "$Id: herror.c,v 1.1.1.1 2003/11/19 01:51:28 kyu3 Exp $";\r
-#endif /* LIBC_SCCS and not lint */\r
+ herror.c 8.1 (Berkeley) 6/4/93\r
+ herror.c,v 1.1.1.1 2003/11/19 01:51:28 kyu3 Exp\r
+ */\r
\r
#include <sys/types.h>\r
#include <sys/uio.h>\r
#include <unistd.h>\r
\r
const char *h_errlist[] = {\r
- "Resolver Error 0 (no error)",\r
- "Unknown host", /* 1 HOST_NOT_FOUND */\r
- "Host name lookup failure", /* 2 TRY_AGAIN */\r
- "Unknown server error", /* 3 NO_RECOVERY */\r
- "No address associated with name", /* 4 NO_ADDRESS */\r
+ "Resolver Error 0 (no error)",\r
+ "Unknown host", /* 1 HOST_NOT_FOUND */\r
+ "Host name lookup failure", /* 2 TRY_AGAIN */\r
+ "Unknown server error", /* 3 NO_RECOVERY */\r
+ "No address associated with name", /* 4 NO_ADDRESS */\r
};\r
-int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };\r
+int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };\r
\r
-int h_errno;\r
+int h_errno;\r
\r
const char *\r
hstrerror(\r
\r
/*\r
* herror --\r
- * print the error indicated by the h_errno value.\r
+ * print the error indicated by the h_errno value.\r
*/\r
void\r
herror(\r
- const char *s\r
- )\r
+ const char *s\r
+ )\r
{\r
- struct iovec iov[4];\r
- register struct iovec *v = iov;\r
- int i;\r
+ struct iovec iov[4];\r
+ register struct iovec *v = iov;\r
+ int i;\r
\r
- if (s && *s) {\r
- v->iov_base = (char *)s;\r
- v->iov_len = strlen(s);\r
- v++;\r
- v->iov_base = ": ";\r
- v->iov_len = 2;\r
- v++;\r
- }\r
- v->iov_base = (char *)hstrerror(h_errno);\r
- v->iov_len = strlen(v->iov_base);\r
- v++;\r
- v->iov_base = "\n";\r
- v->iov_len = 1;\r
+ if (s && *s) {\r
+ v->iov_base = (char *)s;\r
+ v->iov_len = strlen(s);\r
+ v++;\r
+ v->iov_base = ": ";\r
+ v->iov_len = 2;\r
+ v++;\r
+ }\r
+ v->iov_base = (char *)hstrerror(h_errno);\r
+ v->iov_len = strlen(v->iov_base);\r
+ v++;\r
+ v->iov_base = "\n";\r
+ v->iov_len = 1;\r
#ifdef _ORG_FREEBSD_\r
- writev(STDERR_FILENO, iov, (v - iov) + 1);\r
+ writev(STDERR_FILENO, iov, (v - iov) + 1);\r
#else\r
- for (i = 0; i < (v - iov) + 1; i++)\r
- fprintf( stderr, iov[i].iov_base);\r
+ for (i = 0; i < (v - iov) + 1; i++)\r
+ fprintf( stderr, iov[i].iov_base);\r
#endif\r
\r
}\r
\r
const char *\r
hstrerror(\r
- int err\r
- )\r
+ int err\r
+ )\r
{\r
- if (err < 0)\r
- return ("Resolver internal error");\r
- else if (err < h_nerr)\r
- return (h_errlist[err]);\r
- return ("Unknown resolver error");\r
+ if (err < 0)\r
+ return ("Resolver internal error");\r
+ else if (err < h_nerr)\r
+ return (h_errlist[err]);\r
+ return ("Unknown resolver error");\r
}\r