~ubuntu-branches/ubuntu/vivid/libpam-tacplus/vivid

« back to all changes in this revision

Viewing changes to libtac/lib/hdr_check.c

  • Committer: Bazaar Package Importer
  • Author(s): Jeroen Nijhof
  • Date: 2011-09-05 16:01:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110905160100-7o4aqefbiflj4232
Tags: upstream-1.3.5
ImportĀ upstreamĀ versionĀ 1.3.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* hdr_check.c - Perform basic sanity checks on received packet.
 
2
 * 
 
3
 * Copyright (C) 2010, Pawel Krawczyk <pawel.krawczyk@hush.com> and
 
4
 * Jeroen Nijhof <jeroen@nijhofnet.nl>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program - see the file COPYING.
 
18
 *
 
19
 * See `CHANGES' file for revision history.
 
20
 */
 
21
 
 
22
#include "tacplus.h"
 
23
#include "messages.h"
 
24
#include "libtac.h"
 
25
 
 
26
/* Checks given reply header for possible inconsistencies:
 
27
 *  1. reply type other than expected
 
28
 *  2. sequence number other than 2 or 4
 
29
 *  3. session_id different from one sent in request
 
30
 * Returns pointer to error message
 
31
 * or NULL when the header seems to be correct
 
32
 */
 
33
char *_tac_check_header(HDR *th, int type) {
 
34
    if(th->type != type) {
 
35
        TACSYSLOG((LOG_ERR,\
 
36
            "%s: unrelated reply, type %d, expected %d",\
 
37
            __FUNCTION__, th->type, type))
 
38
        return protocol_err_msg;
 
39
    } else if((th->seq_no != 2) && (th->seq_no != 4)) {
 
40
        TACSYSLOG((LOG_ERR, "%s: not a reply - seq_no %d != {2,4}",\
 
41
            __FUNCTION__, th->seq_no))
 
42
        return protocol_err_msg;
 
43
    } /* else if(ntohl(th->session_id) != session_id) {
 
44
        TACSYSLOG((LOG_ERR,\
 
45
            "%s: unrelated reply, received session_id %d != sent %d",\
 
46
            __FUNCTION__, ntohl(th->session_id), session_id))
 
47
        return protocol_err_msg;
 
48
    } */
 
49
    
 
50
    return NULL; /* header is ok */    
 
51
} /* check header */