void QMLManager::retrieveUserid() { if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) != 302) { appendTextToLog(QStringLiteral("Cloud storage connection not working correctly: (%1) %2") .arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()) .arg(QString(reply->readAll()))); setStartPageText(RED_FONT + tr("Cannot connect to cloud storage") + END_FONT); revertToNoCloudIfNeeded(); return; } setCredentialStatus(VALID); QString userid(prefs.userid); if (userid.isEmpty()) { if (same_string(prefs.cloud_storage_email, "") || same_string(prefs.cloud_storage_password, "")) { appendTextToLog("cloud user name or password are empty, can't retrieve web user id"); revertToNoCloudIfNeeded(); return; } appendTextToLog(QStringLiteral("calling getUserid with user %1").arg(prefs.cloud_storage_email)); userid = locationProvider->getUserid(prefs.cloud_storage_email, prefs.cloud_storage_password); } if (!userid.isEmpty()) { // overwrite the existing userid free(prefs.userid); prefs.userid = strdup(qPrintable(userid)); QSettings s; s.setValue("subsurface_webservice_uid", prefs.userid); s.sync(); } setCredentialStatus(VALID); setStartPageText("Cloud credentials valid, loading dives..."); git_storage_update_progress(true, "load dives with valid credentials"); // this only gets called with "alreadySaving" already locked loadDivesWithValidCredentials(); }
int gethostname(char *name, int namelen) { NMRec rec = {30,23,"Procyon~GNO/ME~HoStNaMe"}; /* why blockLen = 30? */ ResponseR mbnResp; Handle message; mbnResp.l = MessageByName(0,(Pointer)&rec); if (_toolErr) { errno = ENOENT; return -1; } #if 0 printf("MBN returned %X %X\n", mbnResp.w.messageID, mbnResp.w.createFlag); #endif MessageCenter(getMessage,mbnResp.w.messageID, message = NewHandle(0l,userid(),0,0l)); if (_toolErr) { errno = ENOMEM; return -1; } strncpy(name, (char *)*message+6+2+(1+23), MIN(MAXHOSTNAMELEN, namelen)); DisposeHandle(message); return 0; }
void NodeFriendCircleComment::setCommentInfoShow(std::vector<msg::CommentInfo> commentInfo ,int index ) { int i=index; auto allInfo=commentInfo; auto userinfo=commentInfo[i].userinfo(); userID=userinfo.userid(); auto nickname =userinfo.nickname(); auto infoma=commentInfo.at(i); auto type =infoma.type(); this->setCommentID(infoma.commentid()); this->setParentID(infoma.parentcomment()); this->setIfDelete(infoma.isdelete()); std::map<int,std::string> alluserinfo; for(auto itor:commentInfo) { if(itor.type()!=msg::CommentType::LIKE) { alluserinfo[itor.commentid()]=itor.userinfo().nickname(); } } if(type==1) { textReplay->setString(nickname+":"); } else if(type ==3) { std::string replyName=alluserinfo[infoma.parentcomment()]; textReplay->setString(nickname+" "+tools::local_string("reply","回复")+" "+replyName+" :"); } auto info = commentInfo[i]; textDate->setString(getStringFromInt(commentInfo[i].time())); textComment->setString(commentInfo[i].content()); textComment->setContentSize(Size(117,38)); std::string time = getStringFromInt(commentInfo[i].time()); std::string text = ""; const std::string& text1=time; double time2 = tools::stod(text1); time2 /= 1000; text = tools::time_display(time2); texthour->setString(text); textDate->setVisible(false); auto imgName=userinfo.picname(); if(imgName == "") { imgName = "Default/image_defualt_user_icon_small48X48.png"; } ShaderSprite *imgIcon = ShaderSprite::createAndDownload(imgName, "Default/image_defualt_user_icon_small48X48.png", "Default/image_defualt_user_icon_small48X48.png"); imgIcon->setAnchorPoint(Vec2(0,0.5)); imgIcon->setPosition(headImage->getPosition()); headImage->setVisible(false); this->addChild(imgIcon); }
int main(int argc, char *argv[]) { int ch; char *fn; /* Report stack usage at end if compile option is set */ __REPORT_STACK(); /* Parse the command-line options */ while ((ch = getopt(argc, argv, "bc")) != -1) switch (ch) { case 'c': cflag = 1; break; case 'b': bflag = 1; break; case '?': default: usage(); } argc -= optind; argv = argv + optind; if (!*argv) usage(); else { /* Start up the resource manager */ ResourceStartUp(userid()); /* Parse the command-line filenames */ while (*argv) { fn = *argv++; ReadResources(fn); if (*argv && !bflag) (void)printf("\n"); } /* Shut down the resource manager */ /* (which closes open resource files) */ ResourceShutDown(); } exit(rval); }
int main() { const Cadena NombreM("Jose Manuel Barba Gonzalez"); Fecha fecM(21,2,1982); Fecha fpubli(1,1,1970); Fecha fexp(3,7,2015); const Fecha fString("1/1/1970"); Fecha f; const char *user = "******"; Cadena art_id("110"); Cadena art_nom("Programación C"); Cadena cadM(user); //Numero Num_tjtM("1234 9840 9482 3847"); // Numero Num_tjtM("378282246310005"); Cadena userid("001"); Cadena userNom("Jose M"); Cadena userApll("Barba Gonzalez"); Cadena userDir("su casa"); // const Clave userPass("holas"); //istringstream isM("2/4/2006"); //ostringstream os(""); cout << "---" << endl; //isM >> f; /* Usuario userM(userid,userNom,userApll,userDir,userPass); Tarjeta TjtM(Num_tjtM,userM,fexp); Autor autM(userNom,userApll,userDir); Articulo::Autores autores = crea_autores(autM); Libro artM(autores,art_id,art_nom,fpubli,50.55,200,100); InformeDigital InfDigM(autores,art_id,art_nom,fpubli,50.55,fexp); */ cout << "Main\n" << NombreM << endl << cadM << "." << endl; cout << "---Cadena---" << endl; cout << "Extraccion: una palabra --- "; istringstream is("bueno bonito barato"); Cadena c("algo"); is >> c; if(c == "bueno" && is.peek() == ' ') cout << "OK." << endl; cout << c << endl; cout << endl << "---Fecha---" << endl; cout << "Fecha de Nacimiento: "; fecM.visualizar(); cout << "Fecha como cadena: "; fString.visualizar(); Fecha g(--fecM);g.visualizar();g.restadias(3);g.visualizar(); ++g;g.visualizar();g.sumadias(2);g.visualizar(); cout << "---" << endl; //f.visualizar(); //cout << f; /* cout << "\n---Articulo Libro---\n" << artM; cout << "\n---Articulo InformeDigital---\n" << "A la venta hasta el "; InfDigM.imp_esp(os); cout << "\n---Tarjeta---\n" << TjtM.tarjeta() << endl; cout << "\n---Usuario---\n" << userM.id() << "|" << userM.nombre() << " " << userM.apellidos() << "|" << userM.direccion() << "|" << userPass.clave() << endl; if(userPass.verifica("holas")) cout << "Verificada" << endl; else cout << "No Verificada" << endl; */ return 0; }
void do_arguments(globalstate *gstate, int ac, char **av) { int i; /* this appears to keep getopt happy */ optind = 1; #ifdef HAVE_GETOPT_LONG while ((i = getopt_long(ac, av, "CDSIMTabcinqtuvs:d:U:o:m:", longopts, NULL)) != -1) #else while ((i = getopt(ac, av, "CDSIMTabcinqtuvs:d:U:o:m:")) != EOF) #endif { switch(i) { #ifdef ENABLE_COLOR case 'C': gstate->use_color = !gstate->use_color; break; #endif case 'D': debug_set(1); break; case 'v': fprintf(stderr, "%s: version %s\n", myname, version_string()); exit(EX_OK); break; case 'b': case 'n': gstate->interactive = No; break; case 'a': gstate->displays = Infinity; gstate->topn = Infinity; break; case 'i': gstate->interactive = Yes; break; case 'o': gstate->order_name = optarg; break; case 'd': i = atoiwi(optarg); if (i == Invalid || i == 0) { message_error(" Bad display count"); } else { gstate->displays = i; } break; case 's': i = atoi(optarg); if (i < 0 || (i == 0 && getuid() != 0)) { message_error(" Bad seconds delay"); } else { gstate->delay = i; } break; case 'u': gstate->show_usernames = !gstate->show_usernames; break; case 'U': i = userid(optarg); if (i == -1) { message_error(" Unknown user '%s'", optarg); } else { gstate->pselect.uid = i; } break; case 'm': i = atoi(optarg); gstate->pselect.mode = i; break; case 'S': gstate->pselect.system = !gstate->pselect.system; break; case 'I': gstate->pselect.idle = !gstate->pselect.idle; break; case 'M': enable_ncpus = 1; break; #ifdef ENABLE_COLOR case 'T': gstate->show_tags = 1; break; #endif case 'c': gstate->pselect.fullcmd = !gstate->pselect.fullcmd; break; case 't': gstate->pselect.threads = !gstate->pselect.threads; break; case 'q': /* be quick about it */ /* only allow this if user is really root */ if (getuid() == 0) { /* be very un-nice! */ (void) nice(-20); } else { message_error(" Option -q can only be used by root"); } break; default: fprintf(stderr, "\ Top version %s\n\ Usage: %s [-ISTabcinqu] [-d x] [-s x] [-o field] [-U username] [number]\n", version_string(), myname); exit(EX_USAGE); } } /* get count of top processes to display */ if (optind < ac && *av[optind]) { if ((i = atoiwi(av[optind])) == Invalid) { message_error(" Process count not a number"); } else { gstate->topn = i; } } }
int AppSettings::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 13) qt_static_metacall(this, _c, _id, _a); _id -= 13; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QString*>(_v) = token(); break; case 1: *reinterpret_cast< QUrl*>(_v) = address(); break; case 2: *reinterpret_cast< QString*>(_v) = email(); break; case 3: *reinterpret_cast< QString*>(_v) = username(); break; case 4: *reinterpret_cast< QString*>(_v) = password(); break; case 5: *reinterpret_cast< QString*>(_v) = userid(); break; } _id -= 6; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setToken(*reinterpret_cast< QString*>(_v)); break; case 1: setAddress(*reinterpret_cast< QUrl*>(_v)); break; case 2: setEmail(*reinterpret_cast< QString*>(_v)); break; case 3: setUsername(*reinterpret_cast< QString*>(_v)); break; case 4: setPassword(*reinterpret_cast< QString*>(_v)); break; case 5: setUserid(*reinterpret_cast< QString*>(_v)); break; } _id -= 6; } else if (_c == QMetaObject::ResetProperty) { _id -= 6; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 6; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 6; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 6; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 6; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 6; } #endif // QT_NO_PROPERTIES return _id; }
int main(int argc, char **argv) { sigset_t oldmask, newmask; pid_t pid; int status; int exitcode; char *valid_users; char *ptr; char *path; char cwd[MAXPATHLEN+3]; int opt; struct rlimit lim; progname = argv[0]; /* Clear environment to prevent all kinds of security holes, save PATH */ path = getenv("PATH"); environ[0] = NULL; /* FIXME: Clean path before setting it again? */ if ( path!=NULL ) setenv("PATH",path,1); /* Parse command-line options */ use_root = use_time = use_user = use_output = no_coredump = 0; memsize = filesize = nproc = RLIM_INFINITY; be_verbose = be_quiet = 0; show_help = show_version = 0; opterr = 0; while ( (opt = getopt_long(argc,argv,"+r:t:u:m:f:p:co:vq",long_opts,(int *) 0))!=-1 ) { switch ( opt ) { case 0: /* long-only option */ break; case 'r': /* rootdir option */ use_root = 1; rootdir = (char *) malloc(strlen(optarg)+2); strcpy(rootdir,optarg); break; case 't': /* time option */ use_time = 1; runtime = strtol(optarg,&ptr,10); if ( *ptr!=0 || runtime<=0 ) { error(0,"invalid time specified: `%s'",optarg); } break; case 'u': /* user option */ use_user = 1; runuid = strtol(optarg,&ptr,10); if ( *ptr!=0 ) runuid = userid(optarg); if ( runuid<0 ) error(0,"invalid username or ID specified: `%s'",optarg); break; case 'm': /* memsize option */ memsize = (rlim_t) strtol(optarg,&ptr,10); if ( *ptr!=0 || memsize<=0 ) { error(0,"invalid memory limit specified: `%s'",optarg); } /* Convert limit from kB to bytes and check for overflow */ if ( memsize!=(memsize*1024)/1024 ) { memsize = RLIM_INFINITY; } else { memsize *= 1024; } break; case 'f': /* filesize option */ filesize = (rlim_t) strtol(optarg,&ptr,10); if ( *ptr!=0 || filesize<=0 ) { error(0,"invalid filesize limit specified: `%s'",optarg); } /* Convert limit from kB to bytes and check for overflow */ if ( filesize!=(filesize*1024)/1024 ) { filesize = RLIM_INFINITY; } else { filesize *= 1024; } break; case 'p': /* nproc option */ nproc = (rlim_t) strtol(optarg,&ptr,10); if ( *ptr!=0 || nproc<=0 ) { error(0,"invalid process limit specified: `%s'",optarg); } break; case 'c': /* no-core option */ no_coredump = 1; break; case 'o': /* output option */ use_output = 1; outputfilename = (char *) malloc(strlen(optarg)+2); strcpy(outputfilename,optarg); break; case 'v': /* verbose option */ be_verbose = 1; break; case 'q': /* quiet option */ be_quiet = 1; break; case ':': /* getopt error */ case '?': error(0,"unknown option or missing argument `%c'",optopt); break; default: error(0,"getopt returned character code `%c' ??",(char)opt); } } if ( show_help ) usage(); if ( show_version ) version(); if ( argc<=optind ) error(0,"no command specified"); /* Command to be executed */ cmdname = argv[optind]; cmdargs = argv+optind; /* Check that new uid is in list of valid uid's. This must be done before chroot for /etc/passwd lookup. */ if ( use_user ) { valid_users = strdup(VALID_USERS); for(ptr=strtok(valid_users,","); ptr!=NULL; ptr=strtok(NULL,",")) { if ( runuid==userid(ptr) ) break; } if ( ptr==NULL || runuid<=0 ) error(0,"illegal user specified: %d",runuid); } /* Set resource limits: must be root to raise hard limits. Note that limits can thus be raised from the systems defaults! */ /* First define shorthand macro function */ #define setlim(type) \ if ( setrlimit(RLIMIT_ ## type, &lim)!=0 ) { \ if ( errno==EPERM ) { \ warning("no permission to set resource RLIMIT_" #type); \ } else { \ error(errno,"setting resource RLIMIT_" #type); \ } \ } if ( memsize!=RLIM_INFINITY ) { verbose("setting memory limits to %d bytes",(int)memsize); } lim.rlim_cur = lim.rlim_max = memsize; setlim(AS); setlim(DATA); setlim(STACK); setlim(MEMLOCK); if ( filesize!=RLIM_INFINITY ) { verbose("setting filesize limit to %d bytes",(int)filesize); } lim.rlim_cur = lim.rlim_max = filesize; setlim(FSIZE); if ( nproc!=RLIM_INFINITY ) { verbose("setting process limit to %d",(int)nproc); } lim.rlim_cur = lim.rlim_max = nproc; setlim(NPROC); #undef setlim if ( no_coredump ) { verbose("disabling core dumps"); lim.rlim_cur = lim.rlim_max = 0; if ( setrlimit(RLIMIT_CORE,&lim)!=0 ) error(errno,"disabling core dumps"); } /* Set root-directory and change directory to there. */ if ( use_root ) { /* Small security issue: when running setuid-root, people can find out which directories exist from error message. */ if ( chdir(rootdir) ) error(errno,"cannot chdir to `%s'",rootdir); /* Get absolute pathname of rootdir, by reading it. */ if ( getcwd(cwd,MAXPATHLEN)==NULL ) error(errno,"cannot get directory"); if ( cwd[strlen(cwd)-1]!='/' ) strcat(cwd,"/"); /* Canonicalize CHROOT_PREFIX: the use of NULL below is a GNU extension, recommended for security */ if ( (path = realpath(CHROOT_PREFIX,NULL))==NULL ) { error(errno,"cannot canonicalize path '%s'",CHROOT_PREFIX); } /* Check that we are within prescribed path. */ if ( strncmp(cwd,path,strlen(path))!=0 ) { error(0,"invalid root: must be within `%s'",path); } free(path); if ( chroot(".") ) error(errno,"cannot change root to `%s'",cwd); verbose("using root-directory `%s'",cwd); } /* Set user-id (must be root for this). */ if ( use_user ) { if ( setuid(runuid) ) error(errno,"cannot set user ID to `%d'",runuid); verbose("using user ID `%d'",runuid); } else { /* Reset effective uid to real uid, to increase security when program is run setuid */ if ( setuid(getuid()) ) error(errno,"cannot set real user ID"); verbose("using real uid `%d' as effective uid",getuid()); } if ( geteuid()==0 || getuid()==0 ) error(0,"root privileges not dropped"); /* Open output file for writing running time to */ if ( use_output ) { outputfile = fopen(outputfilename,"w"); if ( outputfile==NULL ) error(errno,"cannot open `%s'",outputfilename); verbose("using file `%s' to write runtime to",outputfilename); } switch ( child_pid = fork() ) { case -1: /* error */ error(errno,"cannot fork"); case 0: /* run controlled command */ /* Run the command in a separate process group so that the command and all its children can be killed off with one signal. */ setsid(); execvp(cmdname,cmdargs); error(errno,"cannot start `%s'",cmdname); default: /* become watchdog */ if ( gettimeofday(&starttime,NULL) ) error(errno,"getting time"); /* unmask all signals */ memset(&newmask, 0, sizeof(newmask)); if ( sigprocmask(SIG_SETMASK, &newmask, &oldmask)!=0 ) { error(errno,"unmasking signals"); } signal(SIGTERM,terminate); if ( use_time ) { signal(SIGALRM,terminate); alarm(runtime); verbose("using timelimit of %d seconds",runtime); } /* Wait for the child command to finish */ while ( (pid = wait(&status))!=-1 && pid!=child_pid ); if ( pid!=child_pid ) error(errno,"waiting on child"); outputtime(); /* Test whether command has finished abnormally */ if ( ! WIFEXITED(status) ) { if ( WIFSIGNALED(status) ) { warning("command terminated with signal %d",WTERMSIG(status)); return 128+WTERMSIG(status); } if ( WIFSTOPPED(status) ) { warning("command stopped with signal %d",WSTOPSIG(status)); return 128+WSTOPSIG(status); } error(0,"command exit status unknown: %d",status); } /* Return the exitstatus of the command */ exitcode = WEXITSTATUS(status); if ( exitcode!=0 ) verbose("command exited with exitcode %d",exitcode); return exitcode; } /* This should never be reached */ error(0,"unexpected end of program"); }
void identd::packet_arrived(neolib::tcp_string_packet_stream& aStream, const neolib::string_packet& aPacket) { clients::iterator theClient = iClients.find(&aStream); if (theClient == iClients.end()) return; theClient->second.reset(); std::string response; neolib::vecarray<std::string, 2> parts; neolib::tokens(aPacket.contents(), std::string(","), parts, 2); if (parts.size() == 2) { neolib::vecarray<std::string, 1> localPart; neolib::vecarray<std::string, 1> remotePart; neolib::tokens(parts[0], std::string(" \r\n"), localPart, 1); neolib::tokens(parts[1], std::string(" \r\n"), remotePart, 1); unsigned long localPort = 0; unsigned long remotePort = 0; if (!localPart[0].empty()) localPort = neolib::string_to_unsigned_integer(localPart[0]); if (!remotePart[0].empty()) remotePort = neolib::string_to_unsigned_integer(remotePart[0]); if (localPort >= 1 && localPort <= 65535 && remotePort >= 1 && remotePort <= 65535) { connection* theConnection = iModel.connection_manager().find_connection(static_cast<u_short>(localPort), static_cast<u_short>(remotePort)); if (theConnection != 0) { response = neolib::unsigned_integer_to_string<char>(localPort) + "," + neolib::unsigned_integer_to_string<char>(remotePort); response += ":USERID:WIN32:"; switch(type()) { case Nickname: response += theConnection->nick_name(); break; case Email: { std::string userName = theConnection->identity().email_address(); std::string::size_type at = userName.find('@'); if (at != std::string::npos) userName = userName.substr(0, at); if (userName.empty()) userName = theConnection->nick_name(); response += userName; } break; case Userid: response += userid(); break; } response += "\r\n"; } else { response = neolib::unsigned_integer_to_string<char>(localPort) + "," + neolib::unsigned_integer_to_string<char>(remotePort); response += ":ERROR:NO-USER\r\n"; } } else { response = aPacket.contents(); response += ":ERROR:INVALID-PORT\r\n"; } } else { response = aPacket.contents(); response += ":ERROR:UNKNOWN-ERROR\r\n"; } aStream.send_packet(neolib::string_packet(response)); }