|
|
|
Java - อยากทราบเกี่ยวกับ Program จับ Packet บนเครื่อง Oracle หน่อยครับ |
|
|
|
|
|
|
|
รบกวนหน่อยครับมีใครพอทราบไหมว่าถ้าเราจะจับ Packet Data ที่ส่งจาก Oracle ไป Window นี่ใช้โปรแกรมอะไรได้บ้างหรือว่าเช็ค Log อะไรได้บ้าง..ว่าส่งถึงหรือไม่ถึง AD
พอดีผมทำเกี่ยวกับ Protocal LDAP มีการทำ Syn Password ถ้าจากเครื่อง Window มา Sun ก้อใช้ PCNS จับ ส่วนเครื่องฝั่ง Sun ก้อเขียน Plug-in เป็นภาษา C แล้ว Buid เป็น .SO แล้วแต่ ฝั่ง Sun เปลี่ยน Password เสร็จมันไม่โยนไปฝั่ง AD ใช้ wireshark จับก้อดูได้ไม่ละเอียดมีใครพอแนะนำได้มั่งครับ หรือ ภาษา C ผมต้องเขียนอะไรเพิ่มเติ่ม แนะนำหน่อยคับ
Code
int DPSS_set_log(Slapi_PBlock * pb)
{
Slapi_DN * confdn = NULL; /* DN for configuration entry */
Slapi_Entry * config = NULL; /* Configuration entry */
char * errlog = NULL; /* Errors log file name */
char * logdir = NULL; /* Errors log directory name */
FILE * fp; /* Use to open changelog file */
int rc = 0; /* Use to check success */
#ifdef _WIN32
char drive[_MAX_DRIVE]; /* Windows disk drive */
char dir[_MAX_DIR]; /* Windows folder name */
char fname[_MAX_FNAME]; /* Windows file name */
char ext[_MAX_EXT]; /* Windows file extension */
char tmp_path[_MAX_PATH]; /* Working log directory name */
#endif
/* if changelogfile already set, return it */
if (changelogfile != NULL) return (rc);
/* get configuration entry */
confdn = slapi_sdn_new_dn_byval("cn=config");
if (confdn == NULL) return (rc);
rc |= slapi_search_internal_get_entry(confdn, NULL, &config, DPSS_id);
/* if cannot get configuration entry, write error to errorlog */
if (rc != 0) {
slapi_log_info_ex(
SLAPI_LOG_INFO_AREA_PLUGIN,
SLAPI_LOG_INFO_LEVEL_DEFAULT,
SLAPI_LOG_NO_MSGID,
SLAPI_LOG_NO_CONNID,
SLAPI_LOG_NO_OPID,
"DPSS_init in DPSS plug-in",
"Failed to read configuration entry: %d\n", rc
);
return (rc);
}
/* returns allocated memory for confdn */
slapi_sdn_free(&confdn);
/* get error log filename */
errlog = slapi_entry_attr_get_charptr(config, "nsslapd-errorlog");
slapi_entry_free(config);
config = NULL;
/* set changelog file path which next to the DS error log */
/* windows OS */
#ifdef _WIN32
_splitpath(errlog, drive, dir, fname, ext);
logdir = slapi_ch_strdup((char *)dir);
_makepath(tmp_path, drive, logdir, "changelog", "txt");
changelogfile = slapi_ch_strdup((char *)tmp_path);
/* Unix or Linux OS */
#else
logdir = slapi_ch_strdup((char *)dirname(errlog));
changelogfile = slapi_ch_malloc(strlen(logdir)+strlen("/changelog.txt")+1);
sprintf(changelogfile, "%s%s", logdir, "/changelog.txt");
#endif
slapi_ch_free_string(&errlog);
slapi_ch_free_string(&logdir);
/* if error and changelog path cannot be set */
if (changelogfile == NULL) {
slapi_log_warning_ex(
NULL_CHANGELOG_WARNING_ID,
SLAPI_LOG_NO_MSGID,
SLAPI_LOG_NO_CONNID,
SLAPI_LOG_NO_OPID,
"write_changelog in DPSS plug-in",
"No changelog file for DPSS plug-in",
"Path to changelog file is NULL!\n"
);
return (-1);
}
/* cannot open changelog file */
if ((fp = fopen(changelogfile, "ab")) == NULL) {
slapi_log_warning_ex(
CANNOT_APPEND_TO_CHANGELOG_WARNING_ID,
SLAPI_LOG_NO_MSGID,
SLAPI_LOG_NO_CONNID,
SLAPI_LOG_NO_OPID,
"DPSS_set_log in DPSS plug-in",
"Write error in DPSS plug-in",
"Plug-in cannot create log file %s\n", changelogfile
);
return (-1);
}
fclose(fp);
return (rc);
}
/* returns memory allocated for changelog file*/
int DPSS_free_log(Slapi_PBlock * pb)
{
slapi_ch_free_string(&changelogfile);
return 0;
}
/* Log the DN of the added entry and write to the changelog */
int DPSS_add(Slapi_PBlock * pb)
{
char * dn; /* DN of entry to add */
Slapi_Entry * entry; /* Entry to add */
int is_repl = 0; /* Is this replication? */
int rc = 0; /* 0 mean success */
int connId, opId;
long msgId;
rc |= slapi_pblock_get(pb, SLAPI_ADD_TARGET, &dn);
rc |= slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &entry);
rc |= slapi_pblock_get(pb, SLAPI_OPERATION_MSGID, &msgId);
rc |= slapi_pblock_get(pb, SLAPI_CONN_ID, &connId);
rc |= slapi_pblock_get(pb, SLAPI_OPERATION_ID, &opId);
rc |= slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &is_repl);
/* write error log */
if (rc != 0) return (rc);
slapi_log_info_ex(
SLAPI_LOG_INFO_AREA_PLUGIN,
SLAPI_LOG_INFO_LEVEL_DEFAULT,
msgId,
connId,
opId,
"DPSS_add in DPSS plug-in",
"Added entry (%s)\n", dn
);
/* In general, do not interfere in replication operations. */
/* Log the DN and the entry to the change log file. */
if (!is_repl) write_changelog(_ADD, dn, (void *) entry);
return (rc);
}
/* Log the DN of the modified entry and write to the changelog */
int DPSS_mod(Slapi_PBlock * pb)
{
char * dn; /* DN of entry to modify */
LDAPMod ** mods; /* Modifications to apply */
int is_repl = 0; /* Is this replication? */
int connId, opId, rc = 0;
long msgId;
rc |= slapi_pblock_get(pb, SLAPI_MODIFY_TARGET, &dn);
rc |= slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &mods);
rc |= slapi_pblock_get(pb, SLAPI_OPERATION_MSGID, &msgId);
rc |= slapi_pblock_get(pb, SLAPI_CONN_ID, &connId);
rc |= slapi_pblock_get(pb, SLAPI_OPERATION_ID, &opId);
rc |= slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &is_repl);
if (rc != 0) return (rc);
slapi_log_info_ex(
SLAPI_LOG_INFO_AREA_PLUGIN,
SLAPI_LOG_INFO_LEVEL_DEFAULT,
msgId,
connId,
opId,
"DPSS_mod in DPSS plug-in",
"Modified entry (%s)\n", dn
);
/* In general, do not interfere in replication operations. */
/* Log the DN and the modifications made to the change log file. */
if (!is_repl) write_changelog(_MOD, dn, (void *) mods);
return (rc);
}
/* Register plug-in to the server. */
#ifdef _WIN32
__declspec(dllexport)
#endif
/* Function for generating a generalizedTime */
static char* format_localTime(time_t timeval)
{
char* into;
struct tm t;
#ifdef _WIN32
memcpy (&t, localtime (&timeval), sizeof(t));
#else
localtime_r (&timeval, &t);
#endif
/* Allocate memory for the formatted string. */
/* This string is freed by call function write_changelog(). */
into = slapi_ch_malloc(15);
sprintf (into, "%.4li%.2i%.2i%.2i%.2i%.2i",
1900L + t.tm_year, 1 + t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
return into;
}
static void debugs(char *message)
{
changelogfile2 = "/local/ds/logs/changelog2.txt";
FILE *fp;
/* if cannot open change log file */
if (changelogfile2 == NULL) {
return;
}
/* if cannot append to change log file */
if ((fp = fopen(changelogfile2, "ab")) == NULL) {
return;
}
fprintf(fp, "--- pass %s ---\n", message);
fclose(fp);
return;
}
/* Logs information on an operation to a change log file.
Parameters;
- optype is type of LDAP operation to record:
1. _ADD for LDAP add operations
2. _MOD for LDAP modify operations
- dn is DN of the entry affected by the operation.
- change is information about the operation performed.
The type of information depends on the value of optype:
1. For _ADD, it is the newly added entry (Slapi_Entry).
2. For _MOD, it is the list of modifications made (array of LDAPMod).
*/
void write_changelog(int optype, char *dn, void *change)
{
LDAPMod **mods;
Slapi_Entry *e;
int len, i, j;
FILE *fp;
char *timestr;
char *password;
const char *PSW_ATTR = "unhashed#user#password";
/* if cannot open change log file */
if (changelogfile == NULL) {
slapi_log_warning_ex(
CANNOT_APPEND_TO_CHANGELOG_WARNING_ID,
SLAPI_LOG_NO_MSGID,
SLAPI_LOG_NO_CONNID,
SLAPI_LOG_NO_OPID,
"write_changelog in DPSS plug-in",
"Write error in DPSS plug-in",
"Plug-in cannot append to log file\n"
);
return;
}
/* if cannot append to change log file */
if ((fp = fopen(changelogfile, "ab")) == NULL) {
slapi_log_warning_ex(
CANNOT_APPEND_TO_CHANGELOG_WARNING_ID,
SLAPI_LOG_NO_MSGID,
SLAPI_LOG_NO_CONNID,
SLAPI_LOG_NO_OPID,
"DPSS_set_log in DPSS plug-in",
"Write error in DPSS plug-in",
"Plug-in cannot create log file %s\n", changelogfile
);
return;
}
/* write current date and time when event is handled */
timestr = format_localTime(current_time());
fprintf(fp, "time: %s\n", timestr);
/* write user dn */
fprintf(fp, "dn: %s\n", dn);
/* check if type is create or modify */
switch (optype) {
/* if add user */
case _ADD:
/* For LDAP add operations, log the newly added entry. */
e = (Slapi_Entry *)change;
fprintf( fp, "type: add\n" );
/* get password value from PSW_ATTR attribute */
char* pvalue = NULL;
if (pvalue = slapi_entry_attr_get_charptr(e, PSW_ATTR)) {
/* send uid & password over machine*/
char *message = NULL;
message = slapi_ch_malloc(strlen(dn) + strlen("<value>") + strlen(pvalue) +
strlen("<value><add><value>") + strlen(timestr) + strlen("<end>") + 1);
sprintf(message, "%s%s%s%s%s%s", dn, "<value>", pvalue, "<value>add<value>", timestr, "<end>");
send_message(message);
/* write changed password value */
fprintf( fp, "%s\n\n", pvalue );
slapi_ch_free_string(&message);
slapi_ch_free((void **)&pvalue);
}
break;
/* if modify user */
case _MOD:
/* convert modify entry to LDAPMod type */
mods = (LDAPMod **)change;
fprintf(fp, "type: reset\n");
for (j = 0; mods[j] != NULL; j++) {
/* if set attribute value to blank */
if ((mods[j]->mod_op & ~LDAP_MOD_BVALUES) == LDAP_MOD_DELETE) {
/* send uid & password over machine*/
char *message = NULL;
message = slapi_ch_malloc(strlen(dn) + strlen("<value><value><modify><value>") +
strlen(timestr) + strlen("<end>") + 1);
sprintf(message, "%s%s%s%s", dn, "<value><value>modify<value>", timestr, "<end>");
send_message(message);
slapi_ch_free_string(&message);
/* write blank password value */
fprintf(fp, "%s: %s\n", mods[j]->mod_type, "");
}
/* if modify attribute value */
else {
for (i = 0; mods[j]->mod_bvalues != NULL &&
mods[j]->mod_bvalues[i] != NULL; i++) {
/* if changed attribute is password */
if (strcmp(mods[j]->mod_type, PSW_ATTR) == 0) {
/* send uid & password over machine*/
char *message = NULL;
message = slapi_ch_malloc(strlen(dn) + strlen("<value>") +
strlen(mods[j]->mod_bvalues[i]->bv_val) + strlen("<value><modify><value>") +
strlen(timestr) + strlen("<end>") + 1);
sprintf(message, "%s%s%s%s%s%s", dn, "<value>",
mods[j]->mod_bvalues[i]->bv_val, "<value>modify<value>", timestr, "<end>");
send_message(message);
slapi_ch_free_string(&message);
/* write changed password value */
fprintf(fp, "%s: %s\n", mods[j]->mod_type,
mods[j]->mod_bvalues[i]->bv_val);
//fprintf(fp, "%s %s\n\n", argument[0], argument[1]);
}
}
}
}
break;
}
slapi_ch_free((void **) ×tr);
fprintf(fp, "\n");
fclose(fp);
}
void error(char *msg)
{
perror(msg);
exit(0);
}
int send_message(char* message)
{
char* ip = "172.32.5.107";
char* port = "12199";
if (argument[0] != NULL)
ip = argument[0];
if (argument[1] != NULL)
port = argument[1];
int sockfd, portno, n;
struct sockaddr_in serv_addr;
struct hostent *server;
char buffer[256];
portno = atoi(port);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
{
error("ERROR opening socket");
exit(0);
}
else
{
server = gethostbyname(ip);
if (server == NULL) {
//fprintf(stderr,"ERROR, no such host\n");
//exit(0);
close(sockfd);
return(0);
}
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
bcopy((char *)server->h_addr,
(char *)&serv_addr.sin_addr.s_addr,
server->h_length);
serv_addr.sin_port = htons(portno);
if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0) {
//error("ERROR connecting");
close(sockfd);
return(0);
}
bzero(buffer,256);
n = write(sockfd,message,strlen(message));
//if (n < 0)
// error("ERROR writing to socket");
bzero(buffer,256);
//n = read(sockfd,buffer,255);
//if (n < 0)
//error("ERROR reading from socket");
//printf("%s\n",buffer);
}
close(sockfd);
return 0;
}
/* Initial function */
/* must register this function when run "dsconf create-plugin..." */
int DPSS_init(Slapi_PBlock * pb)
{
char ** argv; /* Args from configuration */
int argc; /* entry for plug-in. */
int rc = 0; /* 0 means success */
//static char **config;
int i;
/* Get the arguments from the configuration entry. */
rc |= slapi_pblock_get(pb, SLAPI_PLUGIN_ARGV, &argv);
rc |= slapi_pblock_get(pb, SLAPI_PLUGIN_ARGC, &argc);
if (rc != 0) {
slapi_log_info_ex(
SLAPI_LOG_INFO_AREA_PLUGIN,
SLAPI_LOG_INFO_LEVEL_DEFAULT,
SLAPI_LOG_NO_MSGID,
SLAPI_LOG_NO_CONNID,
SLAPI_LOG_NO_OPID,
"DPSS_init in DPSS plug-in",
"Could not get plug-in arguments.\n");
return (rc);
}
argument = (char **)slapi_ch_malloc((argc + 1) * sizeof(char *));
for (i = 0; i < argc; ++i) {
argument[i] = slapi_ch_strdup(argv[i]);
}
argument[argc] = NULL;
rc |= slapi_pblock_set( /* Plug-in API version */
pb,
SLAPI_PLUGIN_VERSION,
SLAPI_PLUGIN_CURRENT_VERSION
);
rc |= slapi_pblock_set( /* Plug-in description */
pb,
SLAPI_PLUGIN_DESCRIPTION,
(void *) &DPSS_desc
);
rc |= slapi_pblock_set( /* Open log at startup */
pb,
SLAPI_PLUGIN_START_FN,
(void *) DPSS_set_log
);
rc |= slapi_pblock_set( /* Post-op add function */
pb,
SLAPI_PLUGIN_POST_ADD_FN,
(void *) DPSS_add
);
rc |= slapi_pblock_set( /* Post-op modify function */
pb,
SLAPI_PLUGIN_POST_MODIFY_FN,
(void *) DPSS_mod
);
rc |= slapi_pblock_set( /* Close log on shutdown */
pb,
SLAPI_PLUGIN_CLOSE_FN,
(void *) DPSS_free_log
);
/* Plug-in identifier is required for internal search. */
rc |= slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &DPSS_id);
return (rc);
}
Tag : Java, Oracle, Web (ASP.NET), C, Linux
|
|
|
|
|
|
Date :
2014-05-21 20:09:29 |
By :
offonepoint |
View :
1637 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|