Forráskód Böngészése

-hash option will remove NA and EU hash from MTA config files when decoded

Hash will only be commented so that you can re-encode the file
with -na or -eu option and not have the hash.
-na|-eu should be used in conjunction with -nohash
AdrianSimionov 9 éve
szülő
commit
f37298cf0f
3 módosított fájl, 61 hozzáadás és 4 törlés
  1. 27 3
      src/docsis.c
  2. 33 1
      src/docsis_decode.c
  3. 1 0
      src/docsis_globals.h

+ 27 - 3
src/docsis.c

@@ -46,6 +46,7 @@
 
 struct tlv *global_tlvtree_head;
 symbol_type *global_symtable;
+unsigned int nohash = 0;
 
 static void setup_mib_flags(int resolve_oids, char *custom_mibs);
 
@@ -188,6 +189,9 @@ usage ()
   fprintf(stderr, "\nTo add SHA1 hash to mta config file, use -na or -eu options:\n");
   fprintf(stderr, "\tdocsis -na|-eu -p <mta_cfg_file> <output_file>\n");
   fprintf(stderr, "\tdocsis -na|-eu -m -p <mta_file1> ...  <new_extension>\n");
+  fprintf(stderr, "\nTo remove hash from MTA config file, use -nohash option:\n");
+  fprintf(stderr, "\tdocsis -nohash -d <mta_cfg_file>\n");
+  fprintf(stderr, "\tdocsis -nohash -o -d <mta_cfg_file>\n");
   fprintf(stderr, "\nWhere:\n<cfg_file>\t\t= name of text (human readable) cable modem or MTA \n"
 		  "\t\t\t  configuration file;\n"
 		  "<key_file>\t\t= text file containing the authentication key\n"
@@ -212,17 +216,37 @@ main (int argc, char *argv[])
   unsigned int encode_docsis = FALSE, decode_bin = FALSE, hash = 0;
   int i;
   int resolve_oids = 1;
-
   if (argc < 2 ) {
 	usage();
   }
 
-  /* option: -o -d */
-  if (!strcmp (argv[1], "-o") ){
+  /* option: -nohash -o -d */
+  if (!strcmp (argv[1], "-nohash") ){
+    nohash = 1;
+    if (!strcmp (argv[2], "-o") ){
+      resolve_oids = 0;
+      if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_OID_OUTPUT_NUMERIC)) {
+        netsnmp_ds_toggle_boolean (NETSNMP_DS_LIBRARY_ID, NETSNMP_OID_OUTPUT_NUMERIC);
+      }
+      if (!strcmp (argv[3], "-d")) {
+        decode_bin = TRUE;
+        config_file = argv[4];
+      } else {
+        usage();
+      }
+    } else if (!strcmp (argv[2], "-d")) {
+      decode_bin = TRUE;
+      config_file = argv[3];
+    } else {
+      usage();
+    }
+  /* option -o -d */
+  } else if (!strcmp (argv[1], "-o") ){
     resolve_oids = 0;
     if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_OID_OUTPUT_NUMERIC)) {
       netsnmp_ds_toggle_boolean (NETSNMP_DS_LIBRARY_ID, NETSNMP_OID_OUTPUT_NUMERIC);
     }
+
     if (!strcmp (argv[2], "-d")) {
       decode_bin = TRUE;
       config_file = argv[3];

+ 33 - 1
src/docsis_decode.c

@@ -293,10 +293,42 @@ void decode_oid (unsigned char *tlvbuf, symbol_type *sym, size_t length )
 
 void decode_snmp_object (unsigned char *tlvbuf, symbol_type *sym, size_t length )
 {
+  void *pj = malloc(17);
+  void *pi = malloc(17);
+  void *pk = malloc(15);
+  void *pl = malloc(15);
+
+  if (nohash) {
+    memcpy (pi, "\x30\x26\x06\x0e\x2b\x06\x01\x04\x01\xa3\x0b\x02\x02\x01\x01\x02\x07", 17);
+    memcpy (pj, tlvbuf, 17);
+    if ( *(int*)pi == *(int*)pj ) {
+      printf("/* ");
+      printf("%s ", sym->sym_ident);
+      decode_vbind (tlvbuf, length );
+      printf(" */");
+      printf("\n");
+      return;
+    }
+    memcpy (pk, "\x30\x24\x06\x0c\x2b\x06\x01\x04\x01\xba\x08\x01\x01\x02\x09", 15);
+    memcpy (pl, tlvbuf, 15);
+    if ( *(int*)pk == *(int*)pl ) {
+      printf("/* ");
+      printf("%s ", sym->sym_ident);
+      decode_vbind (tlvbuf, length );
+      printf(" */");
+      printf("\n");
+      return;
+    }
+  }
+
   printf("%s ", sym->sym_ident);
   decode_vbind (tlvbuf, length );
-/*  22-06-03  decode_vbind prints the trailing ';' as well  */
   printf("\n");
+
+  free(pi);
+  free(pj);
+  free(pk);
+  free(pl);
 }
 
 void decode_string (unsigned char *tlvbuf, symbol_type *sym, size_t length )

+ 1 - 0
src/docsis_globals.h

@@ -27,5 +27,6 @@
 extern struct tlv *global_tlvtree_head;
 extern symbol_type *global_symtable;
 extern unsigned int line;	/* defined in docsis_lex.l */
+extern unsigned int nohash;
 
 #endif /* _DOCSIS_GLOBALS_H */