bool SharedPortEndpoint::GetAltDaemonSocketDir(std::string &result) { #ifndef WIN32 if (!param(result, "DAEMON_SOCKET_DIR") ) { EXCEPT("DAEMON_SOCKET_DIR must be defined"); } // If set to "auto", we want to make sure that $(DAEMON_SOCKET_DIR)/collector or $(DAEMON_SOCKET_DIR)/15337_9022_123456 isn't more than 108 characters std::string default_name; if (result == "auto") { char *tmp = expand_param("$(LOCK)/daemon_sock"); default_name = tmp; free(tmp); } else { default_name = result; } struct sockaddr_un named_sock_addr; const unsigned max_len = sizeof(named_sock_addr.sun_path)-1; if (strlen(default_name.c_str()) + 18 > max_len) { dprintf(D_FULLDEBUG, "WARNING: DAEMON_SOCKET_DIR %s setting is too long.\n", default_name.c_str()); return false; } result = default_name; return true; #endif return false; }
void evis_wave(running_machine &machine, int ref, int params, const char **param) { char buffer[1024]; if (!game_started) return; expand_param(machine, params, param, buffer); std::string message = std::string(WAVE) .append(std::to_string(atoi(buffer)+1)) .append("\n"); sender.sendMessage(message); }
void SharedPortEndpoint::InitializeDaemonSocketDir() { if ( m_initialized_socket_dir ) { return; } m_initialized_socket_dir = true; std::string result; #ifdef USE_ABSTRACT_DOMAIN_SOCKET // Linux has some unique behavior. We use a random cookie as a prefix to our // shared port "directory" in the abstract Unix namespace. char *keybuf = Condor_Crypt_Base::randomHexKey(32); if (keybuf == NULL) { EXCEPT("SharedPortEndpoint: Unable to create a secure shared port cookie.\n"); } result = keybuf; free(keybuf); keybuf = NULL; #elif defined(WIN32) return; #else if( !param(result, "DAEMON_SOCKET_DIR") ) { EXCEPT("DAEMON_SOCKET_DIR must be defined"); } // If set to "auto", we want to make sure that $(DAEMON_SOCKET_DIR)/collector or $(DAEMON_SOCKET_DIR)/15337_9022_123456 isn't more than 108 characters // Hence we assume the longest valid shared port ID is 18 characters. if (result == "auto") { struct sockaddr_un named_sock_addr; const unsigned max_len = sizeof(named_sock_addr.sun_path)-1; char * default_name = expand_param("$(LOCK)/daemon_sock"); if (strlen(default_name) + 18 > max_len) { TemporaryPrivSentry tps(PRIV_CONDOR); // NOTE we force the use of /tmp here - not using the HTCondor library routines; // this is because HTCondor will look up the param TMP_DIR, which might also be // a long directory path. We really want /tmp. char dirname_template[] = "/tmp/condor_shared_port_XXXXXX"; const char *dirname = mkdtemp(dirname_template); if (dirname == NULL) { EXCEPT("SharedPortEndpoint: Failed to create shared port directory: %s (errno=%d)\n", strerror(errno), errno); } m_created_shared_port_dir = true; result = dirname; dprintf(D_ALWAYS, "Default DAEMON_SOCKET_DIR too long; using %s instead. Please shorten the length of $(LOCK)\n", dirname); } else { result = default_name; } free( default_name ); } #endif #ifndef WIN32 setenv("CONDOR_PRIVATE_SHARED_PORT_COOKIE", result.c_str(), 1); #endif }
union node* expand_param(struct nargparam* param, union node** nptr, struct vartab* varstack, char* argv[], int exitcode, int flags) { union node* n = *nptr; stralloc value; char* str = NULL; const char *v = NULL; unsigned long argc, vlen = 0; for(argc = 0; argv[argc]; ++argc) ; stralloc_init(&value); /* treat special arguments */ if(param->flag & S_SPECIAL) { switch(param->flag & S_SPECIAL) { /* $# substitution */ case S_ARGC: { stralloc_catulong0(&value, argc, 0); break; } /* $* substitution */ case S_ARGV: { char** s; for(s = argv; *s;) { stralloc_cats(&n->narg.stra, *s); if(*++s) stralloc_catc(&n->narg.stra, ' '); } break; } /* $@ substitution */ case S_ARGVS: { unsigned int i = 0; while(i < argc) { param->flag &= ~S_SPECIAL; param->flag |= S_ARG; param->numb = 1 + i; n = expand_param(param, nptr, varstack, argv, exitcode,flags); if(++i < argc) nptr = &n->list.next; } return n; } /* $? substitution */ case S_EXITCODE: { stralloc_catulong0(&value, exitcode, 0); break; } /* $- substitution */ case S_FLAGS: break; /* $! substitution */ case S_BGEXCODE: break; /* $[0-9] arg subst */ case S_ARG: { if(param->numb == 0) { /* stralloc_cats(&value, sh_argv0); */ } else if(param->numb - 1 < argc) { stralloc_cats(&value, argv[param->numb - 1]); } break; } /* $$ arg subst */ case S_PID: { stralloc_catulong0(&value, getpid(), 0); break; } } /* special parameters are always set */ if(value.len) { stralloc_nul(&value); v = value.s; } vlen = value.len; } /* ..and variable substitutions */ else { size_t offset; /* look for the variable. if the S_NULL flag is set and we have a var which is null set v to NULL */ if((v = var_get(varstack, param->name, &offset))) { if(v[offset] == '\0' && (param->flag & S_NULL)) { v = NULL; vlen = 0; } else { v = &v[offset]; vlen = str_len(v); } } } /* check for S_STRLEN substitution */ if(param->flag & S_STRLEN) { char lstr[FMT_ULONG]; n = expand_cat(lstr, fmt_ulong(lstr, vlen), nptr, varstack, flags); stralloc_free(&value); return n; } str = str_ndup(v, vlen); /* otherwise expand the apropriate variable/word subst */ switch(param->flag & S_VAR) { /* return word if parameter unset (or null) */ case S_DEFAULT: { if(v) n = expand_cat(v, vlen, nptr, varstack, flags); /* unset, substitute */ else n = expand_arg(¶m->word->narg, nptr, varstack, argv, exitcode, flags); break; } /* if parameter unset (or null) then expand word to it and substitute paramter */ case S_ASGNDEF: { if(v) n = expand_cat(v, vlen, nptr, varstack, flags); else { n = expand_arg(¶m->word->narg, nptr, varstack, argv, exitcode, flags | X_NOSPLIT); var_setvsa(param->name, /* BUG */ &n->narg.stra, V_DEFAULT); } break; } /* indicate error if null or unset */ case S_ERRNULL: { if(v) n = expand_cat(v, vlen, nptr, varstack, flags); else { union node* tmpnode = NULL; n = expand_arg(¶m->word->narg, &tmpnode, varstack, argv, exitcode, flags); errmsg_warn((n && n->narg.stra.s) ? n->narg.stra.s : "parameter null or not set", 0); if(tmpnode) tree_free(tmpnode); } break; } /* if parameter unset (or null) then substitute null, otherwise substitute word */ case S_ALTERNAT: { if(v) n = expand_arg(¶m->word->narg, nptr, varstack, argv, exitcode, flags); break; /* remove smallest matching suffix */ case S_RSSFX: { int i; stralloc sa; if(v && vlen) { expand_copysa(param->word, &sa, varstack, argv, exitcode, 0); stralloc_nul(&sa); for(i = vlen - 1; i >= 0; i--) if(fnmatch(sa.s, str + i, FNM_PERIOD) == 0) break; n = expand_cat(v, (i < 0 ? vlen : i), nptr, varstack, flags); } break; } } /* remove largest matching suffix */ case S_RLSFX: { unsigned int i; stralloc sa; if(v && vlen) { expand_copysa(param->word, &sa, varstack, argv, exitcode, 0); stralloc_nul(&sa); for(i = 0; i <= vlen; i++) if(fnmatch(sa.s, str + i, FNM_PERIOD) == 0) break; n = expand_cat(v, (i > vlen ? vlen : i), nptr, varstack, flags); } break; } /* remove smallest matching prefix */ case S_RSPFX: { unsigned int i; stralloc sa; if(v && vlen) { expand_copysa(param->word, &sa, varstack, argv, exitcode, 0); stralloc_nul(&sa); for(i = 1; i <= vlen; i++) { str_copyn(str, v, i); if(fnmatch(sa.s, (char*)v, FNM_PERIOD) == 0) break; } if(i > vlen) i = 0; n = expand_cat(v + i, vlen - i, nptr, varstack, flags); str_copy(str, v); } break; } /* remove largest matching prefix */ case S_RLPFX: { unsigned int i; stralloc sa; if(v && vlen) { expand_copysa(param->word, &sa, varstack, argv, exitcode, 0); stralloc_nul(&sa); for(i = vlen; i > 0; i--) { str_copyn(str, v, i); if(fnmatch(sa.s, (char*)v, FNM_PERIOD) == 0) break; } if(i == 0) i = vlen; n = expand_cat(v + i, vlen - i, nptr, varstack, flags); str_copy(str, v); } break; } } free(str); stralloc_free(&value); return n; }
/* We have been given a filename describing where we should get our executable from. That name could be of the form "<hostname>:<pathname>", or it could just be <pathname>. Also the <pathname> part could contain macros to be looked up in our config file. We do that macro expansion here, and also check the <hostname> part. If the hostname refers to our own host, we set "on_this_host" to TRUE and if it refers to the submitting host, we set it to FALSE. For now, it is an error if it refers to some third host. We then ruturn a pointer to the macro expanded pathname in a static data area. The pathname could also be an AFS file, in which case we can also access the file with a symlink. The form is "/afs/...". */ char * UserProc::expand_exec_name( int &on_this_host ) { char *host_part; char *path_part; char *tmp; char *a_out; int status; a_out = NULL; status = REMOTE_CONDOR_get_a_out_name( a_out ); if( status < 0 || a_out == NULL ) { EXCEPT( "Can't get name of a.out file" ); } if( strchr(a_out,':') ) { // form is <hostname>:<path> host_part = strtok( a_out, " \t:" ); if( host_part == NULL ) { EXCEPT( "Can't find host part" ); } path_part = strtok( NULL, " \t:"); if( path_part == NULL ) { EXCEPT( "Can't find path part" ); } if( strcmp(host_part,ThisHost) == MATCH ) { on_this_host = TRUE; } else { if( strcmp(host_part,InitiatingHost) == MATCH ) { on_this_host = FALSE; } else { EXCEPT( "Unexpected host_part \"%s\", ThisHost %s", host_part, ThisHost ); } } } else if( strncmp("/afs",a_out,4) == MATCH ) { on_this_host = TRUE; path_part = a_out; } else { // form is <path> on_this_host = FALSE; path_part = a_out; } // expand macros in the pathname part tmp = expand_param( path_part ); free( m_a_out ); m_a_out = strdup( tmp ); FREE( tmp ); free(a_out); if( on_this_host ) { if( access(m_a_out,X_OK) == 0 ) { dprintf( D_ALWAYS, "Executable is located on this host\n" ); } else { dprintf( D_FAILURE|D_ALWAYS, "Executable located on this host - but not executable\n" ); on_this_host = FALSE; } } else { dprintf( D_ALWAYS, "Executable is located on submitting host\n" ); } dprintf( D_ALWAYS, "Expanded executable name is \"%s\"\n", m_a_out ); return m_a_out; }