| 1 | --- snmplib/parse.c |
| 2 | +++ snmplib/parse.c |
| 3 | @@ -3902,8 +3902,13 @@ read_module_internal(const char *name) |
| 4 | return MODULE_ALREADY_LOADED; |
| 5 | } |
| 6 | if ((fp = fopen(mp->file, "r")) == NULL) { |
| 7 | + int rval; |
| 8 | + if (errno == ENOTDIR || errno == ENOENT) |
| 9 | + rval = MODULE_NOT_FOUND; |
| 10 | + else |
| 11 | + rval = MODULE_LOAD_FAILED; |
| 12 | snmp_log_perror(mp->file); |
| 13 | - return MODULE_LOAD_FAILED; |
| 14 | + return rval; |
| 15 | } |
| 16 | mp->no_imports = 0; /* Note that we've read the file */ |
| 17 | File = mp->file; |
| 18 | @@ -3917,10 +3922,7 @@ read_module_internal(const char *name) |
| 19 | File = oldFile; |
| 20 | mibLine = oldLine; |
| 21 | current_module = oldModule; |
| 22 | - if (np != NULL) |
| 23 | - return MODULE_LOADED_OK; |
| 24 | - else if (gMibError == MODULE_SYNTAX_ERROR) |
| 25 | - return MODULE_SYNTAX_ERROR; |
| 26 | + return gMibError ? gMibError : MODULE_LOADED_OK; |
| 27 | } |
| 28 | |
| 29 | return MODULE_NOT_FOUND; |
| 30 | @@ -4339,6 +4341,7 @@ parse(FILE * fp, struct node *root) |
| 31 | case END: |
| 32 | if (state != IN_MIB) { |
| 33 | print_error("Error, END before start of MIB", NULL, type); |
| 34 | + gMibError = MODULE_SYNTAX_ERROR; |
| 35 | return NULL; |
| 36 | } else { |
| 37 | struct module *mp; |
| 38 | @@ -4403,6 +4406,7 @@ parse(FILE * fp, struct node *root) |
| 39 | nnp = parse_macro(fp, name); |
| 40 | if (nnp == NULL) { |
| 41 | print_error("Bad parse of MACRO", NULL, type); |
| 42 | + gMibError = MODULE_SYNTAX_ERROR; |
| 43 | /* |
| 44 | * return NULL; |
| 45 | */ |
| 46 | @@ -4427,6 +4431,7 @@ parse(FILE * fp, struct node *root) |
| 47 | type = get_token(fp, token, MAXTOKEN); |
| 48 | if (type == ENDOFFILE) { |
| 49 | print_error("Expected \"}\"", token, type); |
| 50 | + gMibError = MODULE_SYNTAX_ERROR; |
| 51 | return NULL; |
| 52 | } |
| 53 | type = get_token(fp, token, MAXTOKEN); |
| 54 | @@ -4436,6 +4441,7 @@ parse(FILE * fp, struct node *root) |
| 55 | case DEFINITIONS: |
| 56 | if (state != BETWEEN_MIBS) { |
| 57 | print_error("Error, nested MIBS", NULL, type); |
| 58 | + gMibError = MODULE_SYNTAX_ERROR; |
| 59 | return NULL; |
| 60 | } |
| 61 | state = IN_MIB; |
| 62 | @@ -4460,6 +4466,7 @@ parse(FILE * fp, struct node *root) |
| 63 | nnp = parse_objecttype(fp, name); |
| 64 | if (nnp == NULL) { |
| 65 | print_error("Bad parse of OBJECT-TYPE", NULL, type); |
| 66 | + gMibError = MODULE_SYNTAX_ERROR; |
| 67 | return NULL; |
| 68 | } |
| 69 | break; |
| 70 | @@ -4467,6 +4474,7 @@ parse(FILE * fp, struct node *root) |
| 71 | nnp = parse_objectgroup(fp, name, OBJECTS, &objects); |
| 72 | if (nnp == NULL) { |
| 73 | print_error("Bad parse of OBJECT-GROUP", NULL, type); |
| 74 | + gMibError = MODULE_SYNTAX_ERROR; |
| 75 | return NULL; |
| 76 | } |
| 77 | break; |
| 78 | @@ -4474,6 +4482,7 @@ parse(FILE * fp, struct node *root) |
| 79 | nnp = parse_objectgroup(fp, name, NOTIFICATIONS, ¬ifs); |
| 80 | if (nnp == NULL) { |
| 81 | print_error("Bad parse of NOTIFICATION-GROUP", NULL, type); |
| 82 | + gMibError = MODULE_SYNTAX_ERROR; |
| 83 | return NULL; |
| 84 | } |
| 85 | break; |
| 86 | @@ -4481,6 +4490,7 @@ parse(FILE * fp, struct node *root) |
| 87 | nnp = parse_trapDefinition(fp, name); |
| 88 | if (nnp == NULL) { |
| 89 | print_error("Bad parse of TRAP-TYPE", NULL, type); |
| 90 | + gMibError = MODULE_SYNTAX_ERROR; |
| 91 | return NULL; |
| 92 | } |
| 93 | break; |
| 94 | @@ -4488,6 +4498,7 @@ parse(FILE * fp, struct node *root) |
| 95 | nnp = parse_notificationDefinition(fp, name); |
| 96 | if (nnp == NULL) { |
| 97 | print_error("Bad parse of NOTIFICATION-TYPE", NULL, type); |
| 98 | + gMibError = MODULE_SYNTAX_ERROR; |
| 99 | return NULL; |
| 100 | } |
| 101 | break; |
| 102 | @@ -4495,6 +4506,7 @@ parse(FILE * fp, struct node *root) |
| 103 | nnp = parse_compliance(fp, name); |
| 104 | if (nnp == NULL) { |
| 105 | print_error("Bad parse of MODULE-COMPLIANCE", NULL, type); |
| 106 | + gMibError = MODULE_SYNTAX_ERROR; |
| 107 | return NULL; |
| 108 | } |
| 109 | break; |
| 110 | @@ -4502,6 +4514,7 @@ parse(FILE * fp, struct node *root) |
| 111 | nnp = parse_capabilities(fp, name); |
| 112 | if (nnp == NULL) { |
| 113 | print_error("Bad parse of AGENT-CAPABILITIES", NULL, type); |
| 114 | + gMibError = MODULE_SYNTAX_ERROR; |
| 115 | return NULL; |
| 116 | } |
| 117 | break; |
| 118 | @@ -4509,6 +4522,7 @@ parse(FILE * fp, struct node *root) |
| 119 | nnp = parse_macro(fp, name); |
| 120 | if (nnp == NULL) { |
| 121 | print_error("Bad parse of MACRO", NULL, type); |
| 122 | + gMibError = MODULE_SYNTAX_ERROR; |
| 123 | /* |
| 124 | * return NULL; |
| 125 | */ |
| 126 | @@ -4520,6 +4534,7 @@ parse(FILE * fp, struct node *root) |
| 127 | nnp = parse_moduleIdentity(fp, name); |
| 128 | if (nnp == NULL) { |
| 129 | print_error("Bad parse of MODULE-IDENTITY", NULL, type); |
| 130 | + gMibError = MODULE_SYNTAX_ERROR; |
| 131 | return NULL; |
| 132 | } |
| 133 | break; |
| 134 | @@ -4527,6 +4542,7 @@ parse(FILE * fp, struct node *root) |
| 135 | nnp = parse_objectgroup(fp, name, OBJECTS, &objects); |
| 136 | if (nnp == NULL) { |
| 137 | print_error("Bad parse of OBJECT-IDENTITY", NULL, type); |
| 138 | + gMibError = MODULE_SYNTAX_ERROR; |
| 139 | return NULL; |
| 140 | } |
| 141 | break; |
| 142 | @@ -4534,16 +4550,19 @@ parse(FILE * fp, struct node *root) |
| 143 | type = get_token(fp, token, MAXTOKEN); |
| 144 | if (type != IDENTIFIER) { |
| 145 | print_error("Expected IDENTIFIER", token, type); |
| 146 | + gMibError = MODULE_SYNTAX_ERROR; |
| 147 | return NULL; |
| 148 | } |
| 149 | type = get_token(fp, token, MAXTOKEN); |
| 150 | if (type != EQUALS) { |
| 151 | print_error("Expected \"::=\"", token, type); |
| 152 | + gMibError = MODULE_SYNTAX_ERROR; |
| 153 | return NULL; |
| 154 | } |
| 155 | nnp = parse_objectid(fp, name); |
| 156 | if (nnp == NULL) { |
| 157 | print_error("Bad parse of OBJECT IDENTIFIER", NULL, type); |
| 158 | + gMibError = MODULE_SYNTAX_ERROR; |
| 159 | return NULL; |
| 160 | } |
| 161 | break; |
| 162 | @@ -4555,6 +4574,7 @@ parse(FILE * fp, struct node *root) |
| 163 | break; |
| 164 | default: |
| 165 | print_error("Bad operator", token, type); |
| 166 | + gMibError = MODULE_SYNTAX_ERROR; |
| 167 | return NULL; |
| 168 | } |
| 169 | if (nnp) { |
| 170 | No newline at end of file |