X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=userv.git;a=blobdiff_plain;f=client.c;h=02d77a9340057e8da024a92aa777c39e6c0fe44e;hp=7a810b534aa98d42da10dad7135d4b5810a825a2;hb=26444956110f28281bef77dfc28be75e25ae85a2;hpb=5043c988440a119e4f773c967be19a829582b8ba diff --git a/client.c b/client.c index 7a810b5..02d77a9 100644 --- a/client.c +++ b/client.c @@ -133,14 +133,14 @@ struct fdsetupstate { }; enum signalsexitspecials { se_number=-100, se_numbernocore, se_highbit, se_stdout }; -enum overridetypes { ot_none, ot_string, ot_file }; +enum overridetypes { ot_none, ot_string, ot_file, ot_builtin }; struct constkeyvaluepair { const char *key, *value; }; static const char *serviceuser; static uid_t serviceuid, myuid; static struct fdsetupstate *fdsetup; -static int fdsetupsize, builtin; +static int fdsetupsize; static struct constkeyvaluepair *defvararray; static int defvaravail, defvarused; static unsigned long timeout; @@ -472,10 +472,6 @@ static void of_hidecwd(const struct optioninfo *oip, const char *value, char *ke hidecwd=1; } -static void of_builtin(const struct optioninfo *oip, const char *value, char *key) { - builtin=1; -} - static void of_help(const struct optioninfo *oip, const char *value, char *key) { usage(); exit(0); @@ -500,6 +496,10 @@ static void of_copyright(const struct optioninfo *oip, const char *value, char * exit(0); } +static void of_builtin(const struct optioninfo *oip, const char *value, char *key) { + overridetype= ot_builtin; +} + static void of_override(const struct optioninfo *oip, const char *value, char *key) { overridetype= ot_string; overridevalue= value; @@ -759,13 +759,13 @@ int main(int argc, char *const *argv) { } } } - if (builtin) { + if (overridetype == ot_builtin) { serviceuser= "-"; } else { if (!*argpp) usageerror("no service user given after options"); serviceuser= *argpp++; } - if (!*argpp) usageerror(builtin ? + if (!*argpp) usageerror(overridetype == ot_builtin ? "no service name given after options and service user" : "no builtin service given after options"); @@ -848,13 +848,22 @@ int main(int argc, char *const *argv) { ovused= -1; ovbuf= 0; break; + case ot_builtin: + l= strlen(argv[0]); + if (l >= MAX_OVERRIDE_LEN-20) + miscerror("builtin service string is too long (%d, max is %d)", + l,MAX_OVERRIDE_LEN-21); + l+= 20; + ovbuf= xmalloc(l); + snprintf(ovbuf,l,"execute-builtin %s\n",argv[0]); + ovused= strlen(ovbuf); + break; case ot_string: l= strlen(overridevalue); if (l >= MAX_OVERRIDE_LEN) miscerror("override string is too long (%d, max is %d)",l,MAX_OVERRIDE_LEN-1); ovbuf= xmalloc(l+2); - strcpy(ovbuf,overridevalue); - strcat(ovbuf,"\n"); + snprintf(ovbuf,l+2,"%s\n",overridevalue); ovused= l+1; break; case ot_file: