modify.c

来自「ftam等标准协议服务器和客户端的源代码。」· C语言 代码 · 共 855 行 · 第 1/2 页

C
855
字号
#include "quipu/util.h"#include "quipu/common.h"#include "quipu/entry.h"#include "quipu/modify.h"#include "quipu/name.h"#include <sys/types.h>#include <ctype.h>#include "sequence.h"#include "dir_entry.h"#include "defs.h"#include "util.h"#define AS_SYNTAX(attrSeq) attrSeq->attr_type->oa_syntax#define AS_STROID(attrSeq) attrSeq->attr_type->oa_ot.ot_stroidextern bool photo_on;char *modify_error();static Attr_Sequence as_sort();static bool is_map_required();static void char_map(), char_unmap();static void my_as_print(), my_as_comp_print();void rfc2greybook();extern mailtype mailformat;#ifndef NO_STATSextern LLog    *log_stat;#endifstruct entrymod * ems_append (a,b)     struct entrymod *a;     struct entrymod *b;{  struct entrymod *ptr;  if ((ptr = a) == NULLMOD)    return b;    for ( ; ptr->em_next != NULLMOD; ptr = ptr->em_next)    ;    ptr->em_next = b;  return a;}dsErrorStruct modify_entry(mods)     dirEntry mods;{  struct ds_modifyentry_arg mod_arg;  dsErrorStruct mod_error;  struct DSError error;  struct entrymod *curr_mod = 0, *entrymods = 0;  AttributeType attr_type = 0;  AttributeValue attr_val = 0;  AV_Sequence attrVal_seq = 0;  register modVals curr_val;  dirAttrs attrs;  char err_buf[STRINGLEN], attr_val_buf[STRINGLEN];  short attr_removed;    if (get_default_service(&mod_arg.mea_common) != 0) {    mod_error.error = serviceerror;    mod_error.err_mess = strdup("Directory Service Error!\n");  }  mod_arg.mea_common.ca_servicecontrol.svc_options =     mod_arg.mea_common.ca_servicecontrol.svc_options | SVC_OPT_PREFERCHAIN;  mod_arg.mea_object = str2dn(mods->entry_name);  for (attrs = mods->attrs; attrs; attrs = attrs->next) {    if (attrs->mod_flag) {      if (mailformat == greybook && !lexequ(attrs->attr_name, "mailbox"))	attr_type = str2AttrT("rfc822Mailbox");      else	attr_type = str2AttrT(attrs->attr_name);      for (curr_val = attrs->val_seq; 	   curr_val && curr_val->mod_flag;	   curr_val = curr_val->next)	;      if (!curr_val) {	if (attrs->in_flag) {	  curr_mod = em_alloc();	  curr_mod->em_next = NULLMOD;	  curr_mod->em_type = EM_REMOVEATTRIBUTE;	  curr_mod->em_what = NULLATTR;	  	  curr_mod->em_what = as_comp_new(attr_type, NULLAV, NULLACL_INFO);	  entrymods = ems_append(entrymods, curr_mod);	}	curr_mod = em_alloc();	curr_mod->em_next = NULLMOD;	curr_mod->em_type = EM_ADDATTRIBUTE;	curr_mod->em_what = NULLATTR;		for (curr_val = attrs->val_seq; curr_val; curr_val = curr_val->next) {	  char_unmap(attr_val_buf, curr_val->new_value, attr_type);	  if (attr_val_buf[0] != '\0') {	    if (mailformat == greybook && !lexequ(attrs->attr_name, "mailbox"))		rfc2greybook(attr_val_buf);	    attr_val = str2AttrV(attr_val_buf,				 attr_type->oa_syntax);	    if (attr_val) {	      if (attrVal_seq) 		attrVal_seq = avs_merge(attrVal_seq, avs_comp_new(attr_val));	      else 		attrVal_seq = avs_comp_new(attr_val);	    } else {	      if (entrymods) ems_free(entrymods);	      AttrT_free(attr_type);	      mod_error.error = attributerror;	      (void) sprintf(err_buf,		 "Attribute Error!\nInvalid syntax for value '%s' type '%s'.", 		 curr_val->new_value, attrs->attr_name);	      mod_error.err_mess = strdup(err_buf);	      return mod_error;	    }	  }	}	if (attrVal_seq) {	  curr_mod->em_what = as_comp_new(AttrT_cpy(attr_type),					  attrVal_seq, 					  NULLACL_INFO);	  entrymods = ems_append(entrymods, curr_mod);	  attrVal_seq = 0;	  curr_mod = 0;	  AttrT_free(attr_type);	}      } else {	if (attrs->in_flag) {	  for (curr_val = attrs->val_seq;	       curr_val;	       curr_val = curr_val->next) {	    char_unmap(attr_val_buf, curr_val->value, attr_type);	    if (curr_val->mod_flag && attr_val_buf[0] != '\0') {	      if (mailformat == greybook 		  && !lexequ(attrs->attr_name, "mailbox"))		rfc2greybook(attr_val_buf);	      attrVal_seq = avs_comp_new(str2AttrV(attr_val_buf,						   attr_type->oa_syntax));	      curr_mod = em_alloc();	      curr_mod->em_next = NULLMOD;	      curr_mod->em_type = EM_REMOVEVALUES;	      curr_mod->em_what = as_comp_new(AttrT_cpy(attr_type),					      attrVal_seq,					      NULLACL_INFO);	      entrymods = ems_append(entrymods, curr_mod);	    }	  }	  	  for (curr_val = attrs->val_seq;	       curr_val;	       curr_val = curr_val->next) {	    char_unmap(attr_val_buf, curr_val->new_value, attr_type);	    if (curr_val->mod_flag && attr_val_buf[0] != '\0') {	      if (mailformat == greybook 		  && !lexequ(attrs->attr_name, "mailbox"))		rfc2greybook(attr_val_buf);	      attr_val = str2AttrV(attr_val_buf, 				   attr_type->oa_syntax);	      if (attr_val) {		if (attrVal_seq) 		  attrVal_seq = avs_merge(attrVal_seq, 					  avs_comp_new(attr_val));		else 		  attrVal_seq = avs_comp_new(attr_val);	      } else {		if (entrymods) ems_free(entrymods);		AttrT_free(attr_type);		mod_error.error = attributerror;		(void) sprintf(err_buf,		     "Attribute Error!\nInvalid syntax for value %s type %s.", 		      curr_val->new_value, attrs->attr_name);		mod_error.err_mess = strdup(err_buf);		return mod_error;	      }	      curr_mod = em_alloc();	      curr_mod->em_next = NULLMOD;	      curr_mod->em_type = EM_ADDVALUES;	      curr_mod->em_what = as_comp_new(AttrT_cpy(attr_type),					      attrVal_seq,					      NULLACL_INFO);	      entrymods = ems_append(entrymods, curr_mod);	    }	  }	  if (attrVal_seq) {	    attrVal_seq = 0;	    curr_mod = 0;	    AttrT_free(attr_type);	  }	} else {	  curr_mod = em_alloc();	  curr_mod->em_next = NULLMOD;	  curr_mod->em_type = EM_ADDATTRIBUTE;	  	  for (curr_val = attrs->val_seq; 	       curr_val; 	       curr_val = curr_val->next) {	    char_unmap(attr_val_buf, curr_val->new_value, attr_type);	    if (attr_val_buf[0] != '\0') {	      if (mailformat == greybook		  && !lexequ(attrs->attr_name, "mailbox"))		rfc2greybook(attr_val_buf);	      attr_val = str2AttrV(attr_val_buf, 				   attr_type->oa_syntax);	      if (attr_val) {		if (attrVal_seq) 		  attrVal_seq = avs_merge(attrVal_seq, 					  avs_comp_new(attr_val));		else 		  attrVal_seq = avs_comp_new(attr_val);	      } else {		if (entrymods) ems_free(entrymods);		AttrT_free(attr_type);		mod_error.error = attributerror;		(void) sprintf(err_buf,		     "Attribute Error!\nInvalid syntax for value %s type %s.", 		      curr_val->new_value, attrs->attr_name);		mod_error.err_mess = strdup(err_buf);		return mod_error;	      }	    }	  }	  if (attrVal_seq) {	    curr_mod->em_what = as_comp_new(AttrT_cpy(attr_type),					    attrVal_seq, 					    NULLACL_INFO);	    entrymods = ems_append(entrymods, curr_mod);	    attrVal_seq = 0;	    curr_mod = 0;	    AttrT_free(attr_type);	  }	}      }    }  }  if (entrymods) {    mod_arg.mea_changes = entrymods;    if (ds_modifyentry(&mod_arg, &error) != DS_OK) {      mod_error.err_mess = modify_error(&error);      switch (error.dse_type) {      case DSE_LOCALERROR:	mod_error.error = duaerror;	if (!mod_error.err_mess) {	  mod_error.err_mess = 	    strdup("Internal Error, No modifications made. Sorry!");	}	break;	      case DSE_REMOTEERROR:	mod_error.error = localdsaerror;	break;	      case DSE_ATTRIBUTEERROR:	mod_error.error = attributerror;	if (!mod_error.err_mess) {	  mod_error.err_mess = 	    strdup("Attribute Error! No Modifications made.");	}	break;      case DSE_REFERRAL:      case DSE_DSAREFERRAL:	mod_error.error = remotedsaerror;	if (!mod_error.err_mess) {	  mod_error.err_mess = 	    strdup("Referral Error! No Modifications made.");	}	break;      case DSE_SECURITYERROR:	mod_error.error = security;	if (!mod_error.err_mess) {	  mod_error.err_mess = strdup("Security Error! Check access rights.");	}	break;      case DSE_NAMEERROR:	mod_error.error = namerror;	if (!mod_error.err_mess) {	  switch (error.dse_un.dse_un_name.DSE_na_problem) {	  case DSE_NA_NOSUCHOBJECT:	    mod_error.err_mess = 	      strdup("Name Error! No such object.");	    break;	  case DSE_NA_ALIASPROBLEM:	  case DSE_NA_ALIASDEREFERENCE:	    mod_error.err_mess = strdup("Error! Alias problem.");	    break;	  case DSE_NA_INVALIDATTRIBUTESYNTAX:	    mod_error.err_mess = 	      strdup("Name Error! Invalid attribute syntax.");	    break;	  }	}	break;	      case DSE_SERVICEERROR:	mod_error.error = serviceerror;	break;	      case DSE_UPDATEERROR:	mod_error.error = updaterror;	break;	      default:	mod_error.error = localdsaerror;	break;      }      ds_error_free(&error);      dn_free(mod_arg.mea_object);      return mod_error;    } else {      ems_free(entrymods);      delete_cache(mod_arg.mea_object);    }  } else {    mod_error.error = updaterror;    mod_error.err_mess = strdup("No modifications to make!");    dn_free(mod_arg.mea_object);    return mod_error;  }  for (attrs = mods->attrs; attrs; attrs = attrs->next) {    if (attrs->mod_flag == TRUE && attrs->in_flag == FALSE)       attrs->in_flag = TRUE;    attrs->mod_flag = FALSE;    attr_removed = TRUE;    for (curr_val = attrs->val_seq; curr_val; curr_val = curr_val->next) {      if (curr_val->new_value != NULLCP) {	if (curr_val->value != NULLCP) free(curr_val->value);	curr_val->value = curr_val->new_value;	curr_val->new_value = NULLCP;	attr_removed = FALSE;      }      if (curr_val->value && *curr_val->value != '\0' && !curr_val->mod_flag)	attr_removed = FALSE;      curr_val->mod_flag = FALSE;    }    if (attr_removed) attrs->in_flag = FALSE;  }  mod_error.error = Okay;  dn_free(mod_arg.mea_object);  return mod_error;}	    void make_template(entry_name, attrs)     char *entry_name;     dirAttrs *attrs;{  char *buffer;  PS ps;  extern oid_table_attr *at_objectclass;  struct ds_read_arg read_arg;  struct ds_read_result   result;  struct DSError          error;  Entry read_entry;  Attr_Sequence   as, read_attrs;  Attr_Sequence   nas = 0, tas = 0, templ_as, make_template_as();  *attrs = 0;  if (*entry_name == '\0') return;  if ((ps = ps_alloc(str_open)) == NULLPS) return;  if (str_setup(ps, NULLCP, 0, 0) == NOTOK) return;  if (get_default_service (&read_arg.rda_common) != 0) return;  read_arg.rda_common.ca_servicecontrol.svc_options =     read_arg.rda_common.ca_servicecontrol.svc_options | SVC_OPT_PREFERCHAIN;  read_arg.rda_eis.eis_allattributes = TRUE;  read_arg.rda_eis.eis_infotypes = EIS_ATTRIBUTESANDVALUES;    read_arg.rda_object = str2dn(entry_name);  photo_on = FALSE;    if ((read_entry = local_find_entry(read_arg.rda_object, FALSE)) != NULLENTRY      && read_entry->e_data != E_TYPE_CONSTRUCTOR) {    read_attrs = read_entry->e_attributes;  } else {    if (ds_read(&read_arg, &error, &result) != DS_OK) {      photo_on = TRUE;      return;    }    if (result.rdr_entry.ent_attr == NULLATTR) {      photo_on = TRUE;      return;    }    read_attrs = result.rdr_entry.ent_attr;  }  for (as = read_attrs; as != NULLATTR; as = as->attr_link)    if (as->attr_type == at_objectclass)      break;  templ_as = make_template_as(as->attr_value);    for (as = read_attrs; as != NULLATTR; as = as->attr_link)    if (!(AS_SYNTAX(as) == str2syntax("schema") ||	  AS_SYNTAX(as) == str2syntax("objectclass") ||	  AS_SYNTAX(as) == str2syntax("acl") ||	  AS_SYNTAX(as) == str2syntax("edbinfo") ||	  AS_SYNTAX(as) == str2syntax("octetstring") ||

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?