Hi as the thread title suggets....I need to implement the following function in perl.
Being a PERL uneducated...I have very sparse idea on that...I am attaching the snippet.
Can anyone help with this...will be highly appreciated.
Finally with the help of the perl module I need to get checked whether the user currently logged in is an admin user or not.
Being a PERL uneducated...I have very sparse idea on that...I am attaching the snippet.
Can anyone help with this...will be highly appreciated.
int
check_admin_role(char *rem_usr)
{
char *tok;
char *ptrbuf;
char tmpbuf[256]="";
char buf[255]="",tmp[100]="",cmd[100]="";
snprintf(cmd,100, "/isan/bin/vsh -c 'sh user-account %s' > /var/tmp/.tmp_check_role", rem_usr);
system(cmd);
FILE* fp = fopen("/var/tmp/.tmp_check_role","r");
if( fp != NULL) {
// opened successfully and now read each line of the file
while( fgets(tmp,100,fp) != NULL) {
strncat(buf, tmp, strlen(tmp));
}
fclose(fp);
}
system("rm /var/tmp/.tmp_check_role");
strncpy(tmpbuf, buf, strlen(buf)+1);
tok = strtok_r(tmpbuf, "\n", &ptrbuf);
while(tok) {
char *t;
char *ptrt;
if(strstr(tok, "roles")) {
t = strtok_r(tok, ":", &ptrt);
t = strtok_r(ptrt, ":",&ptrt);
if(t) {
while(*t == ' ')
t++;
if(!strncmp(t, "Admin", strlen(t)-1)) {
return 1;
}
else {
// xml_debug_message(DEBUG_INFO,XML_PARSE,"User does not have Admin Role");
return 0;
}
}
}
tok = strtok_r(ptrbuf, "\n", &ptrbuf);
}
// xml_debug_message(DEBUG_INFO,XML_PARSE,"User does not have Admin Role");
return 0;
}
Finally with the help of the perl module I need to get checked whether the user currently logged in is an admin user or not.