static void construct_custom_attributes( MyString &attributes, ClassAd* job_ad ) { attributes = ""; bool first_time = true; char *tmp = NULL; job_ad->LookupString( ATTR_EMAIL_ATTRIBUTES, &tmp ); if( ! tmp ) { return; } StringList email_attrs; email_attrs.initializeFromString( tmp ); free( tmp ); tmp = NULL; ExprTree* expr_tree; email_attrs.rewind(); while( (tmp = email_attrs.next()) ) { expr_tree = job_ad->LookupExpr(tmp); if( ! expr_tree ) { dprintf(D_ALWAYS, "Custom email attribute (%s) is undefined.", tmp); continue; } if( first_time ) { attributes.formatstr_cat( "\n\n" ); first_time = false; } attributes.formatstr_cat( "%s = %s\n", tmp, ExprTreeToString(expr_tree) ); } return; }
void passwd_cache::getUseridMap(MyString &usermap) { // fill in string with entries of form expected by loadConfig() uid_entry *uent; group_entry *gent; MyString index; uid_table->startIterations(); while ( uid_table->iterate(index, uent) ) { if( !usermap.IsEmpty() ) { usermap += " "; } usermap.formatstr_cat("%s=%ld,%ld",index.Value(),(long)uent->uid,(long)uent->gid); if( group_table->lookup(index,gent) == 0 ) { unsigned i; for(i=0;i<gent->gidlist_sz;i++) { if( gent->gidlist[i] == uent->gid ) { // already included this gid, because it is the primary continue; } usermap.formatstr_cat(",%ld",(long)gent->gidlist[i]); } } else { // indicate that supplemental groups are unknown usermap.formatstr_cat(",?"); } } }
bool SharedPortEndpoint::serialize(MyString &inherit_buf,int &inherit_fd) { inherit_buf.formatstr_cat("%s*",m_full_name.Value()); #ifdef WIN32 /* Serializing requires acquiring the handles of the respective pipes and seeding them into the buffer. */ HANDLE current_process = GetCurrentProcess(); HANDLE to_child; if(!DuplicateHandle(current_process, pipe_end, current_process, &to_child, NULL, true, DUPLICATE_SAME_ACCESS)) { dprintf(D_ALWAYS, "SharedPortEndpoint: Failed to duplicate named pipe for inheritance.\n"); return false; } inherit_buf.formatstr_cat("%d", to_child); #else inherit_fd = m_listener_sock.get_file_desc(); ASSERT( inherit_fd != -1 ); char *named_sock_serial = m_listener_sock.serialize(); ASSERT( named_sock_serial ); inherit_buf += named_sock_serial; delete []named_sock_serial; #endif return true; }
void stats_entry_recent<Probe>::PublishDebug(ClassAd & ad, const char * pattr, int flags) const { MyString str; MyString var1; MyString var2; ProbeToStringDebug(var1, this->value); ProbeToStringDebug(var2, this->recent); str.formatstr_cat("(%s) (%s)", var1.Value(), var2.Value()); str.formatstr_cat(" {h:%d c:%d m:%d a:%d}", this->buf.ixHead, this->buf.cItems, this->buf.cMax, this->buf.cAlloc); if (this->buf.pbuf) { for (int ix = 0; ix < this->buf.cAlloc; ++ix) { ProbeToStringDebug(var1, this->buf.pbuf[ix]); str.formatstr_cat(!ix ? "[%s" : (ix == this->buf.cMax ? "|%s" : ",%s"), var1.Value()); } str += "]"; } MyString attr(pattr); if (flags & this->PubDecorateAttr) attr += "Debug"; ad.Assign(pattr, str); }
int TransferQueueManager::HandleReport( Stream *sock ) { TransferQueueRequest *client; m_xfer_queue.Rewind(); while( m_xfer_queue.Next( client ) ) { if( client->m_sock == sock ) { if( !client->ReadReport(this) ) { dprintf(D_FULLDEBUG, "TransferQueueManager: dequeueing %s.\n", client->Description()); delete client; m_xfer_queue.DeleteCurrent(); TransferQueueChanged(); } return KEEP_STREAM; } } // should never get here m_xfer_queue.Rewind(); MyString clients; while( m_xfer_queue.Next( client ) ) { clients.formatstr_cat(" (%p) %s\n", client->m_sock,client->m_sock->peer_description()); } EXCEPT("TransferQueueManager: ERROR: disconnect from client (%p) %s;" " not found in list: %s\n", sock, sock->peer_description(), clients.Value()); return FALSE; // close socket }
bool CCBListener::HandleCCBRequest( ClassAd &msg ) { MyString address; MyString connect_id; MyString request_id; MyString name; if( !msg.LookupString( ATTR_MY_ADDRESS, address) || !msg.LookupString( ATTR_CLAIM_ID, connect_id) || !msg.LookupString( ATTR_REQUEST_ID, request_id) ) { MyString msg_str; msg.sPrint(msg_str); EXCEPT("CCBListener: invalid CCB request from %s: %s\n", m_ccb_address.Value(), msg_str.Value() ); } msg.LookupString( ATTR_NAME, name ); if( name.find(address.Value())<0 ) { name.formatstr_cat(" with reverse connect address %s",address.Value()); } dprintf(D_FULLDEBUG|D_NETWORK, "CCBListener: received request to connect to %s, request id %s.\n", name.Value(), request_id.Value()); return DoReversedCCBConnect( address.Value(), connect_id.Value(), request_id.Value(), name.Value() ); }
// sprintf() method void UserLogHeader::sprint_cat( MyString &buf ) const { if ( m_valid ) { buf.formatstr_cat( "id=%s" " seq=%d" " ctime=%lu" " size=" FILESIZE_T_FORMAT " num=%" PRIi64 " file_offset=" FILESIZE_T_FORMAT " event_offset=%" PRIi64 " max_rotation=%d" " creator_name=<%s>", m_id.Value(), m_sequence, (unsigned long) m_ctime, m_size, m_num_events, m_file_offset, m_event_offset, m_max_rotation, m_creator_name.Value() ); } else { buf += "invalid"; } }
void stats_entry_recent<double>::PublishDebug(ClassAd & ad, const char * pattr, int flags) const { MyString str; str.formatstr_cat("%g %g", this->value, this->recent); str.formatstr_cat(" {h:%d c:%d m:%d a:%d}", this->buf.ixHead, this->buf.cItems, this->buf.cMax, this->buf.cAlloc); if (this->buf.pbuf) { for (int ix = 0; ix < this->buf.cAlloc; ++ix) { str.formatstr_cat(!ix ? "[%g" : (ix == this->buf.cMax ? "|%g" : ",%g"), this->buf.pbuf[ix]); } str += "]"; } MyString attr(pattr); if (flags & this->PubDecorateAttr) attr += "Debug"; ad.Assign(pattr, str); }
int GLExecPrivSepHelper::run_script(ArgList& args,MyString &error_desc) { if (!proxy_valid_right_now()) { dprintf(D_ALWAYS, "GLExecPrivSepHelper::run_script: not invoking glexec since the proxy is not valid!\n"); error_desc += "The job proxy is not valid."; return INVALID_PROXY_RC; } /* Note that set_user_priv is a no-op if condor is running as non-root (the "usual" mode for invoking glexec) */ priv_state priv_saved = set_user_priv(); FILE* fp = my_popen(args, "r", TRUE); set_priv(priv_saved); if (fp == NULL) { dprintf(D_ALWAYS, "GLExecPrivSepHelper::run_script: " "my_popen failure on %s: errno=%d (%s)\n", args.GetArg(0), errno, strerror(errno)); return -1; } MyString str; while (str.readLine(fp, true)); priv_saved = set_user_priv(); int ret = my_pclose(fp); set_priv(priv_saved); if (ret != 0) { str.trim(); dprintf(D_ALWAYS, "GLExecPrivSepHelper::run_script: %s exited " "with status %d and following output:\n%s\n", args.GetArg(0), ret, str.Value()); error_desc.formatstr_cat("%s exited with status %d and the following output: %s", condor_basename(args.GetArg(0)), ret, str.Value()); error_desc.replaceString("\n","; "); } return ret; }
int CCBServer::HandleRequest(int cmd,Stream *stream) { ReliSock *sock = (ReliSock *)stream; ASSERT( cmd == CCB_REQUEST ); // Avoid lengthy blocking on communication with our peer. // This command-handler should not get called until data // is ready to read. sock->timeout(1); ClassAd msg; sock->decode(); if( !msg.initFromStream( *sock ) || !sock->end_of_message() ) { dprintf(D_ALWAYS, "CCB: failed to receive request " "from %s.\n", sock->peer_description() ); return FALSE; } MyString name; if( msg.LookupString(ATTR_NAME,name) ) { // client name is purely for debugging purposes name.formatstr_cat(" on %s",sock->peer_description()); sock->set_peer_description(name.Value()); } MyString target_ccbid_str; MyString return_addr; MyString connect_id; // id target daemon should present to requester CCBID target_ccbid; // NOTE: using ATTR_CLAIM_ID for connect id so that it is // automatically treated as a secret over the network. // It must be presented by the target daemon when connecting // to the requesting client, so the client can confirm that // the connection is in response to its request. if( !msg.LookupString(ATTR_CCBID,target_ccbid_str) || !msg.LookupString(ATTR_MY_ADDRESS,return_addr) || !msg.LookupString(ATTR_CLAIM_ID,connect_id) ) { MyString ad_str; msg.sPrint(ad_str); dprintf(D_ALWAYS, "CCB: invalid request from %s: %s\n", sock->peer_description(), ad_str.Value() ); return FALSE; } if( !CCBIDFromString(target_ccbid,target_ccbid_str.Value()) ) { dprintf(D_ALWAYS, "CCB: request from %s contains invalid CCBID %s\n", sock->peer_description(), target_ccbid_str.Value() ); return FALSE; } CCBTarget *target = GetTarget( target_ccbid ); if( !target ) { dprintf(D_ALWAYS, "CCB: rejecting request from %s for ccbid %s because no daemon is " "currently registered with that id " "(perhaps it recently disconnected).\n", sock->peer_description(), target_ccbid_str.Value()); MyString error_msg; error_msg.formatstr( "CCB server rejecting request for ccbid %s because no daemon is " "currently registered with that id " "(perhaps it recently disconnected).", target_ccbid_str.Value()); RequestReply( sock, false, error_msg.Value(), 0, target_ccbid ); return FALSE; } SetSmallBuffers(sock); CCBServerRequest *request = new CCBServerRequest( sock, target_ccbid, return_addr.Value(), connect_id.Value() ); AddRequest( request, target ); dprintf(D_FULLDEBUG, "CCB: received request id %lu from %s for target ccbid %s " "(registered as %s)\n", request->getRequestID(), request->getSock()->peer_description(), target_ccbid_str.Value(), target->getSock()->peer_description()); ForwardRequestToTarget( request, target ); return KEEP_STREAM; }
int CCBServer::HandleRegistration(int cmd,Stream *stream) { ReliSock *sock = (ReliSock *)stream; ASSERT( cmd == CCB_REGISTER ); // Avoid lengthy blocking on communication with our peer. // This command-handler should not get called until data // is ready to read. sock->timeout(1); ClassAd msg; sock->decode(); if( !msg.initFromStream( *sock ) || !sock->end_of_message() ) { dprintf(D_ALWAYS, "CCB: failed to receive registration " "from %s.\n", sock->peer_description() ); return FALSE; } SetSmallBuffers(sock); MyString name; if( msg.LookupString(ATTR_NAME,name) ) { // target daemon name is purely for debugging purposes name.formatstr_cat(" on %s",sock->peer_description()); sock->set_peer_description(name.Value()); } CCBTarget *target = new CCBTarget(sock); MyString reconnect_cookie_str,reconnect_ccbid_str; CCBID reconnect_cookie,reconnect_ccbid; bool reconnected = false; if( msg.LookupString(ATTR_CLAIM_ID,reconnect_cookie_str) && CCBIDFromString(reconnect_cookie,reconnect_cookie_str.Value()) && msg.LookupString( ATTR_CCBID,reconnect_ccbid_str) && CCBIDFromContactString(reconnect_ccbid,reconnect_ccbid_str.Value()) ) { target->setCCBID( reconnect_ccbid ); reconnected = ReconnectTarget( target, reconnect_cookie ); } if( !reconnected ) { AddTarget( target ); } CCBReconnectInfo *reconnect_info = GetReconnectInfo( target->getCCBID() ); ASSERT( reconnect_info ); sock->encode(); ClassAd reply_msg; MyString ccb_contact; CCBIDToString( reconnect_info->getReconnectCookie(),reconnect_cookie_str ); // We send our address as part of the CCB contact string, rather // than letting the target daemon fill it in. This is to give us // potential flexibility on the CCB server side to do things like // assign different targets to different CCB server sub-processes, // each with their own command port. CCBIDToContactString( m_address.Value(), target->getCCBID(), ccb_contact ); reply_msg.Assign(ATTR_CCBID,ccb_contact.Value()); reply_msg.Assign(ATTR_COMMAND,CCB_REGISTER); reply_msg.Assign(ATTR_CLAIM_ID,reconnect_cookie_str.Value()); if( !reply_msg.put( *sock ) || !sock->end_of_message() ) { dprintf(D_ALWAYS, "CCB: failed to send registration response " "to %s.\n", sock->peer_description() ); RemoveTarget( target ); return KEEP_STREAM; // we have already closed this socket } return KEEP_STREAM; }
// make query int GenericQuery:: makeQuery (MyString &req) { int i, value; char *item; float fvalue; req = ""; // construct query requirement expression bool firstCategory = true; // add string constraints for (i = 0; i < stringThreshold; i++) { stringConstraints [i].Rewind (); if (!stringConstraints [i].AtEnd ()) { bool firstTime = true; req += firstCategory ? "(" : " && ("; while ((item = stringConstraints [i].Next ())) { req.formatstr_cat ("%s(%s == \"%s\")", firstTime ? " " : " || ", stringKeywordList [i], item); firstTime = false; firstCategory = false; } req += " )"; } } // add integer constraints for (i = 0; i < integerThreshold; i++) { integerConstraints [i].Rewind (); if (!integerConstraints [i].AtEnd ()) { bool firstTime = true; req += firstCategory ? "(" : " && ("; while (integerConstraints [i].Next (value)) { req.formatstr_cat ("%s(%s == %d)", firstTime ? " " : " || ", integerKeywordList [i], value); firstTime = false; firstCategory = false; } req += " )"; } } // add float constraints for (i = 0; i < floatThreshold; i++) { floatConstraints [i].Rewind (); if (!floatConstraints [i].AtEnd ()) { bool firstTime = true; req += firstCategory ? "(" : " && ("; while (floatConstraints [i].Next (fvalue)) { req.formatstr_cat ("%s(%s == %f)", firstTime ? " " : " || ", floatKeywordList [i], fvalue); firstTime = false; firstCategory = false; } req += " )"; } } // add custom AND constraints customANDConstraints.Rewind (); if (!customANDConstraints.AtEnd ()) { bool firstTime = true; req += firstCategory ? "(" : " && ("; while ((item = customANDConstraints.Next ())) { req.formatstr_cat ("%s(%s)", firstTime ? " " : " && ", item); firstTime = false; firstCategory = false; } req += " )"; } // add custom OR constraints customORConstraints.Rewind (); if (!customORConstraints.AtEnd ()) { bool firstTime = true; req += firstCategory ? "(" : " && ("; while ((item = customORConstraints.Next ())) { req.formatstr_cat ("%s(%s)", firstTime ? " " : " || ", item); firstTime = false; firstCategory = false; } req += " )"; } return Q_OK; }