/* h_firstEnt_() * Get the first element from the hash table. * Starting the iteration on the table itself. */ hEnt * h_firstEnt_ (hTab * tabPtr, sTab * sPtr) { sPtr->tabPtr = tabPtr; sPtr->nIndex = 0; sPtr->hEntPtr = NULL; if (tabPtr->slotPtr) { return h_nextEnt_ (sPtr); } else { return (NULL); } }
int mychdir_(char *path, struct hostent *hp) { char *goodpath = path; char *sp = NULL; sTab hashSearchPtr; hEnt *hashEntryPtr; static char first = TRUE; char filename[MAXPATHLEN]; /*Bug#169, set hp to NULL to let the function do operation directly * and do not try /net and /tmp_mnt */ hp = NULL; if (path == NULL || strlen(path) == 0 || path[0] != '/' || AM_NEVER) return (chdir(usePath(path))); if (hp != NULL) if (netHostChdir(path, hp) == 0) return 0; if (strstr(path, "/tmp_mnt" ) == path) { sp = path + strlen("/tmp_mnt"); if (chdir(usePath(sp)) == 0) return 0; } else { if (chdir(usePath(path)) == 0) return 0; } if (errno != ENOENT && errno != ENOTDIR) return -1; if (getcwd(filename, sizeof(filename)) == NULL) goto try; sp = getenv("HOME"); if (sp != NULL) chdir(sp); chdir(filename); try: if (path[0] != '/') return -1; if ((goodpath=strstr(path,"/exp/lsf")) != NULL) { if (chdir(usePath(goodpath)) == 0) return 0; } if (strstr(path, "/tmp_mnt" ) == path) { goodpath = path + strlen("/tmp_mnt"); } else { if (chdir(usePath(path)) ==0) return 0; sp = getenv("PWD"); if (tryPwd(path, sp) == 0) return 0; } if (goodpath == NULL) goodpath = strchr(path+1, '/'); else goodpath = strchr(goodpath+1, '/'); if (goodpath != NULL) { if (chdir(usePath(goodpath)) == 0) return 0; } else { return -1; } if (first) { first = FALSE; if (getMap_() != 0) return -1; } hashEntryPtr = h_firstEnt_(&hashTab, &hashSearchPtr); if (hashEntryPtr == NULL) { errno = ENOENT; return -1; } while (hashEntryPtr != NULL) { sprintf(filename, "%s%s", hashEntryPtr->keyname, goodpath); if (chdir(usePath(filename)) == 0) return 0; hashEntryPtr = h_nextEnt_(&hashSearchPtr); } goodpath = strchr(goodpath+1, '/'); if (goodpath == NULL) { return -1; } hashEntryPtr = h_firstEnt_(&hashTab, &hashSearchPtr); while (hashEntryPtr != NULL) { sprintf(filename, "%s%s", hashEntryPtr->keyname, goodpath); if (chdir(usePath(filename)) == 0) return 0; hashEntryPtr = h_nextEnt_(&hashSearchPtr); } if (chdir(usePath(goodpath)) == 0) return 0; if ( strstr(path, "/tmp_mnt" ) != path) return -1; goodpath = path + strlen("/tmp_mnt"); if (*goodpath == '\0') return -1; strcpy(filename, goodpath); sp = strchr(filename+1, '/'); if (sp == NULL) return -1; goodpath = strchr(sp+1, '/'); if (goodpath == NULL) return -1; if ((sp = strchr(goodpath+1, '/')) == NULL) return -1; *goodpath = '\0'; strcat(filename, sp); if (chdir(usePath(filename)) ==0) return 0; if ((sp = strchr(goodpath+1, '/')) == NULL) return (-1); *goodpath = '\0'; strcat(filename, sp); if (chdir(usePath(filename)) ==0) return 0; if (chdir(usePath(path)) == 0) return 0; return -1; } static int tryPwd(char *path, char *pwdpath) { char *PA, *PAPB, *pa, *pb, *pc, *sp1; char filename[MAXFILENAMELEN]; if (pwdpath == NULL) return -1; if (strcmp(pwdpath, "/") == 0) return -1; strcpy(filename, pwdpath); sp1 = strchr(filename+1, '/'); if (sp1 != NULL) *sp1 = '\0'; PA = putstr_(filename); strcpy(filename, pwdpath); if (sp1 != NULL) { sp1 = strchr(sp1+1, '/'); if (sp1 != NULL) *sp1 = '\0'; } PAPB = putstr_(filename); pa = path; pb = strchr(path+1, '/'); if (pb == NULL) pb = pa; pc = strchr(pb+1, '/'); if (pc == NULL) pc = pb; strcpy(filename, PA); strcat(filename, pa); if (chdir(usePath(filename)) == 0) { free(PA); free(PAPB); return 0; } strcpy(filename, PA); strcat(filename, pb); if (chdir(usePath(filename)) == 0) { free(PA); free(PAPB); return 0; } strcpy(filename, PAPB); strcat(filename, pc); if (chdir(usePath(filename)) == 0) { free(PA); free(PAPB); return 0; } strcpy(filename, PAPB); strcat(filename, pb); if (chdir(usePath(filename)) == 0) { free(PA); free(PAPB); return 0; } free(PA); free(PAPB); return -1; }
int ls_initrex(int num, int options) { struct servent *sv; if (geteuid() == 0) rootuid_ = TRUE; if (initenv_(NULL, NULL)<0) { if (rootuid_ && !(options & KEEPUID)) lsfSetUid(getuid()); return(-1); } inithostsock_(); lsQueueInit_(&requestQ, lsReqCmp_, NULL); if (requestQ == NULL) { lserrno = LSE_MALLOC; return(-1); } res_addr_.sin_family = AF_INET; if (genParams_[LSF_RES_PORT].paramValue) { if ((res_addr_.sin_port = atoi(genParams_[LSF_RES_PORT].paramValue)) != 0) res_addr_.sin_port = htons(res_addr_.sin_port); else goto res_init_fail; } else if (genParams_[LSF_RES_DEBUG].paramValue) { res_addr_.sin_port = htons(RES_PORT); } else { # if defined(_COMPANY_X_) if ((res_addr_.sin_port = get_port_number(RES_SERVICE,(char *)NULL)) == -1) { # else if ((sv = getservbyname("res", "tcp")) != NULL) res_addr_.sin_port = sv->s_port; else { # endif res_init_fail: lserrno = LSE_RES_NREG; if (rootuid_ && !(options & KEEPUID)) lsfSetUid(getuid()); return (-1); } } initconntbl_(); FD_ZERO(&connection_ok_); if ((rootuid_) && (genParams_[LSF_AUTH].paramValue == NULL)) { int i; i = opensocks_(num); if (!(options & KEEPUID)) lsfSetUid(getuid()); return (i); } else { return (num); } } int opensocks_(int num) { static char fname[] = "opensocks_"; int s; int nextdescr; int i; totsockets_ = (num <= 0 || num > MAXCONNECT) ? LSF_DEFAULT_SOCKS : num; if (logclass & LC_COMM) ls_syslog(LOG_DEBUG,"%s: try to allocate num <%d> of socks",fname,num); nextdescr = FIRST_RES_SOCK; for (i = 0; i < totsockets_; i++) { if ((s = CreateSock_(SOCK_STREAM)) < 0) { if (logclass & LC_COMM) ls_syslog(LOG_DEBUG, "%s: CreateSock_ failed, iter:<%d> %s", fname,i,strerror(errno)); totsockets_ = i; if (i > 0) { break; } else { return(-1); } } if (s != nextdescr) { if (dup2(s,nextdescr) < 0) { if (logclass & LC_COMM) ls_syslog(LOG_DEBUG, "%s: dup2() failed, old:<%d>, new<%d>, iter:<%d> %s", fname,s,nextdescr,i,strerror(errno)); close(s); lserrno = LSE_SOCK_SYS; totsockets_ = i; if (i > 0) break; else return (-1); } #if defined(FD_CLOEXEC) fcntl(nextdescr, F_SETFD, (fcntl(nextdescr, F_GETFD) | FD_CLOEXEC)) ; #else #if defined(FIOCLEX) (void)ioctl(nextdescr, FIOCLEX, (char *)NULL); #endif #endif close(s); } nextdescr++; } currentsocket_ = FIRST_RES_SOCK; if (logclass & LC_COMM) ls_syslog(LOG_DEBUG,"%s: returning num=<%d>",fname,totsockets_); return (totsockets_); } /* ls_fdbusy() */ int ls_fdbusy(int fd) { sTab hashSearchPtr; hEnt *hEntPtr; if (fd == chanSock_(limchans_[PRIMARY]) || fd == chanSock_(limchans_[MASTER]) || fd == chanSock_(limchans_[UNBOUND])) return TRUE; if (fd == cli_nios_fd[0]) return TRUE; hEntPtr = h_firstEnt_(&conn_table, &hashSearchPtr); while (hEntPtr) { int *pfd; pfd = hEntPtr->hData; if (fd == pfd[0] || fd == pfd[1]) return (TRUE); hEntPtr = h_nextEnt_(&hashSearchPtr); } if (rootuid_ && fd >= currentsocket_ && fd < FIRST_RES_SOCK + totsockets_) return TRUE; return FALSE; }