int SetSupGroups(LINACONFIG *lc,int Index) { FILE *pf=NULL; char buff[2000],*pt,*Pw,*UserName; int GroupNo,Ugid,*ipt,count,*array,i; Dlink *Glist=NULL; pf = popen("cat /etc/group","r"); if(pf==NULL) return 0; Glist=Dopen(); UserName = GetUserId(lc,Index); Ugid = GetGid(lc,Index); while (fgets(buff,1999,pf) != NULL) { if( (pt=GetLoginId(buff))==NULL) continue; // Actually Group Name Pw = GetUserPasswd(buff); if(Pw==NULL) continue; if(Pw[0]=='\0') { free(Pw);continue;} GroupNo=GetUserNo(buff); if(GroupNo==Ugid) {free(Pw);continue;} if((i=SearchString(buff,UserName))>= 0) { int j=0; j =i; while((buff[j]>' ') &&(buff[j]!=',')&&(buff[j]!=':')) j++; buff[j]='\0'; if(strcmp(buff+i,UserName)==0) { ipt=(int *)malloc(sizeof(int)); *ipt = GroupNo; Dadd(Glist,ipt); // printf("%s : %d\n",pt,*ipt); printf("%d ",*ipt); } } free(pt);free(Pw); } count = Dcount(Glist); printf(" :Supp group count = %d\n",count); fflush(stdout); if(count > 0) { array = (int *)malloc(sizeof(int)*(count)); Resetlink(Glist); i=0; while( (ipt = (int *)Getrecord(Glist))!= NULL) { array[i++]=*ipt; } setgroups(count,array); free(array); } pclose(pf); Dempty(Glist); return count; }
bool UnifiedGenericInstance::Equals(GenericInstanceDesc * pLocalGid) { GenericInstanceDesc * pCanonicalGid = GetGid(); UInt32 cTypeVars = pCanonicalGid->GetArity(); // If the number of type arguments is different, we can never have a match. if (cTypeVars != pLocalGid->GetArity()) return false; // Compare the generic type itself. if (pCanonicalGid->GetGenericTypeDef().GetValue() != pLocalGid->GetGenericTypeDef().GetValue()) return false; // Compare the type arguments of the instantiation. for (UInt32 i = 0; i < cTypeVars; i++) { EEType * pUnifiedType = pCanonicalGid->GetParameterType(i).GetValue(); EEType * pLocalType = pLocalGid->GetParameterType(i).GetValue(); if (pUnifiedType != pLocalType) { // Direct pointer comparison failed, but there are a couple of cases where converting the local // generic instantiation to the unified version had to update the type variable EEType to avoid // including a pointer to an arbitrary module (one not related to the generic instantiation via a // direct type dependence). // * Cloned types were converted to their underlying canonical types. // * Some array types were re-written to use a module-neutral definition. if (pLocalType->IsCanonical()) return false; if (pLocalType->IsCloned()) { if (pUnifiedType != pLocalType->get_CanonicalEEType()) return false; else continue; // type parameter matches } ASSERT(pLocalType->IsParameterizedType()); if (!pUnifiedType->IsParameterizedType()) return false; if (pUnifiedType->get_RelatedParameterType() != pLocalType->get_RelatedParameterType()) return false; if (pUnifiedType->get_ParameterizedTypeShape() != pLocalType->get_ParameterizedTypeShape()) return false; } } return true; }
int main(int argc, char *argv[]) { #ifdef _WIN32 nodaemon = 1; WSADATA wsadata; WSAStartup(0x0202, &wsadata); #endif SOCKET s = INVALID_SOCKET; s = socket(AF_INET6, SOCK_STREAM, 0); if (s != INVALID_SOCKET) { HaveIPv6Stack = 1; close(s); s = INVALID_SOCKET; } s = socket(AF_INET, SOCK_STREAM, 0); if (s != INVALID_SOCKET) { HaveIPv4Stack = 1; close(s); } int o; const static char* const optstring = "u:g:L:p:i:P:l:r:feD46"; for (opterr = 0; ( o = getopt(argc, argv, optstring) ) > 0; ) switch (o) { case '4': if (!HaveIPv4Stack) { fprintf(stderr, "Fatal: Your system does not support %s.\n", cIPv4); return !0; } v4required = 1; break; case '6': if (!HaveIPv6Stack) { fprintf(stderr, "Fatal: Your system does not support %s.\n", cIPv6); return !0; } v6required = 1; break; case 'p': fn_pid = optarg; break; case 'i': fn_ini = optarg; break; case 'l': fn_log = optarg; break; case 'L': maxsockets++; break; case 'f': nodaemon = 1; logstdout = 1; break; case 'D': nodaemon = 1; break; case 'e': logstdout = 1; break; case 'r': RandomizationLevel = atoi(optarg); if (RandomizationLevel < 0 || RandomizationLevel > 2) RandomizationLevel = 1; break; case 'g': if (GetGid()) return !0; break; case 'u': if (GetUid()) return !0; break; case 'P': break; default: Usage(argv[0]); return !0; } if (optind != argc) { Usage(argv[0]); return !0; } int allocsockets = maxsockets ? maxsockets : 2; SocketList = malloc(allocsockets * sizeof(SOCKET)); #if defined(__BSD__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) optind = 1; optreset = 1; // Makes BSD getopt happy #else optind = 0; // Makes GLIBC getopt happy #endif for (opterr = 0; ( o = getopt(argc, argv, optstring) ) > 0; ) switch (o) { case 'L': AddSocketAddress(optarg); break; case 'P': defaultport = optarg; break; default: break; } if (!maxsockets) { if (HaveIPv6Stack && (v6required || !v4required)) AddSocketAddress("::"); if (HaveIPv4Stack && (v4required || !v6required)) AddSocketAddress("0.0.0.0"); } if (!numsockets) { fprintf(stderr, "Fatal: Could not listen on any socket.\n"); return !0; } #ifndef _WIN32 if ((gid != INVALID_GID && setgid(gid)) || (uid != INVALID_GID && setuid(uid))) { fprintf(stderr, "Fatal: setgid/setuid for %s failed.\n", optarg); return !0; } #endif if (RandomizationLevel == 1) { int i; srand((unsigned int)time(NULL)); int serverType = rand() % _countof(HostOS); int16_t lang = LcidList[rand() % _countof(LcidList)]; for (i = 0; i < _countof(RandomPid); i++) { GenerateRandomPid(AppList[i].guid, RandomPid[i], serverType, lang); } } #ifndef _WIN32 // Windows has no fork or signal handling if ( !nodaemon) if (daemon(!0, logstdout)) { fprintf(stderr, "Fatal: Could not daemonize to background.\n"); return errno; } { struct sigaction sa = { .sa_handler = SIG_IGN, .sa_flags = SA_NOCLDWAIT }; if ( sigemptyset(&sa.sa_mask) || sigaction(SIGCHLD, &sa, 0) ) return errno; } #endif logger("KMS emulator started successfully\n"); if (fn_pid) { FILE *_f = fopen(fn_pid, "w"); if ( _f ) { fprintf(_f, "%u", getpid()); fclose(_f); } else { logger("Warning: Cannot write pid file.\n"); } } srand( (int)time(NULL) ); RpcAssocGroup = rand(); for (;;) { socklen_t len; struct sockaddr_storage addr; SOCKET s_client; for (;;) if ( (s_client = network_accept_any(SocketList, numsockets, NULL, NULL)) < 0 ) { if ( errno != EINTR ) return errno; } else break; RpcAssocGroup++; len = sizeof addr; if (getsockname(s_client, (struct sockaddr*)&addr, &len) || getnameinfo((struct sockaddr*)&addr, len, NULL, 0, RpcSecondaryAddress, sizeof(RpcSecondaryAddress), NI_NUMERICSERV)) { strcpy(RpcSecondaryAddress, "1688"); // In case of failure use default port (doesn't seem to break activation) } RpcSecondaryAddressLength = LE16(strlen(RpcSecondaryAddress) + 1); #ifndef _WIN32 int pid; if ( (pid = fork()) < 0 ) return errno; else if ( pid ) close(s_client); else #endif { char ipstr[256], text[256]; struct timeval to = { .tv_sec = 60, .tv_usec = 0 }; setsockopt(s_client, SOL_SOCKET, SO_RCVTIMEO, (char*)&to, sizeof(to)); setsockopt(s_client, SOL_SOCKET, SO_SNDTIMEO, (char*)&to, sizeof(to)); len = sizeof addr; if (getpeername(s_client, (struct sockaddr*)&addr, &len) || !ip2str(ipstr, sizeof(ipstr), (struct sockaddr*)&addr, len)) { *ipstr = 0; } char *connection_type = addr.ss_family == AF_INET6 ? cIPv6 : cIPv4; static char *const cAccepted = "accepted"; static char *const cClosed = "closed"; static char *const fIP = "%s connection %s: %s.\n"; CloseAllListeningSockets(); sprintf(text, fIP, connection_type, cAccepted, ipstr); if (*ipstr) logger(text); RpcServer(s_client); #ifdef _WIN32 shutdown(s_client, SD_BOTH); #endif close(s_client); sprintf(text, fIP, connection_type, cClosed, ipstr); if (*ipstr) logger(text); #ifndef _WIN32 return 0; #endif } } unlink(fn_pid); CloseAllListeningSockets(); return 0; }