// -*-c++-*- /* $Id: agent.h,v 1.20 2002/11/27 22:51:39 max Exp $ */ /* * * Copyright (C) 1999 David Mazieres (dm@uun.org) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * */ #include "arpc.h" #include "sfsmisc.h" #include "sfsauth_prot.h" #include "crypt.h" #include "sfsagent.h" #include "rxx.h" #include "qhash.h" #include "sfscrypt.h" class rxfilter { rrxx filter; rrxx exclude; public: rxfilter () {} rxfilter (const str &f, const str &e); bool check (const str &n); }; extern vec certprogs; extern vec certfilters; extern vec revokeprogs; extern vec revokefilters; extern qhash srpnames; extern bhash norevoke; void runprog (const sfsagent_cmd &av, str target, cbs cb); void sfslookup (str name, callback::ref cb, u_int certno = 0, str res = NULL); void revcheck (str name, callback::ref cb); struct authmgr; struct authmeth { list_entry link; str name; sfs_time expire; ref destroyed; sfs_hash authid_cache; authmgr *amgr; authmeth () : destroyed (New refcounted (false)), amgr(NULL) {} authmeth (authmgr *a) : destroyed (New refcounted (false)), amgr(a) {} virtual ~authmeth () { *destroyed = true; } virtual void authwarn (sfsagent_authinit_arg *aa); virtual void authinit (sfsagent_authinit_arg *aa, ptr res, cbv cb) = 0; virtual void authmore (sfsagent_authmore_arg *aa, ptr res, cbv cb) = 0; virtual bool kcmp (const sfspub &k) { return false; } virtual bool pcmp (const int p) { return false; } virtual str get_desc () const = 0 ; virtual void to_str (strbuf &b) { b << name; } bool register_sess (const sfs_authinfo &ai, const sfs_seqno &seqno, sfs_hash &hsh, bool storeit = true); }; struct key : public authmeth { ptr privkey; int vers; key () : privkey (NULL), vers (1) {} key (authmgr *a) : privkey (NULL), vers (1) {} void authinit (sfsagent_authinit_arg *aa, ptr res, cbv cb); void _authinit_v1 (sfsagent_authinit_arg *aa, ptr res, cbv cb); void _authinit_v2 (sfsagent_authinit_arg *aa, ptr res, cbv cb); void authmore (sfsagent_authmore_arg *aa, ptr res, cbv cb); bool kcmp (const sfspub &k) { if (!privkey) return false; return *privkey == k; } void to_str (strbuf &b) { strbuf k; if (privkey) privkey->export_pubkey (k); b << name << " (key: " << k << ")"; } str get_desc () const { return privkey->get_desc (); } void sigcb (ptr ar, ptr res, cbv cb, str err, ptr sig); }; struct extauth_server { virtual void eof () {} virtual ~extauth_server () {} }; struct extauth : public authmeth { int pid; ref x; ptr ac; bool eof; extauth_server *eas; extauth (ref xx, authmgr *a, extauth_server *eas); ~extauth () ; void authinit (sfsagent_authinit_arg *aa, ptr res, cbv cb); void authmore (sfsagent_authmore_arg *aa, ptr res, cbv cb); void eofcb (authmgr *a); bool pcmp (const int p) { return p == pid; } void eacb (ptr, cbv, ref, clnt_stat); void to_str (strbuf &b) { b << name << " (pid: " << pid << ")" ; } str get_desc () const { strbuf b; b << "pid: " << pid; return b;} }; struct authsess { authmeth *am; sfs_time expire; u_int id; tailq_entry link; ihash_entry hlink; authsess (authmeth *a, u_int i); void to_str (strbuf &b) { b.fmt ("ASID: 0x%x KEY: ", id); if (am) { am->to_str (b); } else { b << "(null)"; } } }; struct auth_sess_mgr { timecb_t *exp_tmo; authmgr *amgr; ihash sh; tailq sq; int num; auth_sess_mgr () : exp_tmo (NULL), num (0) {} void timeout (bool cb = false); void remove (authsess *as); void touch (authsess *as); void insert (authmeth *am, u_int id); bool register_sess (const sfs_authinfo &ai, const sfs_seqno &seqno, authmeth *m, sfs_hash &hsh, bool storeit = true); u_int compute_asid (const sfs_authinfo &, const sfs_seqno &, sfs_hash &); authmeth *retrieve (const sfs_authinfo &, const sfs_seqno &, sfs_hash &); bool exists (const authmeth *p); }; struct authmgr { timecb_t *exp_tmo; sfs_time exp_time; auth_sess_mgr asmgr; list authmeths; authmgr () : exp_tmo (NULL), exp_time (0) { asmgr.amgr = this; } void timeout (bool cb = false); authmeth *klookup (const sfspub &s); authmeth *plookup (const int p); authmeth *clookup (const str &c); bool exists (const authmeth *p); authmeth *lookup_by_index (const u_int n); void authinit (svccb *s); void authmore (svccb *s); void authdone_cb (svccb *s, ptr res); void remove (authmeth *am) { authmeths.remove (am); } void insert (authmeth *am) { authmeths.insert_head (am) ; } void remove_all (); void fill_keylist (sfs_keylist *kl) ; }; struct sfsagent : public extauth_server { str name; ref x; ptr ac; ptr as; ptr cs; list_entry link; sfsagent (int fd); sfsagent (ref x); ~sfsagent (); void agentdisp (svccb *sbp); void ctldisp (svccb *sbp); void dispatch (svccb *sbp); void keyinitcb (svccb *sbp, key *nk, str err); void setname (str name); void eof () { delete this; } }; extern authmgr gmgr; extern list agents; void agentmsg (u_int32_t proc, const void *arg = NULL); /* agentrex.C */ typedef callback >::ref cb_rex; void rex_connect (str path, str frompath, bool forwardagent, cb_rex::ptr cb); void list_rexsess (svccb *sbp); bool kill_rexsess (str schost);