~ubuntu-dev/ubuntu/lucid/zabbix/lucid-201002110857

« back to all changes in this revision

Viewing changes to src/libs/zbxdbhigh/action.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Ablassmeier
  • Date: 2007-07-02 09:06:51 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070702090651-8l6fl3fjw9rh6l2u
Tags: 1:1.4.1-2
Add patch from SVN in order to fix Incorrect processing of character '%'
in user parameters and remote commands.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
** ZABBIX
3
 
** Copyright (C) 2000-2005 SIA Zabbix
4
 
**
5
 
** This program is free software; you can redistribute it and/or modify
6
 
** it under the terms of the GNU General Public License as published by
7
 
** the Free Software Foundation; either version 2 of the License, or
8
 
** (at your option) any later version.
9
 
**
10
 
** This program is distributed in the hope that it will be useful,
11
 
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
** GNU General Public License for more details.
14
 
**
15
 
** You should have received a copy of the GNU General Public License
16
 
** along with this program; if not, write to the Free Software
17
 
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
 
**/
19
 
 
20
 
 
21
 
#include <stdlib.h>
22
 
#include <stdio.h>
23
 
 
24
 
#include <string.h>
25
 
#include <strings.h>
26
 
 
27
 
#include "db.h"
28
 
#include "log.h"
29
 
#include "zlog.h"
30
 
#include "common.h"
31
 
 
32
 
int     DBadd_action(int triggerid, int userid, char *subject, char *message, int scope, int severity, int recipient, int usrgrpid)
33
 
{
34
 
        char    sql[MAX_STRING_LEN];
35
 
        int     actionid;
36
 
        char    subject_esc[ACTION_SUBJECT_LEN_MAX];
37
 
        char    message_esc[MAX_STRING_LEN];
38
 
 
39
 
        DBescape_string(subject,subject_esc,ACTION_SUBJECT_LEN_MAX);
40
 
        DBescape_string(message,message_esc,MAX_STRING_LEN);
41
 
 
42
 
        if(recipient == RECIPIENT_TYPE_GROUP)
43
 
        {
44
 
                userid = usrgrpid;
45
 
        }
46
 
 
47
 
        snprintf(sql, sizeof(sql)-1,"insert into actions (triggerid, userid, subject, message, scope, severity, recipient) values (%d, %d, '%s', '%s', %d, %d, %d)", triggerid, userid, subject_esc, message_esc, scope, severity, recipient);
48
 
 
49
 
        actionid = DBinsert_id(DBexecute(sql), "actions", "actionid");
50
 
 
51
 
        if(actionid==0)
52
 
        {
53
 
                return FAIL;
54
 
        }
55
 
 
56
 
        return actionid;
57
 
}
58
 
 
59
 
int     DBget_action_by_actionid(int actionid,DB_ACTION *action)
60
 
{
61
 
        DB_RESULT       result;
62
 
        DB_ROW          row;
63
 
        char    sql[MAX_STRING_LEN];
64
 
        int     ret = SUCCEED;
65
 
 
66
 
        zabbix_log( LOG_LEVEL_DEBUG, "In DBget_action_by_actionid(%d)", actionid);
67
 
 
68
 
        snprintf(sql,sizeof(sql)-1,"select userid,recipient,subject,message from actions where actionid=%d", actionid);
69
 
        result=DBselect(sql);
70
 
        row=DBfetch(result);
71
 
 
72
 
        if(!row)
73
 
        {
74
 
                ret = FAIL;
75
 
        }
76
 
        else
77
 
        {
78
 
                action->actionid=actionid;
79
 
                action->userid=atoi(row[0]);
80
 
                action->recipient=atoi(row[1]);
81
 
                action->subject=strdup(row[2]);
82
 
                action->message=strdup(row[3]);
83
 
        }
84
 
 
85
 
        DBfree_result(result);
86
 
 
87
 
        return ret;
88
 
}