undefined "host"s referenced from "when" keyword are now created automatically
authorshort <>
Tue, 10 Jul 2001 15:08:20 +0000 (15:08 +0000)
committershort <>
Tue, 10 Jul 2001 15:08:20 +0000 (15:08 +0000)
 - suggested by Pavel Ruzicka <pavel.ruzicka@gtsgroup.cz>
 - implemented to match style of the auto-create hosts referenced by "enlist"

cfgeval.c
cfgfile.c
cfgfile.h
users_guide

index 1343a9a..f0aed72 100644 (file)
--- a/cfgeval.c
+++ b/cfgeval.c
@@ -394,11 +394,18 @@ struct expr *parent;
        case S_group:
            tac_list_node_init(&expr->eval_scan.u.entity.notify_expr_node);
            expr->u.entity.entity = entity_lookup(expr->type, expr->u.entity.name);
+           if (!expr->u.entity.entity && expr->type == S_host) {
+               expr->u.entity.entity = new_entity(expr->type, (char *)expr->u.entity.name, expr->line);
+               if (!expr->u.entity.entity)
+                   return (1);
+               expr->u.entity.name = NULL;
+           }
            if (!expr->u.entity.entity) {
                report(LOG_ERR, "referenced entity %s %s not found on line %d",
                        entity_type_to_string(expr->type), expr->u.entity.name, expr->line);
                return (1);
-               }
+           }
+           /* already NULLed for not-yet-existing S_host */
            free((char *) expr->u.entity.name);
            expr->u.entity.name = NULL;
            break;
index 358e962..041993c 100644 (file)
--- a/cfgfile.c
+++ b/cfgfile.c
@@ -53,7 +53,6 @@ static int parse_conditional_block TAC_ARGS((ENTITY *entity));
 static NODE *parse_cmd_matches TAC_ARGS((void));
 static NODE *parse_attrs TAC_ARGS((void));
 static void getsym TAC_ARGS((void));
-static ENTITY *new_entity TAC_ARGS((int type, char *name, int line));
 static enum eval_result entity_svc_default TAC_ARGS((ENTITY *entity));
 
 
@@ -1251,9 +1250,9 @@ ENTITY *entity;
 
 /* passed 'name' WILL be directly stored to returned ENTITY, don't touch it! */
 
-static ENTITY *new_entity TAC_ARGS((int type, char *name, int line));
+ENTITY *new_entity TAC_ARGS((int type, char *name, int line));
 
-static ENTITY *
+ENTITY *
 new_entity(type, name, line)
 int type;
 char *name;
index 747a8b1..3669996 100644 (file)
--- a/cfgfile.h
+++ b/cfgfile.h
@@ -155,6 +155,7 @@ extern void cfg_request_identity TAC_ARGS((const struct identity *identity));
 extern enum eval_result cfg_authorize_cmd TAC_ARGS((const char *username, const char *cmd, const char *args));
 
 /* for use by cfgeval.c: */
+extern ENTITY *new_entity TAC_ARGS((int type, char *name, int line));
 extern const char *entity_type_to_string TAC_ARGS((int entity_type));
 extern void scan_invalidate_entities TAC_ARGS((enum invalidate_scan what));
 extern ENTITY *entity_lookup TAC_ARGS((int type, const char *name));
index 13204b7..c1a8cfd 100644 (file)
@@ -404,7 +404,11 @@ group = city_X_NASes {
 As you can see, "enlist" doesn't require the existence of the given entity as
 it would loose its primary purpose. If the entity doesn't exist it will be
 automatically created (as empty one) - this doesn't apply to "member"! Any
-argument to "member" MUST exist.
+argument to "member" MUST already exist. "enlist" is provided to save you from
+writing a lot of empty definition lines like:
+
+host =  first.NAS.X.city {
+}
 
 All forward references are not a problem, you can still make membership or
 enlistment on the top of the file with the entity which will be defined on the
@@ -1182,12 +1186,16 @@ user = fred {
        }
     }
 }
-host = machine.A.company {
-}
 
    You can see the (nested) command "when" can limit the scope of existence of
-   its contents. Unfortunately you cannot use "when" to limit any items, just
-   a few are possible:
+   its contents. Definition of "host machine.A.company" with empty block (no
+   attributes) isn't needed as "when" line will automatically create hosts not
+   defined elsewhere, in the same style as "enlist" keyword creates them. Any
+   "user"s or "group"s referenced by "when" MUST be defined, such entities are
+   never created automatically!
+   
+   Unfortunately you cannot use "when" to limit any items, just a few of them
+   are possible:
 
 member
 enlist