Deleted Added
full compact
45c45
< "$FreeBSD: head/libexec/tftpd/tftpd.c 146827 2005-05-31 17:22:53Z maxim $";
---
> "$FreeBSD: head/libexec/tftpd/tftpd.c 173852 2007-11-23 00:05:29Z edwin $";
112a113,114
> static char *newfile_format = "%Y%m%d";
> static int increase_name = 0;
137c139
< while ((ch = getopt(argc, argv, "cClns:u:U:w")) != -1) {
---
> while ((ch = getopt(argc, argv, "cCF:lns:u:U:wW")) != -1) {
144a147,149
> case 'F':
> newfile_format = optarg;
> break;
162a168,171
> case 'W':
> create_new = 1;
> increase_name = 1;
> break;
515a525,575
> * Find the next value for YYYYMMDD.nn when the file to be written should
> * be unique. Due to the limitations of nn, we will fail if nn reaches 100.
> * Besides, that is four updates per hour on a file, which is kind of
> * execessive anyway.
> */
> static int
> find_next_name(char *filename, int *fd)
> {
> int i;
> time_t tval;
> size_t len;
> struct tm lt;
> char yyyymmdd[MAXPATHLEN];
> char newname[MAXPATHLEN];
> struct stat sb;
> int ret;
>
> /* Create the YYYYMMDD part of the filename */
> time(&tval);
> lt = *localtime(&tval);
> len = strftime(yyyymmdd, sizeof(yyyymmdd), newfile_format, &lt);
> if (len == 0) {
> syslog(LOG_WARNING,
> "Filename suffix too long (%d characters maximum)",
> MAXPATHLEN);
> return (EACCESS);
> }
>
> /* Make sure the new filename is not too long */
> if (strlen(filename) > MAXPATHLEN - len - 5) {
> syslog(LOG_WARNING,
> "Filename too long (%d characters, %d maximum)",
> strlen(filename), MAXPATHLEN - len - 5);
> return (EACCESS);
> }
>
> /* Find the first file which doesn't exist */
> for (i = 0; i < 100; i++) {
> sprintf(newname, "%s.%s.%02d", filename, yyyymmdd, i);
> *fd = open(newname,
> O_WRONLY | O_CREAT | O_EXCL,
> S_IRUSR | S_IWUSR | S_IRGRP |
> S_IWGRP | S_IROTH | S_IWOTH);
> if (*fd > 0)
> return 0;
> }
>
> return (EEXIST);
> }
>
> /*
530a591
> int error;
613,616c674,685
< if (create_new)
< fd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, 0666);
< else
< fd = open(filename, O_WRONLY|O_TRUNC);
---
> if (create_new) {
> if (increase_name) {
> error = find_next_name(filename, &fd);
> if (error > 0)
> return (error + 100);
> } else
> fd = open(filename,
> O_WRONLY | O_TRUNC | O_CREAT,
> S_IRUSR | S_IWUSR | S_IRGRP |
> S_IWGRP | S_IROTH | S_IWOTH );
> } else
> fd = open(filename, O_WRONLY | O_TRUNC);