@@ -192,8 +192,9 @@ print_member_json_int(struct json_container *jsonc,
192
192
{
193
193
struct json_value value ;
194
194
const char * typestr = NULL ;
195
- const char * errstr ;
196
195
short alias_type = UNSPEC ;
196
+ struct alias * a = NULL ;
197
+ const char * errstr ;
197
198
id_t id ;
198
199
debug_decl (print_member_json_int , SUDOERS_DEBUG_UTIL );
199
200
@@ -217,6 +218,37 @@ print_member_json_int(struct json_container *jsonc,
217
218
value .u .string = name ;
218
219
}
219
220
221
+ /* Special handling for ALIAS, which might actually be a WORD. */
222
+ if (type == ALIAS ) {
223
+ switch (word_type ) {
224
+ case TYPE_COMMAND :
225
+ alias_type = CMNDALIAS ;
226
+ typestr = "cmndalias" ;
227
+ break ;
228
+ case TYPE_HOSTNAME :
229
+ alias_type = HOSTALIAS ;
230
+ typestr = "hostalias" ;
231
+ break ;
232
+ case TYPE_RUNASGROUP :
233
+ case TYPE_RUNASUSER :
234
+ alias_type = RUNASALIAS ;
235
+ typestr = "runasalias" ;
236
+ break ;
237
+ case TYPE_USERNAME :
238
+ alias_type = USERALIAS ;
239
+ typestr = "useralias" ;
240
+ break ;
241
+ default :
242
+ sudo_fatalx ("unexpected word type %d" , word_type );
243
+ }
244
+
245
+ a = alias_get (parse_tree , value .u .string , alias_type );
246
+ if (a == NULL && alias_type != CMNDALIAS ) {
247
+ /* Alias does not resolve, treat as WORD instead. */
248
+ type = WORD ;
249
+ }
250
+ }
251
+
220
252
switch (type ) {
221
253
case USERGROUP :
222
254
value .u .string ++ ; /* skip leading '%' */
@@ -293,57 +325,22 @@ print_member_json_int(struct json_container *jsonc,
293
325
}
294
326
break ;
295
327
case ALIAS :
296
- switch (word_type ) {
297
- case TYPE_COMMAND :
298
- if (expand_aliases ) {
299
- alias_type = CMNDALIAS ;
300
- } else {
301
- typestr = "cmndalias" ;
302
- }
303
- break ;
304
- case TYPE_HOSTNAME :
305
- if (expand_aliases ) {
306
- alias_type = HOSTALIAS ;
307
- } else {
308
- typestr = "hostalias" ;
309
- }
310
- break ;
311
- case TYPE_RUNASGROUP :
312
- case TYPE_RUNASUSER :
313
- if (expand_aliases ) {
314
- alias_type = RUNASALIAS ;
315
- } else {
316
- typestr = "runasalias" ;
317
- }
318
- break ;
319
- case TYPE_USERNAME :
320
- if (expand_aliases ) {
321
- alias_type = USERALIAS ;
322
- } else {
323
- typestr = "useralias" ;
324
- }
325
- break ;
326
- default :
327
- sudo_fatalx ("unexpected word type %d" , word_type );
328
- }
328
+ /* handled earlier */
329
329
break ;
330
330
default :
331
331
sudo_fatalx ("unexpected member type %d" , type );
332
332
}
333
333
334
334
if (expand_aliases && type == ALIAS ) {
335
- struct alias * a ;
336
- struct member * m ;
337
-
338
335
/* Print each member of the alias. */
339
- if ((a = alias_get (parse_tree , value .u .string , alias_type )) != NULL ) {
336
+ if (a != NULL ) {
337
+ struct member * m ;
338
+
340
339
TAILQ_FOREACH (m , & a -> members , entries ) {
341
340
if (!print_member_json_int (jsonc , parse_tree , m -> name , m -> type ,
342
- negated ? !m -> negated : m -> negated ,
343
- alias_to_word_type (alias_type ), true))
341
+ negated ? !m -> negated : m -> negated , word_type , true))
344
342
goto oom ;
345
343
}
346
- alias_put (a );
347
344
}
348
345
} else {
349
346
if (negated ) {
@@ -363,9 +360,13 @@ print_member_json_int(struct json_container *jsonc,
363
360
}
364
361
}
365
362
363
+ if (a != NULL )
364
+ alias_put (a );
366
365
debug_return_bool (true);
367
366
oom :
368
367
/* warning printed by caller */
368
+ if (a != NULL )
369
+ alias_put (a );
369
370
debug_return_bool (false);
370
371
}
371
372
0 commit comments