00001 #include <usercomng.h>
00002 #include <subsys.h>
00003 #include <confdb.h>
00004 #include "ldapconf_defs.h"
00005 #include "fields.h"
00006
00007 static HELP_FILE help_config ("ldapconf","formclient");
00008
00009 class USERINFO_COMNG: public USERACCT_COMNG{
00010 LDAPOBJECT ldap;
00011 CONFDB ldapdb;
00012 FIELD_DEFS userconf_ldapform;
00013 char *comng_enabled;
00014 const char *domain_profile;
00015
00016
00017 public:
00018 USERINFO_COMNG (DICTIONARY&_dict);
00019 int deluser (PRIVILEGE *);
00020 int save (PRIVILEGE *priv);
00021 void setupdia (DIALOG&dia);
00022 int validate (DIALOG&, int &nof);
00023 ~USERINFO_COMNG (void);
00024
00025 };
00026
00027 PUBLIC USERINFO_COMNG::USERINFO_COMNG(
00028 DICTIONARY &_dict)
00029 : USERACCT_COMNG (_dict)
00030 {
00031
00032 const char *domain = dict.get_str("domain");
00033 char fpath[PATH_MAX];
00034 sprintf(fpath,"%s/%s",PROFILE_DIR,domain);
00035
00036 if (!strcmp(domain,"/")) {
00037 domain_profile = "userinfo";
00038 D(debugf(4,"ldap_comng: main domain: %s\n",domain));
00039 }
00040 else if (fopen(fpath,"r")){
00041 domain_profile = domain;
00042 D(debugf(4,"ldap_comng: virtual domain: %s\n",domain));
00043 }
00044 else {
00045 comng_enabled = 0;
00046 return;
00047 }
00048
00049 ldap.load_profile(domain_profile);
00050 if (!ldap.c_profile->getvalnum("profile","userconf_comng",0)) {
00051 comng_enabled = 0;
00052 return;
00053 }
00054
00055 userconf_ldapform.c_form = ldap.form;
00056 userconf_ldapform.read();
00057 if (!dict.get_bool ("is_new")){
00058 ldap.filter.setfromf("uid=%s",dict.get_str("name"));
00059 ldap.search();
00060 ldap.export_confdb(&ldapdb);
00061 userconf_ldapform.loadval (&ldapdb,dict.get_str("name"));
00062 }
00063 }
00064
00065 PUBLIC USERINFO_COMNG::~USERINFO_COMNG()
00066 {
00067 }
00068
00069 PUBLIC void USERINFO_COMNG::setupdia (
00070 DIALOG &dia)
00071 {
00072 if (comng_enabled) {
00073 dia.newf_title (MSG_U(T_EXTRA,"LDAP"),1
00074 ,"",MSG_R(T_EXTRA));
00075 userconf_ldapform.setupdia(dia);
00076 }
00077 }
00078
00079 PUBLIC int USERINFO_COMNG::save(
00080 PRIVILEGE *priv)
00081 {
00082 if (!comng_enabled) return 0;
00083 const char *user;
00084 user = dict.get_str("name");
00085 char buf[256];
00086 char is_new;
00087 int n;
00088
00089 sprintf(buf,"uid=%s",user);
00090 ldap.filter.setfrom(buf);
00091 n = ldap.search();
00092 if ( n ) { is_new = 0; }
00093 else { is_new = 1; }
00094
00095
00096 sprintf(buf,"uid=%s,%s,%s",user,ldap.dn_prefix.get(),ldap.base.get());
00097 ldap.dn.setfrom(buf);
00098
00099
00100 if (is_new){
00101 ldap.at_set("uid",user);
00102 ldap.at_set("cn",user);
00103 ldap.oc_add("top");
00104 ldap.oc_add("account");
00105 ldap.oc_add("posixAccount");
00106 ldap.add();
00107 }
00108
00109
00110 userconf_ldapform.saveval (&ldapdb,user);
00111 ldap.import_confdb(&ldapdb);
00112 return ldap.modify();
00113 }
00114
00115 PUBLIC int USERINFO_COMNG::validate(
00116 DIALOG &,
00117 int &nof)
00118 {
00119 int ret = 0;
00120 if (!comng_enabled) return 0;
00121 return ret;
00122 }
00123
00124 PUBLIC int USERINFO_COMNG::deluser (
00125 PRIVILEGE *)
00126 {
00127 int ret = 0;
00128
00129 if (!comng_enabled) return 0;
00130
00131 if (!dict.get_bool("is_new")){
00132 const char *user;
00133 user = dict.get_str("name");
00134 char buf[256];
00135 sprintf(buf,"uid=%s,%s,%s",user,ldap.dn_prefix.get(),ldap.base.get());
00136 ldap.dn.setfrom(buf);
00137 ret = ldap.del();
00138 }
00139 return ret;
00140 }
00141
00142 USERACCT_COMNG *ldapconf_newcomng(
00143 const char *key,
00144 DICTIONARY &dict)
00145 {
00146 USERACCT_COMNG *ret = NULL;
00147
00148 if (strcmp(key,"user")==0 && mode_ldap_userinfo){
00149 ret = new USERINFO_COMNG (dict);
00150 }
00151 return ret;
00152 }
00153
00154 static REGISTER_USERACCT_COMNG xxx (ldapconf_newcomng);
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171