mac2pwd.c.html 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. mac2pwd.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='mac2pw.c.html' title=' mac2pw.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='MACPasswords.c.html' title=' MACPasswords.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  24. *
  25. * All rights reserved.
  26. *
  27. * Redistribution and use in source and binary forms, with or
  28. * without modification, are permitted (subject to the limitations
  29. * in the disclaimer below) provided that the following conditions
  30. * are met:
  31. *
  32. * * Redistributions of source code must retain the above copyright
  33. * notice, this list of conditions and the following disclaimer.
  34. *
  35. * * Redistributions in binary form must reproduce the above
  36. * copyright notice, this list of conditions and the following
  37. * disclaimer in the documentation and/or other materials
  38. * provided with the distribution.
  39. *
  40. * * Neither the name of Qualcomm Atheros nor the names of
  41. * its contributors may be used to endorse or promote products
  42. * derived from this software without specific prior written
  43. * permission.
  44. *
  45. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  46. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  47. * COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR
  48. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  49. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  50. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  51. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  52. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  53. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  54. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  56. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  57. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59. *
  60. *--------------------------------------------------------------------*/
  61. #define _GETOPT_H
  62. /*====================================================================*
  63. * system header files;
  64. *--------------------------------------------------------------------*/
  65. #include &lt;stdio.h&gt;
  66. #include &lt;ctype.h&gt;
  67. #include &lt;errno.h&gt;
  68. #include &lt;limits.h&gt;
  69. /*====================================================================*
  70. * custom header files;
  71. *--------------------------------------------------------------------*/
  72. #include &quot;../tools/getoptv.h&quot;
  73. #include &quot;../tools/putoptv.h&quot;
  74. #include &quot;../tools/memory.h&quot;
  75. #include &quot;../tools/number.h&quot;
  76. #include &quot;../tools/types.h&quot;
  77. #include &quot;../tools/flags.h&quot;
  78. #include &quot;../tools/error.h&quot;
  79. #include &quot;../key/keys.h&quot;
  80. /*====================================================================*
  81. * custom source files;
  82. *--------------------------------------------------------------------*/
  83. #ifndef MAKEFILE
  84. #include &quot;../tools/getoptv.c&quot;
  85. #include &quot;../tools/putoptv.c&quot;
  86. #include &quot;../tools/version.c&quot;
  87. #include &quot;../tools/todigit.c&quot;
  88. #include &quot;../tools/uintspec.c&quot;
  89. #include &quot;../tools/error.c&quot;
  90. #endif
  91. #ifndef MAKEFILE
  92. #include &quot;../key/MACPasswords.c&quot;
  93. #include &quot;../key/RNDPasswords.c&quot;
  94. #include &quot;../key/putpwd.c&quot;
  95. #endif
  96. /*====================================================================*
  97. * program constants;
  98. *--------------------------------------------------------------------*/
  99. #ifndef ETHER_ADDR_LEN
  100. #define ETHER_ADDR_LEN 6
  101. #endif
  102. /*====================================================================*
  103. * program functions;
  104. *--------------------------------------------------------------------*/
  105. void (* generate)(unsigned, unsigned, unsigned, unsigned, unsigned, char, flag_t) = RNDPasswords;
  106. /*====================================================================*
  107. *
  108. * void function (const char * file, unsigned alpha, unsigned bunch, flag_t flags)
  109. *
  110. * read Ethernet hardware address strings from a file and print
  111. * address passwords pairs on stdout;
  112. *
  113. * parse an Ethernet hardware address string into vendor and device
  114. * ID substrings; print a specified number of consecutive addresses
  115. * and password strings having a defined letter count and grouping;
  116. *
  117. * Contributor(s):
  118. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  119. *
  120. *--------------------------------------------------------------------*/
  121. static void function (const char * file, unsigned alpha, unsigned bunch, unsigned space, flag_t flags)
  122. {
  123. extern void (* generate)(unsigned, unsigned, unsigned, unsigned, unsigned, char, flag_t);
  124. unsigned line = 1;
  125. unsigned radix = 0x10;
  126. unsigned width;
  127. unsigned digit;
  128. signed c = getc (stdin);
  129. while (c != EOF)
  130. {
  131. uint32_t vendor = 0;
  132. uint32_t device = 0;
  133. while (isspace (c))
  134. {
  135. if (c == '\n')
  136. {
  137. line++;
  138. }
  139. c = getc (stdin);
  140. }
  141. if ((c == '#') || (c == ';'))
  142. {
  143. do
  144. {
  145. c = getc (stdin);
  146. }
  147. while ((c != '\n') &amp;&amp; (c != EOF));
  148. continue;
  149. }
  150. for (width = 0; width &lt; ETHER_ADDR_LEN; width++)
  151. {
  152. if ((digit = todigit (c)) &lt; radix)
  153. {
  154. vendor *= radix;
  155. vendor += digit;
  156. c = getc (stdin);
  157. continue;
  158. }
  159. error (1, EINVAL, &quot;%s: line %d: Illegal vendor&quot;, file, line);
  160. }
  161. if (!vendor)
  162. {
  163. error (1, EPERM, &quot;%s: line %d: Vendor can't be zero&quot;, file, line);
  164. }
  165. for (width = 0; width &lt; ETHER_ADDR_LEN; width++)
  166. {
  167. if ((digit = todigit (c)) &lt; radix)
  168. {
  169. device *= radix;
  170. device += digit;
  171. c = getc (stdin);
  172. continue;
  173. }
  174. error (1, EINVAL, &quot;%s: line %d: Illegal device&quot;, file, line);
  175. }
  176. if (!device)
  177. {
  178. error (1, EPERM, &quot;%s: line %d: Device can't be zero&quot;, file, line);
  179. }
  180. while (isspace (c))
  181. {
  182. if (c == '\n')
  183. {
  184. line++;
  185. }
  186. c = getc (stdin);
  187. }
  188. generate (vendor, device, 1, alpha, bunch, space, flags);
  189. }
  190. return;
  191. }
  192. /*====================================================================*
  193. *
  194. * int main (int argc, const char * argv []);
  195. *
  196. * read one or more text files containing device address strings
  197. * and print a stream of address/password pairs; device addresses
  198. * must be separated by white space;
  199. *
  200. * Contributor(s):
  201. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  202. *
  203. *--------------------------------------------------------------------*/
  204. #define DEFAULT_ALPHA 25
  205. #define DEFAULT_BUNCH 0
  206. int main (int argc, const char * argv [])
  207. {
  208. extern void (* generate)(unsigned, unsigned, unsigned, unsigned, unsigned, char, flag_t);
  209. static const char * optv [] =
  210. {
  211. &quot;b:el:mqv&quot;,
  212. PUTOPTV_S_FUNNEL,
  213. &quot;Atheros device password generator&quot;,
  214. &quot;b n\tbunching factor [&quot; LITERAL (DEFAULT_BUNCH) &quot;]&quot;,
  215. &quot;e\tbase passwords on host system entropy (more secure)&quot;,
  216. &quot;l n\tpassword letters [&quot; LITERAL (DEFAULT_ALPHA) &quot;]&quot;,
  217. &quot;m\tbase passwords on MAC addresses (non-secure)&quot;,
  218. &quot;q\tomit device address on output&quot;,
  219. &quot;v\tprepend PTS flag on output&quot;,
  220. (const char *)(0)
  221. };
  222. unsigned alpha = DEFAULT_ALPHA;
  223. unsigned bunch = DEFAULT_BUNCH;
  224. unsigned space = '-';
  225. flag_t flags = (flag_t)(0);
  226. signed c;
  227. optind = 1;
  228. while ((c = getoptv (argc, argv, optv)) != -1)
  229. {
  230. switch ((char)(c))
  231. {
  232. case 'b':
  233. bunch = uintspec (optarg, 0, UCHAR_MAX);
  234. break;
  235. case 'e':
  236. generate = RNDPasswords;
  237. break;
  238. case 'l':
  239. alpha = uintspec (optarg, 12, 64);
  240. break;
  241. case 'm':
  242. generate = MACPasswords;
  243. break;
  244. case 'q':
  245. _setbits (flags, PASSWORD_SILENCE);
  246. break;
  247. case 'v':
  248. _setbits (flags, PASSWORD_VERBOSE);
  249. break;
  250. default:
  251. break;
  252. }
  253. }
  254. argc -= optind;
  255. argv += optind;
  256. if (!argc)
  257. {
  258. function (&quot;stdin&quot;, alpha, bunch, space, flags);
  259. }
  260. while ((argv) &amp;&amp; (* argv))
  261. {
  262. if (!freopen (* argv, &quot;rb&quot;, stdin))
  263. {
  264. error (1, EINVAL, &quot;Can't open %s&quot;, * argv);
  265. }
  266. function (* argv, alpha, bunch, space, flags);
  267. argc--;
  268. argv++;
  269. }
  270. return (0);
  271. }
  272. </pre>
  273. <div class='footerlink'>
  274. [<a href='mac2pw.c.html' title=' mac2pw.c '>PREV</a>]
  275. [<a href='toolkit.html' title=' Index '>HOME</a>]
  276. [<a href='MACPasswords.c.html' title=' MACPasswords.c '>NEXT</a>]
  277. </div>
  278. </body>
  279. </html>