modify.c
来自「开放源码的ldap系统」· C语言 代码 · 共 567 行 · 第 1/2 页
C
567 行
goto modrdn_return; } Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): new entry dn is '%s'\n",new_dn,0,0); res=backsql_dn2id(bi,&pe_id,dbh,(char*)p_dn); if (res==NULL) { Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): could not lookup old parent entry id\n",0,0,0); send_ldap_result(conn,op,LDAP_NO_SUCH_OBJECT,"",NULL,NULL,NULL); goto modrdn_return; } Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): old parent entry id is %d\n",pe_id.id,0,0); res=backsql_dn2id(bi,&new_pid,dbh,(char*)new_pdn); if (res==NULL) { Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): could not lookup new parent entry id\n",0,0,0); send_ldap_result(conn,op,LDAP_NO_SUCH_OBJECT,"",NULL,NULL,NULL); goto modrdn_return; } Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): new parent entry id is %d\n",new_pid.id,0,0); Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): executing delentry_query\n",0,0,0); SQLBindParameter(sth,1,SQL_PARAM_INPUT,SQL_C_ULONG,SQL_INTEGER,0,0,&e_id.id,0,0); rc=SQLExecDirect(sth,bi->delentry_query,SQL_NTS); if (rc != SQL_SUCCESS) { Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): failed to delete record from ldap_entries\n",0,0,0); backsql_PrintErrors(bi->db_env,dbh,sth,rc); send_ldap_result(conn,op,LDAP_OTHER,"","SQL-backend error",NULL,NULL); goto modrdn_return; } SQLFreeStmt(sth,SQL_RESET_PARAMS); Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): executing insentry_query\n",0,0,0); backsql_BindParamStr(sth,1,new_dn,BACKSQL_MAX_DN_LEN); SQLBindParameter(sth,2,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,0,0,&e_id.oc_id,0,0); SQLBindParameter(sth,3,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,0,0,&new_pid.id,0,0); SQLBindParameter(sth,4,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,0,0,&e_id.keyval,0,0); rc=SQLExecDirect(sth,bi->insentry_query,SQL_NTS); if (rc != SQL_SUCCESS) { Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): could not insert ldap_entries record\n",0,0,0); backsql_PrintErrors(bi->db_env,dbh,sth,rc); send_ldap_result(conn,op,LDAP_OTHER,"","SQL-backend error",NULL,NULL); goto modrdn_return; } //should process deleteoldrdn here... send_ldap_result(conn,op,LDAP_SUCCESS,"",NULL,NULL,NULL);modrdn_return: SQLFreeStmt(sth,SQL_DROP); if (p_dn) ch_free(p_dn); if (newSuperior && new_pdn) ch_free(new_pdn); if (new_dn) ch_free(new_dn); Debug(LDAP_DEBUG_TRACE,"<==backsql_modrdn()\n",0,0,0); return 0;}int backsql_add(BackendDB *be,Connection *conn,Operation *op,Entry *e){ backsql_info *bi=(backsql_info*)be->be_private; SQLHDBC dbh; SQLHSTMT sth; unsigned long new_keyval; long i; RETCODE rc; backsql_oc_map_rec *oc=NULL; backsql_at_map_rec *at_rec=NULL; backsql_entryID parent_id,*res; Attribute *at; struct berval *at_val; char *pdn; int pno,po;//first parameter no, parameter order int prc; //procedure return code Debug(LDAP_DEBUG_TRACE,"==>backsql_add(): adding entry '%s'\n",e->e_dn,0,0); if (dn_validate(e->e_dn)==NULL) { Debug(LDAP_DEBUG_TRACE,"==>backsql_add(): invalid dn '%s' -- aborting\n",e->e_dn,0,0); } for(at=e->e_attrs;at!=NULL;at=at->a_next) { //Debug(LDAP_DEBUG_TRACE,"backsql_add(): scanning entry -- %s\n",at->a_type,0,0); if (!strcasecmp(at->a_desc->ad_cname->bv_val,"objectclass")) { oc=backsql_oc_with_name(bi,at->a_vals[0]->bv_val); break; } } if (oc==NULL) { Debug(LDAP_DEBUG_TRACE,"backsql_add(): cannot determine objectclass of entry -- aborting\n",0,0,0); send_ldap_result(conn,op,LDAP_OTHER,"","SQL-backend error",NULL,NULL); return 1; } if (oc->create_proc == NULL) { Debug(LDAP_DEBUG_TRACE,"backsql_add(): create procedure is not defined for this objectclass - aborting\n",0,0,0); send_ldap_result(conn,op,LDAP_OTHER,"","SQL-backend error",NULL,NULL); return 1; } dbh=backsql_get_db_conn(be,conn); if (!dbh) { Debug(LDAP_DEBUG_TRACE,"backsql_add(): could not get connection handle - exiting\n",0,0,0); send_ldap_result(conn,op,LDAP_OTHER,"","SQL-backend error",NULL,NULL); return 1; } SQLAllocStmt(dbh, &sth); SQLBindParameter(sth,1,SQL_PARAM_OUTPUT,SQL_C_ULONG,SQL_INTEGER,0,0,&new_keyval,0,0); Debug(LDAP_DEBUG_TRACE,"backsql_add(): executing '%s'\n",oc->create_proc,0,0); rc=SQLExecDirect(sth,oc->create_proc,SQL_NTS); if (rc != SQL_SUCCESS) { Debug(LDAP_DEBUG_TRACE,"backsql_add(): create_proc execution failed\n",0,0,0); backsql_PrintErrors(bi->db_env,dbh,sth,rc); SQLFreeStmt(sth,SQL_DROP); send_ldap_result(conn,op,LDAP_OTHER,"","SQL-backend error",NULL,NULL); return 1; } SQLFreeStmt(sth,SQL_RESET_PARAMS); Debug(LDAP_DEBUG_TRACE,"backsql_add(): create_proc returned keyval=%d\n",new_keyval,0,0); for(at=e->e_attrs;at!=NULL;at=at->a_next) { at_rec=backsql_at_with_name(oc,at->a_desc->ad_cname->bv_val); if (at_rec==NULL) { Debug(LDAP_DEBUG_TRACE,"backsql_add(): attribute provided is not registered in this objectclass ('%s')\n",at->a_desc->ad_cname->bv_val,0,0); continue; } if (at_rec->add_proc==NULL) { Debug(LDAP_DEBUG_TRACE,"backsql_add(): add procedure is not defined for this attribute ('%s')\n",at->a_desc->ad_cname->bv_val,0,0); continue; } for(i=0,at_val=at->a_vals[0];at_val!=NULL;i++,at_val=at->a_vals[i]) { if (at_rec->expect_return & BACKSQL_ADD) { pno=1; SQLBindParameter(sth,1,SQL_PARAM_OUTPUT,SQL_C_ULONG,SQL_INTEGER,0,0,&prc,0,0); } else pno=0; po=(at_rec->param_order & BACKSQL_ADD)>0; SQLBindParameter(sth,(SQLUSMALLINT)(pno+1+po),SQL_PARAM_INPUT,SQL_C_ULONG,SQL_INTEGER,0,0,&new_keyval,0,0); //check for syntax needed here - maybe need binary bind? SQLBindParameter(sth,(SQLUSMALLINT)(pno+2-po),SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,0,0,at_val->bv_val,at_val->bv_len,0); Debug(LDAP_DEBUG_TRACE,"backsql_add(): executing '%s'\n",at_rec->add_proc,0,0); rc=SQLExecDirect(sth,at_rec->add_proc,SQL_NTS); if (rc!=SQL_SUCCESS) { Debug(LDAP_DEBUG_TRACE,"backsql_add(): add_proc execution failed\n",0,0,0); backsql_PrintErrors(bi->db_env,dbh,sth,rc); } } } SQLFreeStmt(sth,SQL_RESET_PARAMS); pdn=dn_parent(be,e->e_dn); res=backsql_dn2id(bi,&parent_id,dbh,pdn); if (res==NULL) { Debug(LDAP_DEBUG_TRACE,"backsql_add(): could not lookup parent entry for new record ('%s')\n", pdn,0,0); send_ldap_result(conn,op,LDAP_OTHER,"","SQL-backend error",NULL,NULL); return 1; } free(pdn); backsql_BindParamStr(sth,1,e->e_dn,BACKSQL_MAX_DN_LEN); SQLBindParameter(sth,2,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,0,0,&oc->id,0,0); SQLBindParameter(sth,3,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,0,0,&parent_id.id,0,0); SQLBindParameter(sth,4,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,0,0,&new_keyval,0,0); rc=SQLExecDirect(sth,bi->insentry_query,SQL_NTS); if (rc != SQL_SUCCESS) { Debug(LDAP_DEBUG_TRACE,"backsql_add(): could not insert ldap_entries record\n",0,0,0); backsql_PrintErrors(bi->db_env,dbh,sth,rc); //execute delete_proc to delete data added !!! SQLFreeStmt(sth,SQL_DROP); send_ldap_result(conn,op,LDAP_OTHER,"","SQL-backend error",NULL,NULL); return 1; } SQLFreeStmt(sth,SQL_DROP); send_ldap_result(conn,op,LDAP_SUCCESS,"",NULL,NULL,NULL); return 0;}int backsql_delete(BackendDB *be,Connection *conn,Operation *op, const char *dn,const char *ndn){ backsql_info *bi=(backsql_info*)be->be_private; SQLHDBC dbh; SQLHSTMT sth; RETCODE rc; backsql_oc_map_rec *oc=NULL; backsql_entryID e_id,*res; int pno;//first parameter no, parameter order Debug(LDAP_DEBUG_TRACE,"==>backsql_delete(): deleting entry '%s'\n",ndn,0,0); dbh=backsql_get_db_conn(be,conn); if (!dbh) { Debug(LDAP_DEBUG_TRACE,"backsql_delete(): could not get connection handle - exiting\n",0,0,0); send_ldap_result(conn,op,LDAP_OTHER,"","SQL-backend error",NULL,NULL); return 1; } res=backsql_dn2id(bi,&e_id,dbh,(char*)ndn); if (res==NULL) { Debug(LDAP_DEBUG_TRACE,"backsql_delete(): could not lookup entry id\n",0,0,0); send_ldap_result(conn,op,LDAP_NO_SUCH_OBJECT,"",NULL,NULL,NULL); return 1; } oc=backsql_oc_with_id(bi,e_id.oc_id); if (oc==NULL) { Debug(LDAP_DEBUG_TRACE,"backsql_delete(): cannot determine objectclass of entry -- aborting\n",0,0,0); send_ldap_result(conn,op,LDAP_OTHER,"","SQL-backend error",NULL,NULL); return 1; } if (oc->delete_proc == NULL) { Debug(LDAP_DEBUG_TRACE,"backsql_delete(): delete procedure is not defined for this objectclass - aborting\n",0,0,0); send_ldap_result(conn,op,LDAP_OTHER,"","SQL-backend error",NULL,NULL); return 1; } SQLAllocStmt(dbh, &sth); if (oc->expect_return) { pno=1; SQLBindParameter(sth,1,SQL_PARAM_OUTPUT,SQL_C_ULONG,SQL_INTEGER,0,0,&rc,0,0); } else pno=0; SQLBindParameter(sth,(SQLUSMALLINT)(pno+1),SQL_PARAM_INPUT,SQL_C_ULONG,SQL_INTEGER,0,0,&e_id.keyval,0,0); //SQLBindParameter(sth,2,SQL_PARAM_OUTPUT,SQL_C_SLONG,SQL_INTEGER,0,0,&retcode,0,0); Debug(LDAP_DEBUG_TRACE,"backsql_delete(): executing '%s'\n",oc->delete_proc,0,0); rc=SQLExecDirect(sth,oc->delete_proc,SQL_NTS); if (rc != SQL_SUCCESS) { Debug(LDAP_DEBUG_TRACE,"backsql_delete(): delete_proc execution failed\n",0,0,0); backsql_PrintErrors(bi->db_env,dbh,sth,rc); SQLFreeStmt(sth,SQL_DROP); send_ldap_result(conn,op,LDAP_OTHER,"","SQL-backend error",NULL,NULL); return 1; } SQLFreeStmt(sth,SQL_RESET_PARAMS); SQLBindParameter(sth,1,SQL_PARAM_INPUT,SQL_C_ULONG,SQL_INTEGER,0,0,&e_id.id,0,0); rc=SQLExecDirect(sth,bi->delentry_query,SQL_NTS); if (rc != SQL_SUCCESS) { Debug(LDAP_DEBUG_TRACE,"backsql_delete(): failed to delete record from ldap_entries\n",0,0,0); backsql_PrintErrors(bi->db_env,dbh,sth,rc); SQLFreeStmt(sth,SQL_DROP); send_ldap_result(conn,op,LDAP_OTHER,"","SQL-backend error",NULL,NULL); return 1; } SQLFreeStmt(sth,SQL_DROP); send_ldap_result(conn,op,LDAP_SUCCESS,"",NULL,NULL,NULL); Debug(LDAP_DEBUG_TRACE,"<==backsql_delete()\n",0,0,0); return 0;}#endif /* SLAPD_SQL */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?