diff options
author | Dean Jansa <djansa@redhat.com> | 2005-09-02 15:45:07 +0000 |
---|---|---|
committer | Dean Jansa <djansa@redhat.com> | 2005-09-02 15:45:07 +0000 |
commit | 4cf615dd407191c966ac60c999a16e1ce94f55d6 (patch) | |
tree | d12b1be26e2897ae148993255cbd741203d5ba63 | |
parent | 149e69ef7bd5f70c0ebd8286c13bdb61747655de (diff) | |
download | qarsh-4cf615dd407191c966ac60c999a16e1ce94f55d6.tar.gz qarsh-4cf615dd407191c966ac60c999a16e1ce94f55d6.tar.xz qarsh-4cf615dd407191c966ac60c999a16e1ce94f55d6.zip |
Add new packet type QP_RSTAT and supporting code.
-rw-r--r-- | qarsh/qarsh_packet.c | 86 | ||||
-rw-r--r-- | qarsh/qarsh_packet.h | 15 | ||||
-rw-r--r-- | qarsh/qarshd.c | 22 |
3 files changed, 122 insertions, 1 deletions
diff --git a/qarsh/qarsh_packet.c b/qarsh/qarsh_packet.c index f3f5559..76fadf1 100644 --- a/qarsh/qarsh_packet.c +++ b/qarsh/qarsh_packet.c @@ -20,6 +20,7 @@ int parse_qp_setuser(xmlXPathContextPtr ctxt, struct qa_packet *qp); int parse_qp_kill(xmlXPathContextPtr ctxt, struct qa_packet *qp); int parse_qp_recvfile(xmlXPathContextPtr ctxt, struct qa_packet *qp); int parse_qp_sendfile(xmlXPathContextPtr ctxt, struct qa_packet *qp); +int parse_qp_rstat(xmlXPathContextPtr ctxt, struct qa_packet *qp); void string_qp_hello(xmlNodePtr node, struct qa_packet *qp); void string_qp_returncode(xmlNodePtr node, struct qa_packet *qp); @@ -30,6 +31,7 @@ void string_qp_setuser(xmlNodePtr node, struct qa_packet *qp); void string_qp_kill(xmlNodePtr node, struct qa_packet *qp); void string_qp_recvfile(xmlNodePtr node, struct qa_packet *qp); void string_qp_sendfile(xmlNodePtr node, struct qa_packet *qp); +void string_qp_rstat(xmlNodePtr node, struct qa_packet *qp); void free_qp_hello(struct qa_packet *qp); void free_qp_returncode(struct qa_packet *qp); @@ -37,6 +39,7 @@ void free_qp_runcmd(struct qa_packet *qp); void free_qp_setuser(struct qa_packet *qp); void free_qp_recvfile(struct qa_packet *qp); void free_qp_sendfile(struct qa_packet *qp); +void free_qp_rstat(struct qa_packet *qp); void dump_qp_ack(struct qa_packet *qp); void dump_qp_runcmd(struct qa_packet *qp); @@ -46,6 +49,7 @@ void dump_qp_setuser(struct qa_packet *qp); void dump_qp_kill(struct qa_packet *qp); void dump_qp_recvfile(struct qa_packet *qp); void dump_qp_sendfile(struct qa_packet *qp); +void dump_qp_rstat(struct qa_packet *qp); struct packet_internals { @@ -115,6 +119,12 @@ struct packet_internals { .pi_string = string_qp_sendfile, .pi_free = free_qp_sendfile, .pi_dump = dump_qp_sendfile + }, { + .pi_name = "rstat", + .pi_parse = parse_qp_rstat, + .pi_string = string_qp_rstat, + .pi_free = free_qp_rstat, + .pi_dump = dump_qp_rstat } }; @@ -273,6 +283,32 @@ parse_qp_sendfile(xmlXPathContextPtr ctxt, struct qa_packet *qp) return 0; } +int +parse_qp_rstat(xmlXPathContextPtr ctxt, struct qa_packet *qp) +{ + char *s; + + qp->qp_rstat.qp_path = get_xpath_string(ctxt, "param[@name='path']"); + + s = get_xpath_string(ctxt, "param[@name='st_mode']"); + qp->qp_rstat.qp_st_mode = atoi(s); + free(s); + + s = get_xpath_string(ctxt, "param[@name='st_uid']"); + qp->qp_rstat.qp_st_uid = atoi(s); + free(s); + + s = get_xpath_string(ctxt, "param[@name='st_gid']"); + qp->qp_rstat.qp_st_gid = atoi(s); + free(s); + + s = get_xpath_string(ctxt, "param[@name='st_size']"); + qp->qp_rstat.qp_st_size = atol(s); + free(s); + + return 0; +} + struct qa_packet * parse_packet(xmlXPathContextPtr ctxt) @@ -462,6 +498,21 @@ void string_qp_sendfile(xmlNodePtr node, struct qa_packet *qp) xmlAddChild(node, make_param("count", tmpstr)); } +void string_qp_rstat(xmlNodePtr node, struct qa_packet *qp) +{ + char tmpstr[32]; + + xmlAddChild(node, make_param("path", qp->qp_rstat.qp_path)); + snprintf(tmpstr, 32, "%d", qp->qp_rstat.qp_st_mode); + xmlAddChild(node, make_param("st_mode", tmpstr)); + snprintf(tmpstr, 32, "%d", qp->qp_rstat.qp_st_uid); + xmlAddChild(node, make_param("st_uid", tmpstr)); + snprintf(tmpstr, 32, "%d", qp->qp_rstat.qp_st_gid); + xmlAddChild(node, make_param("st_gid", tmpstr)); + snprintf(tmpstr, 32, "%ld", qp->qp_rstat.qp_st_size); + xmlAddChild(node, make_param("st_size", tmpstr)); +} + /* Must pass in a pointer, but not a malloc'ed pointer */ char * qptostr(struct qa_packet *qp, char **qpstr, int *qpsize) @@ -635,6 +686,25 @@ make_qp_sendfile(const char *path, int of_port, size_t count) return qp; } +struct qa_packet * +make_qp_rstat(const char *path, const struct stat *sb) +{ + struct qa_packet *qp; + qp = malloc(sizeof *qp); + assert(qp); + memset(qp, 0, sizeof *qp); + + qp->qp_type = QP_RSTAT; + qp->qp_rstat.qp_path = strdup(path); + if (sb) { + qp->qp_rstat.qp_st_mode = sb->st_mode; + qp->qp_rstat.qp_st_uid = sb->st_uid; + qp->qp_rstat.qp_st_gid = sb->st_gid; + qp->qp_rstat.qp_st_size = sb->st_size; + } + return qp; +} + /* * Packet deallocation functions */ @@ -675,6 +745,12 @@ free_qp_sendfile(struct qa_packet *qp) condfree(qp->qp_sendfile.qp_path); } +void +free_qp_rstat(struct qa_packet *qp) +{ + condfree(qp->qp_rstat.qp_path); +} + void qpfree(struct qa_packet *qp) @@ -755,6 +831,16 @@ dump_qp_sendfile(struct qa_packet *qp) } void +dump_qp_rstat(struct qa_packet *qp) +{ + printf("\tpath: %s\n", qp->qp_rstat.qp_path); + printf("\tst_mode: %o\n", qp->qp_rstat.qp_st_mode); + printf("\tst_uid: %d\n", qp->qp_rstat.qp_st_uid); + printf("\tst_gid: %d\n", qp->qp_rstat.qp_st_gid); + printf("\tst_size: %ld\n", qp->qp_rstat.qp_st_size); +} + +void dump_qp(struct qa_packet *qp) { printf("%s #%d\n", QP_NAME(qp->qp_type), qp->qp_seq); diff --git a/qarsh/qarsh_packet.h b/qarsh/qarsh_packet.h index b858631..c4316fd 100644 --- a/qarsh/qarsh_packet.h +++ b/qarsh/qarsh_packet.h @@ -2,6 +2,7 @@ # define _QARSH_PACKET_H 1 #include <sys/types.h> +#include <sys/stat.h> #define QARSH_MAX_PACKET_SIZE 32*1024 @@ -15,7 +16,8 @@ enum qa_packet_type { QP_SETUSER = 6, QP_KILL = 7, QP_RECVFILE = 8, - QP_SENDFILE = 9 + QP_SENDFILE = 9, + QP_RSTAT = 10 }; struct qp_hello_pkt { @@ -68,6 +70,14 @@ struct qp_sendfile_pkt { size_t qp_count; }; +struct qp_rstat_pkt { + char *qp_path; + mode_t qp_st_mode; + uid_t qp_st_uid; + gid_t qp_st_gid; + off_t qp_st_size; +}; + #define QP_VERSION 1 @@ -84,6 +94,7 @@ struct qa_packet { struct qp_kill_pkt kill; struct qp_recvfile_pkt recvfile; struct qp_sendfile_pkt sendfile; + struct qp_rstat_pkt rstat; } qp_u; }; @@ -96,6 +107,7 @@ struct qa_packet { #define qp_kill qp_u.kill #define qp_recvfile qp_u.recvfile #define qp_sendfile qp_u.sendfile +#define qp_rstat qp_u.rstat /* Prototypes */ char *qp_packet_type(enum qa_packet_type t); @@ -109,6 +121,7 @@ struct qa_packet *make_qp_setuser(char *user, char *group); struct qa_packet *make_qp_kill(int sig); struct qa_packet *make_qp_recvfile(const char *path, int if_port, size_t count, mode_t mode); struct qa_packet *make_qp_sendfile(const char *path, int of_port, size_t count); +struct qa_packet *make_qp_rstat(const char *path, const struct stat *sb); char *qptostr(struct qa_packet *qp, char **qpstr, int *qpsize); void qpfree(struct qa_packet *qp); void dump_qp(struct qa_packet *qp); diff --git a/qarsh/qarshd.c b/qarsh/qarshd.c index 1427089..ee9e556 100644 --- a/qarsh/qarshd.c +++ b/qarsh/qarshd.c @@ -146,6 +146,21 @@ recvfile(const char *path, int if_port, size_t count, mode_t mode) return count - nleft; } +struct qa_packet * +rstat(const char *path) +{ + struct stat sb; + struct qa_packet *rp; + + if (stat(path, &sb) < 0) { + rp = make_qp_returncode(-1, errno, strerror(errno)); + } else { + rp = make_qp_rstat(path, &sb); + } + + return rp; +} + void handle_packets(int infd) { @@ -252,6 +267,13 @@ handle_packets(int infd) qp->qp_sendfile.qp_of_port, qp->qp_sendfile.qp_count); break; + case QP_RSTAT: + syslog(LOG_INFO, "Got a QP_RSTAT with path = %s\n", + qp->qp_rstat.qp_path); + rp = rstat(qp->qp_rstat.qp_path); + send_packet(fileno(stdout), rp); + qpfree(rp); + break; default: syslog(LOG_WARNING, "Packet type %s unimplemented", |