ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/CCSAdmin/common.c
(Generate patch)

Comparing CCSAdmin/common.c (file contents):
Revision 562 by douglas, 2005-08-27T21:46:39-07:00 vs.
Revision 589 by douglas, 2005-11-25T05:49:24-08:00

# Line 6 | Line 6
6  
7   #include "common.h"
8  
9 + #ifdef __sun__
10 + #define getpass getpassphrase
11 + #endif
12 +
13 + Shells shells[] = {
14 +        { "sh", "/bin/sh", "/bin/sh", "/bin/sh", "/usr/bin/sh" },
15 +        { "csh", "/bin/csh", "/bin/csh", "/bin/csh", "/usr/bin/csh" },
16 +        { "tcsh", "/bin/tcsh", "/bin/tcsh", "/bin/tcsh", "/usr/bin/tcsh" },
17 +        { "bash", "/usr/local/bin/bash", "/bin/bash", "/bin/bash", "/usr/local/bin/bash" },
18 +        { "ksh", "/usr/local/bin/ksh", "/bin/ksh", "/bin/ksh", "/usr/bin/ksh" },
19 +        { "zsh", "/usr/local/bin/zsh", "/bin/zsh", "/bin/zsh", "/usr/bin/zsh" },
20 +        { "3sh", "/ccs/bin/3sh", "/ccs/bin/3sh", "/ccs/bin/3sh", "/ccs/bin/3sh" },
21 +        { "custom", NULL, NULL, NULL, NULL }
22 + };
23 +
24   int check(int value, jmp_buf environment)
25   {
26          if (value == -1)
# Line 76 | Line 91 | void authenticate(const char *program, j
91          {
92                  check(dup2(pipe_[1], 1), environment);
93                  check(close(pipe_[0]), environment);
94 <                check(execl("/usr/local/bin/ldapwhoami", program, "-D", name, "-W", "-x", "-y", secret, NULL), environment);
94 >                check(execl(LDAPWHOAMI, program, "-D", name, "-W", "-x", "-y", secret, NULL), environment);
95          }
96  
97          check(close(pipe_[1]), environment);
# Line 121 | Line 136 | void putpassword(char password[_PASSWORD
136          check(write(file, password, strlen(password)), environment);
137          check(close(file), environment);
138   }
139 +
140 + void get(const char *prompt, regex_t *regex, char **string, jmp_buf environment)
141 + {
142 +        do
143 +        {
144 +                printf("%s: ", prompt);
145 +
146 +                size_t size;
147 +                char *string_ = fcheck(fgetln(stdin, &size), stdin, environment);
148 +
149 +                *string = *string ? realloc(*string, size) : malloc(size);
150 +
151 +                strlcpy(*string, string_, size);
152 +        }
153 +        while (regcheck(regexec(regex, *string, 0, NULL, 0), regex, environment));
154 + }
155 +
156 + void setshells(Shells *shells, jmp_buf environment)
157 + {
158 +        check(setenv("FREEBSD", shells->freebsd, 1), environment);
159 +        check(setenv("LINUX", shells->linux, 1), environment);
160 +        check(setenv("DARWIN", shells->darwin, 1), environment);
161 +        check(setenv("SOLARIS", shells->solaris, 1), environment);
162 + }
163 +
164 + #if !defined(__FreeBSD__) && !defined(__sun__)
165 + size_t strlcpy(char *dst, const char *src, size_t size)
166 + {
167 +        dst[size - 1] = '\0';
168 +
169 +        return strlen(strncpy(dst, src, size - 1));
170 + }
171 +
172 + size_t strlcat(char *dst, const char *src, size_t size)
173 + {
174 +        dst[size - 1] = '\0';
175 +
176 +        size_t size_ = strlen(dst);
177 +
178 +        return strlen(strncpy(dst + size_, src, size - size_ - 1));
179 + }
180 +
181 + char *fgetln(FILE * restrict stream, size_t * restrict len)
182 + {
183 +        static char *line = NULL;
184 +        static size_t size;
185 +
186 +        if ((*len = getline(&line, &size, stream)) == -1)
187 +                return NULL;
188 +
189 +        return line;
190 + }
191 + #elif defined(__sun__)
192 + char *fgetln(FILE * restrict stream, size_t * restrict len)
193 + {
194 +        static char *line = NULL;
195 +
196 +        *len = 0;
197 +        line = line ? realloc(line, 1) : malloc(1);
198 +
199 +        while (line[*len] = getc(stream), line[(*len)++] != '\n')
200 +                if (line[*len - 1] != EOF)
201 +                        line = realloc(line, *len + 1);
202 +                else
203 +                        return NULL;
204 +
205 +        return line;
206 + }
207 +
208 + int setenv(const char *name, const char *value, int overwrite)
209 + {
210 +        char *string_ = getenv(name);
211 +
212 +        if (overwrite || !string_)
213 +        {
214 +                char *string = malloc(strlen(name) + strlen(value) + 2);
215 +
216 +                sprintf(string, "%s=%s", name, value);
217 +
218 +                int value_ = putenv(string);
219 +
220 +                if (!string_)
221 +                        free(string_);
222 +
223 +                return value_;
224 +        }
225 +
226 +        return 0;
227 + }
228 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines