1 /*
2   Copyright 2021 Northern.tech AS
3 
4   This file is part of CFEngine 3 - written and maintained by Northern.tech AS.
5 
6   This program is free software; you can redistribute it and/or modify it
7   under the terms of the GNU General Public License as published by the
8   Free Software Foundation; version 3.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
18 
19   To the extent this program is licensed as part of the Enterprise
20   versions of CFEngine, the applicable Commercial Open Source License
21   (COSL) may apply to this file if you as a licensee so wish it. See
22   included file COSL.txt.
23 */
24 #ifndef CFENGINE_STAT_CACHE_H
25 #define CFENGINE_STAT_CACHE_H
26 
27 #include <platform.h>
28 #include <cfnet.h>
29 
30 
31 typedef enum
32 {
33     FILE_TYPE_REGULAR,
34     FILE_TYPE_LINK,
35     FILE_TYPE_DIR,
36     FILE_TYPE_FIFO,
37     FILE_TYPE_BLOCK,
38     FILE_TYPE_CHAR_,                             /* Conflict with winbase.h */
39     FILE_TYPE_SOCK
40 } FileType;
41 
42 typedef struct Stat_ Stat;
43 struct Stat_
44 {
45     char *cf_filename;          /* What file are we statting? */
46     char *cf_server;            /* Which server did this come from? */ //WHY? Isn't this in AgentConn?
47     FileType cf_type;           /* enum filetype */
48     mode_t cf_lmode;            /* Mode of link, if link */
49     mode_t cf_mode;             /* Mode of remote file, not link */
50     uid_t cf_uid;               /* User ID of the file's owner */
51     gid_t cf_gid;               /* Group ID of the file's group */
52     off_t cf_size;              /* File size in bytes */
53     time_t cf_atime;            /* Time of last access */
54     time_t cf_mtime;            /* Time of last data modification */
55     time_t cf_ctime;            /* Time of last file status change */
56     char cf_makeholes;          /* what we need to know from blksize and blks */
57     char *cf_readlink;          /* link value or NULL */
58     int cf_failed;              /* stat returned -1 */
59     int cf_nlink;               /* Number of hard links */
60     int cf_ino;                 /* inode number on server */
61     dev_t cf_dev;               /* device number */
62     Stat *next;
63 };
64 
65 void DestroyStatCache(Stat *data);
66 int cf_remote_stat(AgentConnection *conn, bool encrypt, const char *file,
67                    struct stat *statbuf, const char *stattype);
68 const Stat *StatCacheLookup(const AgentConnection *conn, const char *file_name,
69                             const char *server_name);
70 mode_t FileTypeToMode(const FileType type);
71 bool StatParseResponse(const char *const buf, Stat *statbuf);
72 
73 
74 #endif
75