00001
00002
00003
00004
00005
00006
00007 #include "uniconfpamconn.h"
00008 #include "unisecuregen.h"
00009 #include "wvpam.h"
00010
00011
00012 unsigned int WvHash(const UniConfGen *u)
00013 {
00014 return WvHash((int) u);
00015 }
00016
00017
00018
00019
00020
00021 SecureGenDict UniConfPamConn::securegens(7);
00022
00023
00024 UniConfPamConn::UniConfPamConn(WvStream *_s, const UniConf &_root) :
00025 UniConfDaemonConn(new WvPamStream(_s, "uniconfdaemon", WvString::null,
00026 "FAIL { Not authorized }"), _root)
00027 {
00028 }
00029
00030
00031 void UniConfPamConn::addcallback()
00032 {
00033 root.add_callback(this, UniConfCallback(this,
00034 &UniConfPamConn::deltacallback), true);
00035 }
00036
00037
00038 void UniConfPamConn::delcallback()
00039 {
00040 root.del_callback(this, true);
00041 }
00042
00043
00044 void UniConfPamConn::do_get(const UniConfKey &key)
00045 {
00046 updatecred(root[key]);
00047 UniConfDaemonConn::do_get(key);
00048 }
00049
00050
00051 void UniConfPamConn::do_set(const UniConfKey &key, WvStringParm value)
00052 {
00053 updatecred(root[key]);
00054 UniConfDaemonConn::do_set(key, value);
00055 }
00056
00057
00058 void UniConfPamConn::do_remove(const UniConfKey &key)
00059 {
00060 updatecred(root[key]);
00061 UniConfDaemonConn::do_remove(key);
00062 }
00063
00064
00065 void UniConfPamConn::do_subtree(const UniConfKey &key)
00066 {
00067 updatecred(root[key]);
00068 UniConfDaemonConn::do_subtree(key);
00069 }
00070
00071
00072 void UniConfPamConn::do_haschildren(const UniConfKey &key)
00073 {
00074 updatecred(root[key]);
00075 UniConfDaemonConn::do_haschildren(key);
00076 }
00077
00078
00079 void UniConfPamConn::deltacallback(const UniConf &cfg, const UniConfKey &key)
00080 {
00081 updatecred(cfg[key]);
00082 UniConfDaemonConn::deltacallback(cfg, key);
00083
00084 // FIXME: looks like if there's no permission to read, pamconn will tell
00085 // the client that it's been deleted instead of just staying silent.
00086 }
00087
00088
00089 void UniConfPamConn::updatecred(const UniConf &key)
00090 {
00091 // get the user and groups from PAM
00092 WvPamStream *pam = static_cast<WvPamStream *>(cloned);
00093 WvString user = pam->getuser();
00094 WvStringList groups;
00095 pam->getgroups(groups);
00096
00097 // if this isn't a UniSecureGen, don't need to authenticate
00098 SecureGen *sec = securegens[key.whichmount(NULL)];
00099 if (sec && sec->data) sec->data->setcredentials(user, groups);
00100 }