OpenDNSSEC-enforcer  2.0.3
policy_list_cmd.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Surfnet
3  * Copyright (c) 2011 .SE (The Internet Infrastructure Foundation).
4  * Copyright (c) 2011 OpenDNSSEC AB (svb)
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 #include "config.h"
31 
32 #include "daemon/cmdhandler.h"
33 #include "log.h"
34 #include "str.h"
35 #include "daemon/engine.h"
36 #include "clientpipe.h"
37 #include "db/policy.h"
38 
39 #include "policy/policy_list_cmd.h"
40 
41 /* static const char *module_str = "policy_list_cmd"; */
42 
43 static void
44 usage(int sockfd)
45 {
46  client_printf(sockfd,
47  "policy list\n");
48 }
49 
50 static void
51 help(int sockfd)
52 {
53  client_printf(sockfd,
54  "List all policies in the database.\n\n"
55  );
56 }
57 
58 static int
59 handles(const char *cmd, ssize_t n)
60 {
61  return ods_check_command(cmd, n, policy_list_funcblock()->cmdname)?1:0;
62 }
63 
64 static int
65 run(int sockfd, engine_type* engine, const char *cmd, ssize_t n,
66  db_connection_t *dbconn)
67 {
68  const char *fmt = "%-31s %-48s\n";
69  policy_list_t *pol_list;
70  const policy_t *policy;
71  (void)cmd; (void)n; (void)engine;
72 
73  if (!(pol_list = policy_list_new_get(dbconn)))
74  return 1;
75 
76  /* May want to keep this for compatibility?
77  * client_printf(sockfd, "Database set to: %s\nPolicies:\n",
78  engine->config->datastore);*/
79  client_printf(sockfd, fmt, "Policy:", "Description:");
80 
81  policy = policy_list_next(pol_list);
82  while (policy) {
83  client_printf(sockfd, fmt, policy_name(policy),
84  policy_description(policy));
85  policy = policy_list_next(pol_list);
86  }
87  policy_list_free(pol_list);
88  return 0;
89 }
90 
91 static struct cmd_func_block funcblock = {
92  "policy list", &usage, &help, &handles, &run
93 };
94 
95 struct cmd_func_block*
97 {
98  return &funcblock;
99 }
void(* help)(int sockfd)
Definition: cmdhandler.h:64
void policy_list_free(policy_list_t *policy_list)
Definition: policy.c:2664
const char * policy_name(const policy_t *policy)
Definition: policy.c:813
int(* run)(int sockfd, struct engine_struct *engine, const char *cmd, ssize_t n, db_connection_t *dbconn)
Definition: cmdhandler.h:79
const char * cmdname
Definition: cmdhandler.h:59
void(* usage)(int sockfd)
Definition: cmdhandler.h:61
struct cmd_func_block * policy_list_funcblock(void)
policy_list_t * policy_list_new_get(const db_connection_t *connection)
Definition: policy.c:3076
const char * policy_description(const policy_t *policy)
Definition: policy.c:821
const policy_t * policy_list_next(policy_list_t *policy_list)
Definition: policy.c:3211
Definition: policy.h:60
int(* handles)(const char *cmd, ssize_t n)
Definition: cmdhandler.h:67